SELECT count(*)
FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']}
$WHERE";
- echo '<pre>' . $sql . '</pre>';
+ //echo '<pre>' . $sql . '</pre>';
$totalPages = $this->_dbh->query($sql)->fetchColumn();
printf('<p>Found %d Pages</p>', $totalPages);
//echo '<p><a href="admin.php?import=toolbox&step=2">Part 2</a></p>';
$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'] .= '<h2>'.$page['category'].'</h2>';
} else {
- $page['title'] .= $page['category'];
+ $page['title'] = $page['category'];
}
++$iterator;
if ($page['image']) {
$fileStmt->bindParam(':pid', $paragraph['id'], PDO::PARAM_INT);
$fileStmt->execute();
while ($file = $fileStmt->fetch()) {
- echo '<pre>$file: ' . print_r($file, true) . '</pre>';
+ //echo '<pre>$file: ' . print_r($file, true) . '</pre>';
if ($this->_options['toolbox_files_table'] == 'files') {
$page['pageContent'] .= $this->_displayFile($file);
} else {
private function _import()
{
+ global $wpdb;
echo '<p>Fetching Pages</p>';
$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']) {
? $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 '<pre>';
+ //var_dump( $post );
+ //echo '</pre>';
+ //echo '<pre>';
+ //var_dump( $ID );
+ //echo '</pre>';
+ //echo '<pre>$post: ' . print_r( $post, true ) . '</pre>';
+ $error_string = $ID->get_error_messages();
+ echo '<p>page name: ' . $post['post_title'] . '</p>';
+ echo '<pre>$error_string: ' . print_r( $error_string, true ) . '</pre>';
+ exit;
+ }
$newPost = get_post($ID, ARRAY_A);
$this->_post[$page['id']] = $ID;
}
+ $wpdb->query( 'COMMIT' );
$this->_storePost();
return $numPagesImported;
}
$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);
switch($step) {
case 0:
$this->_greet();
- echo '<pre>$this->_options: ' . print_r( $this->_options, true ) . '</pre>';
+ //echo '<pre>$this->_options: ' . print_r( $this->_options, true ) . '</pre>';
echo '<p><a href="admin.php?import=toolbox&step=1">Begin Import</a></p>';
$currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array());
- echo '<pre>' . print_r($currentPostArray, true) . '</pre>';
+ //echo '<pre>' . print_r($currentPostArray, true) . '</pre>';
$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
- echo '<pre>' . print_r($images, true) . '</pre>';
+ //echo '<pre>' . print_r($images, true) . '</pre>';
$files = get_option(GLM_WP_IMPORT_FILES_OPTION, array());
- echo '<pre>' . print_r($files, true) . '</pre>';
+ //echo '<pre>' . print_r($files, true) . '</pre>';
if (count($currentPostArray) > 0) {
echo '<p>Pages have been imported</p>';
echo '<p><a href="admin.php?import=toolbox&step=2">Step Two (Importing Images)</a></p>';