From: Steve Sutton Date: Wed, 15 Jul 2015 18:41:46 +0000 (-0400) Subject: Setting up for 5 pages per import X-Git-Tag: v0.0.2^2~34 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d24a54b6330f3cdcceb89eb1a17a6af16ba7e174;p=WP-Plugins%2Fglm-wp-importer.git Setting up for 5 pages per import with continue button --- diff --git a/controllers/Import.php b/controllers/Import.php index 1cc15bb..92927d0 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -31,6 +31,7 @@ return; } require_once ABSPATH . 'wp-admin/includes/import.php'; + define('PAGES_PER_LOAD', 5); if ( !class_exists( 'WP_Importer' ) ) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; @@ -203,7 +204,6 @@ $sql = "SELECT * FROM toolbox.pages"; $data = $this->_dbh->query($sql)->fetchAll(); printf('

Found %d Pages

', count($data)); - echo '

Start the Import Now

'; echo '

Part 2

'; } } @@ -368,7 +368,7 @@ * @access private * @return void */ - private function _fetchAllPages() + private function _fetchAllPages($limit = null, $offset = 0) { $this->_connect(); $where = array(); @@ -380,6 +380,7 @@ $where[] = "id NOT IN ({$this->_options['exclude_pages']}) AND parent NOT IN ({$this->_options['exclude_pages']}) "; } + $where[] = "active = true"; if (!empty($where)) { $WHERE = ' WHERE ' . implode(' AND ', $where); } @@ -388,6 +389,7 @@ FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} $WHERE ORDER BY parent,pos"; + $pageSql .= " LIMIT $limit OFFSET $offset"; $pageData = $this->_dbh->query($pageSql)->fetchAll(PDO::FETCH_ASSOC); $paragraphSql = " SELECT * @@ -515,10 +517,17 @@ private function _import() { echo '

Fetching Pages

'; + $postarr = unserialize(stripslashes($_REQUEST['postsarr'])); + $this->_post = $postarr; // grab all pages and build the post array - $pages = $this->_fetchAllPages(); + $start = filter_var($_REQUEST['start'], FILTER_VALIDATE_INT); + $pages = $this->_fetchAllPages(PAGES_PER_LOAD, $start); + $numPagesImported = count($pages); foreach ($pages as $page) { + if ($page['parent']) { + + } $post = array( 'post_content' => $page['pageContent'], 'post_name' => $page['navigation_name'],// slug ? @@ -527,13 +536,13 @@ 'post_type' => 'page', 'post_author' => 'steve', 'ping_status' => 'closed', - 'post_parent' => $this->_post[$page['parent']]['ID'], + 'post_parent' => $this->_post[$page['parent']], 'menu_order' => $page['pos'], 'comment_status' => 'closed', ); $ID = wp_insert_post($post, true); $newPost = get_post($ID, ARRAY_A); - $this->_post[$page['id']] = $newPost; + $this->_post[$page['id']] = $ID; if (isset($page['srcs']) && !empty($page['srcs'])) { foreach ($page['srcs'] as $image) { $img_id = array_search($image, $this->_files); @@ -560,6 +569,7 @@ } } } + return $numPagesImported; } private function _replaceKeywords() @@ -685,9 +695,26 @@ case 0: $this->_greet(); $this->_readOptions(); + echo '

Begin Import

'; break; case 1: - $this->_import(); + $numPagesImported = $this->_import(); + $start = filter_var($_REQUEST['start'], FILTER_VALIDATE_INT); + if ($start === false) { + $start = 0; + } else { + $start += PAGES_PER_LOAD; + } + echo '

+ Start: ' . $start . '

+

' . $numPagesImported . ' Pages Imported +

+ + + + +
+

'; echo '

Part 2

'; break; case 2: