Working on the toolbox image
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 12 Oct 2015 21:01:13 +0000 (17:01 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 12 Oct 2015 21:01:13 +0000 (17:01 -0400)
Redo and fix the image path for the paragraph toolbox exported images.
These were imported with the incorrect image size RESIZED

controllers/ToolboxImport.php

index bb7a767..1e4395f 100644 (file)
         private function _getParagraphImages()
         {
             global $wpdb;
-            echo '<pre>' . print_r($this->_options['toolbox_schema'], true) . '</pre>';
-            echo '<pre>' . print_r($this->_options['toolbox_paragraphs_table'], true) . '</pre>';
+            //echo '<pre>' . print_r($this->_options['toolbox_schema'], true) . '</pre>';
+            //echo '<pre>' . print_r($this->_options['toolbox_paragraphs_table'], true) . '</pre>';
             if ($this->_options['toolbox_paragraphs_table']) {
                 $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
                 $this->_connect();
                         0,
                         $this->_options['toolbox_image_url'] . '/CKImage/'
                     );
-                    echo '<pre>' . print_r($wpImage, true) . '</pre>';
+                    //echo '<pre>' . print_r($wpImage, true) . '</pre>';
                     $this->_images[$wpImage] = $fileName;
                 }
+                //echo '<pre>' . print_r($this->_images, true) . '</pre>';
                 $this->_storeImages();
             }
         }
 
+        /**
+         * Fix the paragraph images
+         *
+         * Step 1: Find all the paragraph images
+         * Step 2: Fetch and store the image with the larger CKImage size
+         * Step 3: Update the image meta data (this will regerate the thumbnail data)
+         */
+        private function _fixParagraphimages()
+        {
+            global $wpdb;
+            $this->_images = array();
+            if ($this->_options['toolbox_paragraphs_table']) {
+                $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
+                $this->_connect();
+                $sql = "
+                SELECT image,caption
+                  FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_paragraphs_table']}
+                 WHERE image != ''";
+                $stmt = $this->_dbh->query($sql);
+                while ($row = $stmt->fetch()) {
+                    echo '<pre>image,caption: ' . print_r($row, true) . '</pre>';
+                    $fileName = $row['image'];
+                    $fileinfo = pathinfo($fileName);
+                    echo '<p>filename: ' . print_r($fileinfo['filename'], true) . '</p>';
+                    // find the attachment id
+                    $sql = "
+                    SELECT *
+                      FROM {$wpdb->prefix}posts
+                     WHERE post_name = '{$fileinfo['filename']}'";
+                    $att_results     = $wpdb->get_row($sql, ARRAY_A);
+                    if ( count( $att_results  ) > 0 ) {
+                        $attachment_id   = $att_results['ID'];
+                        $attachment_guid = $att_results['guid'];
+                        echo '<pre>attachment_id: ' . print_r($attachment_id, true) . '</pre>';
+                        echo '<pre>attachment_guid: ' . print_r($attachment_guid, true) . '</pre>';
+                    } else {
+                        echo '<p style="color: red;">WARN: not finding attachment</p>';
+                    }
+                    // find the post with that guid in it
+                    $sql = "
+                    SELECT *
+                      FROM {$wpdb->prefix}posts
+                     WHERE post_content like '%{$attachment_guid}%'";
+                    $page_results = $wpdb->get_row($sql, ARRAY_A);
+                    if ( count( $page_results ) > 0 ) {
+                        $page_id      = $page_results['ID'];
+                        echo '<pre>page_id: ' . print_r($page_id, true) . '</pre>';
+                    } else {
+                        echo '<p style="color: red;">WARN: not finding guid in any page</p>';
+                    }
+                }
+                //echo '<pre>' . print_r($this->_images, true) . '</pre>';
+            }
+        }
+
         public function dispatch()
         {
             $this->_header();
                 $step = filter_var($_GET['step'], FILTER_VALIDATE_INT);
             }
             switch($step) {
+            case 6:
+                //echo '<p>The walking Dead!!!!!!</p>';
+                $this->_fixParagraphimages();
+                break;
             case 0:
                 $this->_greet();
                 echo '<p><a href="admin.php?import=toolbox&amp;step=1">Begin Import</a></p>';
                 } else {
                     echo '<p><a href="admin.php?import=toolbox&amp;step=1">Begin Import</a></p>';
                 }
+                echo '<p><a href="admin.php?import=toolbox&amp;step=6">Fix Paragraph Images</a></p>';
                 break;
             case 1:
                 echo '<p>Reset</p>';