From 550f1b66737db143e6f2f8530a037bac74d248a1 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 21 Apr 2016 12:09:51 -0400 Subject: [PATCH] Updating the image size Also made change to help with the gateway timeout. These big images will need to be done 100 at a time. --- controllers/ToolboxImport.php | 73 ++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/controllers/ToolboxImport.php b/controllers/ToolboxImport.php index b208169..bfae9e3 100644 --- a/controllers/ToolboxImport.php +++ b/controllers/ToolboxImport.php @@ -59,6 +59,7 @@ private $_options; private $_files = array(); private $_images = array(); + private $_imageSize = 'original'; public function __construct() @@ -165,7 +166,7 @@ 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.'"] ' . $data['caption'] . '[/caption]'; @@ -536,14 +537,7 @@ $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 '
' . print_r(htmlspecialchars($page['pageContent']), true) . '
'; - //} - //echo '
' . print_r($pages, true) . '
'; - //return; - //exit; $numPagesImported = count($pages); foreach ($pages as $page) { @@ -1206,7 +1200,16 @@ } } - 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']) { @@ -1215,7 +1218,10 @@ $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 '
' . print_r($row, true) . '
'; $fileName = $row['name_on_disk']; @@ -1225,7 +1231,7 @@ $fileTitle, '', 0, - $this->_options['toolbox_image_url'] . '/CKImage/' + $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/' ); echo '
' . print_r($wpImage, true) . '
'; $this->_images[$wpImage] = $fileName; @@ -1290,7 +1296,7 @@ $fileTitle, '', 0, - $this->_options['toolbox_image_url'] . '/CKImage/' + $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/' ); echo '
' . print_r($wpImage, true) . '
'; $this->_images[$wpImage] = $fileName; @@ -1321,7 +1327,7 @@ $fileTitle, '', 0, - $this->_options['toolbox_image_url'] . '/CKImage/' + $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/' ); echo '
' . print_r($wpImage, true) . '
'; $this->_images[$wpImage] = $fileName; @@ -1352,7 +1358,7 @@ $fileTitle, '', 0, - $this->_options['toolbox_image_url'] . '/CKImage/' + $this->_options['toolbox_image_url'] . '/'.$this->_imageSize.'/' ); echo '
' . print_r($wpImage, true) . '
'; $this->_images[$wpImage] = $fileName; @@ -1401,20 +1407,41 @@ echo '

Step Two (Importing Images)

'; break; case 2: + $imageLimit = 100; echo '

Done

'; echo '

Now processing the images from old database tables

'; - $this->_images = array(); - $this->_storeImages(); - if ($this->_options['toolbox_page_table'] == 'pages') { - $this->_getCkImages(); - $this->_getParagraphImages(); - echo '

Done

'; + if (isset($_REQUEST['start'])) { + echo '

Second Part of the images

'; + $totalImages = $this->_getCkImageCount(); + echo '

Number of images in ckimage ' . $totalImages . '

'; + $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); + if ($start > $totalImages ) { + echo '

Done

'; + echo '

Step Three (Importing Files)

'; + } else { + $this->_getCkImages( $imageLimit, $start ); + $start += $imageLimit; + $endCount = $start + $imageLimit; + echo '

+ Step Two [' . $start . ' - ' . $endCount . ']

'; + } } else { - $this->_getBusCategoryImages(); - $this->_getBusImages(); - echo '

No import from images

'; + $start = 0; + $this->_images = array(); + $this->_storeImages(); + if ($this->_options['toolbox_page_table'] == 'pages') { + $this->_getParagraphImages(); + echo '

Done with Paragraph images

'; + $endCount = $start + $imageLimit; + echo '

+ Step Two [' . $start . ' - ' . $endCount . ']

'; + } else { + $this->_getBusCategoryImages(); + $this->_getBusImages(); + echo '

No import from images

'; + echo '

Step Three (Importing Files)

'; + } } - echo '

Step Three (Importing Files)

'; break; case 3: echo '

Done

'; -- 2.17.1