From: Steve Sutton Date: Fri, 20 Jan 2017 19:17:23 +0000 (-0500) Subject: Work with older database like chucks site X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=82d52cfcffc78dbb3498d92f73104da9ae17d136;p=WP-Plugins%2Fglm-wp-importer.git Work with older database like chucks site n8dnx.org --- diff --git a/controllers/ToolboxImport.php b/controllers/ToolboxImport.php index 573b4eb..241c4c3 100644 --- a/controllers/ToolboxImport.php +++ b/controllers/ToolboxImport.php @@ -154,7 +154,7 @@ 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

'; @@ -437,10 +437,10 @@ $page['pageContent'] = ''; $iterator = 1; if ($this->_options['toolbox_page_table'] == 'bus_category') { - if ( $this->_options['navigation_name_in_content'] ) { + if ( isset( $this->_options['navigation_name_in_content'] ) && $this->_options['navigation_name_in_content'] ) { $page['pageContent'] .= '

'.$page['category'].'

'; } else { - $page['title'] .= $page['category']; + $page['title'] = $page['category']; } ++$iterator; if ($page['image']) { @@ -495,7 +495,7 @@ $fileStmt->bindParam(':pid', $paragraph['id'], PDO::PARAM_INT); $fileStmt->execute(); while ($file = $fileStmt->fetch()) { - echo '
$file: ' . print_r($file, true) . '
'; + //echo '
$file: ' . print_r($file, true) . '
'; if ($this->_options['toolbox_files_table'] == 'files') { $page['pageContent'] .= $this->_displayFile($file); } else { @@ -524,13 +524,16 @@ private function _import() { + global $wpdb; echo '

Fetching Pages

'; $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); + $start = (isset($_REQUEST['start'])) ? filter_var($_REQUEST['start'], FILTER_VALIDATE_INT): 0; $pages = $this->_fetchAllPages(); $numPagesImported = count($pages); + + $wpdb->query( 'BEGIN' ); foreach ($pages as $page) { if ($page['parent']) { @@ -547,21 +550,36 @@ ? $this->_post[$page['parent']] : (($this->_options['parent_page']) ? $this->_options['parent_page'] : 0); $post = array( - 'post_content' => $page['pageContent'], - 'post_name' => $pageName,// slug ? - 'post_title' => $pageName, + 'post_content' => iconv( 'ISO-8859-1', 'UTF-8//IGNORE', $page['pageContent'] ), + 'post_name' => wp_strip_all_tags($pageName),// slug ? + 'post_title' => wp_strip_all_tags($pageName), 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => 'steve', 'ping_status' => 'closed', 'post_parent' => $parent, - 'menu_order' => $page['pos'], + 'menu_order' => ($page['pos']) ? $page['pos'] : 0, 'comment_status' => 'closed', ); $ID = wp_insert_post($post, true); + if ( is_wp_error( $ID ) ) { + $wpdb->query( 'ROLLBACK' ); + //echo '
';
+                    //var_dump( $post );
+                    //echo '
'; + //echo '
';
+                    //var_dump( $ID );
+                    //echo '
'; + //echo '
$post: ' . print_r( $post, true ) . '
'; + $error_string = $ID->get_error_messages(); + echo '

page name: ' . $post['post_title'] . '

'; + echo '
$error_string: ' . print_r( $error_string, true ) . '
'; + exit; + } $newPost = get_post($ID, ARRAY_A); $this->_post[$page['id']] = $ID; } + $wpdb->query( 'COMMIT' ); $this->_storePost(); return $numPagesImported; } @@ -1347,7 +1365,7 @@ $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); $this->_connect(); $sql = " - SELECT image,imagename as caption + SELECT image -- ,imagename as caption FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} WHERE image != ''"; $stmt = $this->_dbh->query($sql); @@ -1380,14 +1398,14 @@ switch($step) { case 0: $this->_greet(); - echo '
$this->_options: ' . print_r( $this->_options, true ) . '
'; + //echo '
$this->_options: ' . print_r( $this->_options, true ) . '
'; echo '

Begin Import

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

Pages have been imported

'; echo '

Step Two (Importing Images)

';