Setting up for 5 pages per import
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 15 Jul 2015 18:41:46 +0000 (14:41 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 15 Jul 2015 18:41:46 +0000 (14:41 -0400)
with continue button

controllers/Import.php

index 1cc15bb..92927d0 100644 (file)
@@ -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';
                 $sql = "SELECT * FROM toolbox.pages";
                 $data = $this->_dbh->query($sql)->fetchAll();
                 printf('<p>Found %d Pages</p>', count($data));
-                echo '<p><a href="admin.php?import=toolbox&amp;step=1">Start the Import Now</a></p>';
                 echo '<p><a href="admin.php?import=toolbox&amp;step=2">Part 2</a></p>';
             }
         }
          * @access private
          * @return void
          */
-        private function _fetchAllPages()
+        private function _fetchAllPages($limit = null, $offset = 0)
         {
             $this->_connect();
             $where = array();
                 $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);
             }
                 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 *
         private function _import()
         {
             echo '<p>Fetching Pages</p>';
+            $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 ?
                     '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);
                     }
                 }
             }
+            return $numPagesImported;
         }
 
         private function _replaceKeywords()
             case 0:
                 $this->_greet();
                 $this->_readOptions();
+                echo '<p><a href="admin.php?import=toolbox&amp;step=1&start=0">Begin Import</a></p>';
                 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 '<p>
+                    Start: ' . $start . '</p>
+                    <p>' . $numPagesImported . ' Pages Imported
+                    <form action="admin.php" method="get"><input type="hidden" name="postsarr" value="' . serialize($this->_post) . '">
+                    <input type="hidden" name="import" value="toolbox">
+                    <input type="hidden" name="step" value="1">
+                    <input type="hidden" name="start" value="' . $start . '">
+                    <input type="submit" value="Continue">
+                    </form>
+                    </p>';
                 echo '<p><a href="admin.php?import=toolbox&amp;step=2">Part 2</a></p>';
                 break;
             case 2: