Updating the image size
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 21 Apr 2016 16:09:51 +0000 (12:09 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 21 Apr 2016 16:09:51 +0000 (12:09 -0400)
Also made change to help with the gateway timeout.
These big images will need to be done 100 at a time.

controllers/ToolboxImport.php

index b208169..bfae9e3 100644 (file)
@@ -59,6 +59,7 @@
         private $_options;
         private $_files = array();
         private $_images = array();
+        private $_imageSize = 'original';
 
 
         public function __construct()
             if (!isset($data['image'])) {
                 return false;
             }
-            $img_url = $this->_options['toolbox_image_url'] . '/CKImage/' . $data['image'];
+            $img_url = $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/' . $data['image'];
             $content = '';
             if (isset($data['caption']) && $data['caption']) {
                 $content .= '[caption align="align'.$alignment.'"]<img  src="' . $img_url . '"> ' . $data['caption'] . '[/caption]';
             $this->_post = get_option(GLM_WP_IMPORT_POST_OPTION, array());
             // grab all pages and build the post array
             $start = filter_var($_REQUEST['start'], FILTER_VALIDATE_INT);
-            //$pages = $this->_fetchAllPages(PAGES_PER_LOAD, $start);
             $pages = $this->_fetchAllPages();
-            //foreach ($pages as $page) {
-                //echo '<pre>' . print_r(htmlspecialchars($page['pageContent']), true) . '</pre>';
-            //}
-            //echo '<pre>' . print_r($pages, true) . '</pre>';
-            //return;
-            //exit;
             $numPagesImported = count($pages);
 
             foreach ($pages as $page) {
             }
         }
 
-        private function _getCkImages()
+        private function _getCkImageCount()
+        {
+            $this->_connect();
+            $sql = "
+            SELECT count(*) as count
+              FROM {$this->_options['ckeditor_schema']}.{$this->_options['ckeditor_images_table']}";
+            return $this->_dbh->query($sql)->fetchColumn();
+        }
+
+        private function _getCkImages( $limit = 100, $offset = 0 )
         {
             global $wpdb;
             if ($this->_options['ckeditor_schema'] && $this->_options['ckeditor_images_table']) {
                 $sql = "
                 SELECT *
                   FROM {$this->_options['ckeditor_schema']}.{$this->_options['ckeditor_images_table']}";
+        
+                $sql .= " LIMIT $limit OFFSET $offset";
                 $stmt = $this->_dbh->query($sql);
+
                 while ($row = $stmt->fetch()) {
                     echo '<pre>' . print_r($row, true) . '</pre>';
                     $fileName = $row['name_on_disk'];
                         $fileTitle,
                         '',
                         0,
-                        $this->_options['toolbox_image_url'] . '/CKImage/'
+                        $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/'
                     );
                     echo '<pre>' . print_r($wpImage, true) . '</pre>';
                     $this->_images[$wpImage] = $fileName;
                         $fileTitle,
                         '',
                         0,
-                        $this->_options['toolbox_image_url'] . '/CKImage/'
+                        $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/'
                     );
                     echo '<pre>' . print_r($wpImage, true) . '</pre>';
                     $this->_images[$wpImage] = $fileName;
                         $fileTitle,
                         '',
                         0,
-                        $this->_options['toolbox_image_url'] . '/CKImage/'
+                        $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/'
                     );
                     echo '<pre>' . print_r($wpImage, true) . '</pre>';
                     $this->_images[$wpImage] = $fileName;
                         $fileTitle,
                         '',
                         0,
-                        $this->_options['toolbox_image_url'] . '/CKImage/'
+                        $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/'
                     );
                     echo '<pre>' . print_r($wpImage, true) . '</pre>';
                     $this->_images[$wpImage] = $fileName;
                 echo '<p><a href="admin.php?import=toolbox&amp;step=2">Step Two (Importing Images)</a></p>';
                 break;
             case 2:
+                $imageLimit = 100;
                 echo '<p>Done</p>';
                 echo '<p>Now processing the images from old database tables</p>';
-                $this->_images = array();
-                $this->_storeImages();
-                if ($this->_options['toolbox_page_table'] == 'pages') {
-                    $this->_getCkImages();
-                    $this->_getParagraphImages();
-                    echo '<p>Done</p>';
+                if (isset($_REQUEST['start'])) {
+                    echo '<p>Second Part of the images</p>';
+                    $totalImages = $this->_getCkImageCount();
+                    echo '<p>Number of images in ckimage ' . $totalImages . '</p>';
+                    $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT );
+                    if ($start > $totalImages ) {
+                        echo '<p>Done</p>';
+                        echo '<p><a href="admin.php?import=toolbox&amp;step=3">Step Three (Importing Files)</a></p>';
+                    } else {
+                        $this->_getCkImages( $imageLimit, $start );
+                        $start += $imageLimit;
+                        $endCount = $start + $imageLimit;
+                        echo '<p><a href="admin.php?import=toolbox&amp;step=2&start=' . $start . '">
+                            Step Two [' . $start . ' - ' . $endCount . ']</a></p>';
+                    }
                 } else {
-                    $this->_getBusCategoryImages();
-                    $this->_getBusImages();
-                    echo '<p>No import from images</p>';
+                    $start = 0;
+                    $this->_images = array();
+                    $this->_storeImages();
+                    if ($this->_options['toolbox_page_table'] == 'pages') {
+                        $this->_getParagraphImages();
+                        echo '<p>Done with Paragraph images</p>';
+                        $endCount = $start + $imageLimit;
+                        echo '<p><a href="admin.php?import=toolbox&amp;step=2&start=' . $start . '">
+                            Step Two [' . $start . ' - ' . $endCount . ']</a></p>';
+                    } else {
+                        $this->_getBusCategoryImages();
+                        $this->_getBusImages();
+                        echo '<p>No import from images</p>';
+                        echo '<p><a href="admin.php?import=toolbox&amp;step=3">Step Three (Importing Files)</a></p>';
+                    }
                 }
-                echo '<p><a href="admin.php?import=toolbox&amp;step=3">Step Three (Importing Files)</a></p>';
                 break;
             case 3:
                 echo '<p>Done</p>';