From c0477ebf70dd719d77498a5daae0dd7a790fa3e6 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 7 Aug 2015 15:43:54 -0400 Subject: [PATCH] Start over with the redo Part 1 fetch and build all pages. Part 2 import all media --- controllers/Import.php | 135 +++++++++++++++++++++++++++++++++++++---- index.php | 2 + 2 files changed, 125 insertions(+), 12 deletions(-) diff --git a/controllers/Import.php b/controllers/Import.php index c36b3a4..cea8439 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -150,10 +150,10 @@ SELECT count(*) FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} $WHERE"; - echo '
' . $sql . '
'; + //echo '
' . $sql . '
'; $totalPages = $this->_dbh->query($sql)->fetchColumn(); printf('

Found %d Pages

', $totalPages); - echo '

Part 2

'; + //echo '

Part 2

'; } } @@ -230,8 +230,13 @@ return ($id) ? $this->_getAttachmentById($id) : false; } - private function _handleMediaFile($file, $caption = '', $post_id = 0, $baseUrl = null) - { + private function _handleMediaFile( + $file, + $file_title, + $caption = '', + $post_id = 0, + $baseUrl = null + ) { $id = array_search($file, $this->_files); if ($id === false) { set_time_limit(120); @@ -268,7 +273,7 @@ 'post_mime_type' => $wp_filetype['type'], 'guid' => $url, 'post_parent' => $post_id, - 'post_title' => $title, + 'post_title' => $file_title, 'post_name' => $title, 'post_content' => $content, 'post_excerpt' => $caption, @@ -571,6 +576,16 @@ update_option(GLM_WP_IMPORT_POST_OPTION, $this->_post); } + private function _storeImages() + { + update_option(GLM_WP_IMPORT_IMAGES_OPTION, $this->_images); + } + + private function _storeFiles() + { + update_option(GLM_WP_IMPORT_FILES_OPTION, $this->_files); + } + private function _replaceKeywords() { global $wpdb; @@ -981,17 +996,95 @@ { global $wpdb; if ($this->_options['ckeditor_schema'] && $this->_options['ckeditor_images_table']) { + $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); $this->_connect(); - $ckimagesSql = " + $sql = " SELECT * FROM {$this->_options['ckeditor_schema']}.{$this->_options['ckeditor_images_table']}"; - $ckData = $this->_dbh->query($ckimagesSql)->fetchAll(); - echo '
' . print_r($ckData, true) . '
'; + $stmt = $this->_dbh->query($sql); + while ($row = $stmt->fetch()) { + echo '
' . print_r($row, true) . '
'; + $fileName = $row['name_on_disk']; + $fileTitle = ($row['file_name']) ? $row['file_name'] : $fileName; + $wpImage = $this->_handleMediaFile( + $fileName, + $fileTitle, + '', + 0, + $this->_options['toolbox_image_url'] . '/CKImage/' + ); + echo '
' . print_r($wpImage, true) . '
'; + $this->_images[$wpImage] = $fileName; + } + $this->_storeImages(); + } else { + return false; + } + } + + private function _getToolboxFiles() + { + global $wpdb; + echo '
' . print_r($this->_options['toolbox_schema'], true) . '
'; + echo '
' . print_r($this->_options['toolbox_files_table'], true) . '
'; + if ($this->_options['toolbox_files_table']) { + $this->_files = get_option(GLM_WP_IMPORT_FILES_OPTION, array()); + $this->_connect(); + $sql = " + SELECT * + FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_files_table']}"; + $stmt = $this->_dbh->query($sql); + while ($row = $stmt->fetch()) { + echo '
' . print_r($row, true) . '
'; + $fileName = $row['filename']; + $fileTitle = ($row['urltext']) ? $row['urltext'] : $fileName; + $wpImage = $this->_handleMediaFile( + $fileName, + $fileTitle, + '', + 0, + $this->_options['toolbox_image_url'] . '/_ORIGINAL_/' + ); + echo '
' . print_r($wpImage, true) . '
'; + $this->_files[$wpImage] = $fileName; + } + $this->_storeFiles(); } else { return false; } } + private function _getParagraphImages() + { + global $wpdb; + echo '
' . print_r($this->_options['toolbox_schema'], true) . '
'; + echo '
' . print_r($this->_options['toolbox_paragraphs_table'], true) . '
'; + 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 '
' . print_r($row, true) . '
'; + $fileName = $row['image']; + $fileTitle = ($row['caption']) ? $row['caption'] : $fileName; + $wpImage = $this->_handleMediaFile( + $fileName, + $fileTitle, + '', + 0, + $this->_options['toolbox_image_url'] . '/tbs1/' + ); + echo '
' . print_r($wpImage, true) . '
'; + $this->_images[$wpImage] = $fileName; + } + $this->_storeImages(); + } + } + public function dispatch() { $this->_header(); @@ -1006,9 +1099,19 @@ //$this->post = array(); //$this->_storePost(); $this->_greet(); - $this->_readOptions(); - echo '

CkImages

'; - echo '

Begin Import

'; + //$this->_readOptions(); + //echo '

CkImages

'; + $currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array()); + $images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); + echo '
' . print_r($images, true) . '
'; + $files = get_option(GLM_WP_IMPORT_FILES_OPTION, array()); + echo '
' . print_r($files, true) . '
'; + if (count($currentPostArray) > 0) { + echo '

Pages have been imported

'; + echo '

Step Two

'; + } else { + echo '

Begin Import

'; + } break; case 1: $numPagesImported = $this->_import(); @@ -1030,7 +1133,15 @@ echo '

Part 2

'; break; case 2: - $this->_replaceSrc(); + echo '

Now processing the images from old database tables

'; + $this->_images = array(); + $this->_storeImages(); + $this->_files = array(); + $this->_storeFiles(); + $this->_getCkImages(); + $this->_getToolboxFiles(); + $this->_getParagraphImages(); + //$this->_replaceSrc(); //$this->_replaceKeywords(); //$this->replaceIsoUrls(); echo '

Done

'; diff --git a/index.php b/index.php index babe773..f8cda2b 100644 --- a/index.php +++ b/index.php @@ -11,6 +11,8 @@ define('GLM_WP_IMPORT_SETTINGS', 'glm_wp_import_settings'); define('GLM_WP_IMPORT_CAPABILITY', 'manage_options'); define('GLM_WP_IMPORT_OPTION_GROUP', 'glmwp_import_group'); define('GLM_WP_IMPORT_POST_OPTION', 'glmwp_import_posts'); +define('GLM_WP_IMPORT_IMAGES_OPTION', 'glmwp_import_images'); +define('GLM_WP_IMPORT_FILES_OPTION', 'glmwp_import_files'); if (is_admin()) { require_once 'controllers/Admin.php'; -- 2.17.1