1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Allow for importing of table data from e107 v1.x "Content Management" plugin into "Pages/Menus" tables.

This commit is contained in:
Cameron 2017-03-22 13:57:11 -07:00
parent e1ce2f528d
commit 0ec1c74e6b
5 changed files with 298 additions and 17 deletions

View File

@ -96,6 +96,7 @@ class import_main_ui extends e_admin_ui
'users' => array('message' => LAN_CONVERT_25, 'classfile' => 'import_user_class.php', 'classname' => 'user_import'),
'news' => array('message' => LAN_CONVERT_28, 'classfile' => 'import_news_class.php', 'classname' => 'news_import'),
'page' => array('message' => "Pages", 'classfile' => 'import_page_class.php', 'classname' => 'page_import'),
'pagechapter' => array('message' => "Page Chapters", 'classfile' => 'import_pagechapter_class.php', 'classname' => 'pagechapter_import'),
'links' => array('message' => "Links", 'classfile' => 'import_links_class.php', 'classname' => 'links_import'),
'media' => array('message' => "Media", 'classfile' => 'import_media_class.php', 'classname' => 'media_import'),
'forum' => array('message' => "Forum", 'classfile' => 'import_forum_class.php', 'classname' => 'forum_import'),
@ -547,7 +548,8 @@ class import_main_ui extends e_admin_ui
$text .= "
<tr>
<td>".LAN_CONVERT_38."</td>
<td>".$frm->checkbox('import_delete_existing_data', 1,$_POST['import_delete_existing_data'], array('label'=>'&nbsp;','title'=>LAN_CONVERT_39))."</td>
<td>".$frm->radio_switch('import_delete_existing_data', $_POST['import_delete_existing_data'])."
<div class='field-help'>".LAN_CONVERT_39."</div></td>
</tr>";
//TODO
@ -732,6 +734,7 @@ class import_main_ui extends e_admin_ui
if ($this->deleteExisting == true)
{
$mes->addDebug("dbImport(): Emptying target table. ");
$exporter->emptyTargetDB(); // Clean output DB - reasonably safe now
}

View File

@ -71,6 +71,10 @@ class base_import_class
return $this->savePageData($dataRecord);
break;
case 'pagechapter' :
return $this->savePageChapterData($dataRecord);
break;
case 'links' :
return $this->saveLinksData($dataRecord);
break;
@ -110,7 +114,7 @@ class base_import_class
{
if($mode == 'db')
{
$result = $this->ourDB->db_Fetch();
$result = $this->ourDB->fetch();
}
else
{
@ -134,6 +138,10 @@ class base_import_class
return $this->copyPageData($initial, $result);
break;
case 'pagechapter' :
return $this->copyPageChapterData($initial, $result);
break;
case 'links' :
return $this->copyLinksData($initial, $result);
break;
@ -197,7 +205,12 @@ class base_import_class
{
return $target;
}
function copyPageChapterData(&$target, &$source)
{
return $target;
}
function copyLinksData(&$target, &$source)
{
return $target;

View File

@ -41,14 +41,14 @@ class page_import
'page_metakeys' => '',
'page_metadscr' => '',
'page_text' => '',
'page_author' => 1,
'page_author' => USERID,
'page_datestamp' => '',
'page_rating_flag' => '0',
'page_comment_flag' => '0',
'page_password' => '',
'page_class' => '0',
'page_ip_restrict' => '',
'menu_name' => '',
'menu_name' => '',
'page_template' => 'default'
);
@ -61,15 +61,14 @@ class page_import
// Constructor
function __construct()
{
global $sql;
$this->pageDB = new db; // Have our own database object to write to the table
$this->pageDB = e107::getDb('page'); // Have our own database object to write to the table
}
// Empty the DB - not necessary
function emptyTargetDB($inc_admin = FALSE)
{
// $this->pageDB->db_Delete('page');
$this->pageDB->truncate('page');
}
@ -95,7 +94,7 @@ class page_import
*/
function saveData($row)
{
if(!$result = $this->pageDB->db_Insert('page',$row))
if(!$result = $this->pageDB->insert('page',$row))
{
return 4;
}
@ -109,6 +108,7 @@ class page_import
function getErrorText($errnum) // these errors are presumptuous and misleading. especially '4' .
{
return $this->pageDB->getLastErrorText();
$errorTexts = array(
0 => 'No error',
1 => 'Can\'t change main admin data',

View File

@ -0,0 +1,154 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/import/import_user_class.php,v $
* $Revision: 11315 $
* $Date: 2010-02-10 10:18:01 -0800 (Wed, 10 Feb 2010) $
* $Author: secretr $
*/
/*
Class intended to simplify importing of user information from outside.
It ensures that each user record has appropriate defaults
To use:
1. Create one instance of the class
2. Call emptyUserDB() to delete existing users
3. If necessary, call overrideDefault() as necessary to modify the defaults
4. For each record:
a) Call getDefaults() to get a record with all the defaults filled in
b) Update the record from the source database
c) Call saveUser($userRecord) to write the record to the DB
*/
class pagechapter_import
{
var $pageDB = null;
var $blockMainAdmin = true;
var $error;
var $defaults = array(
'chapter_id' => '',
'chapter_parent' => 1,
'chapter_name' => '',
'chapter_sef' => '',
'chapter_meta_description' => '',
'chapter_meta_keywords' => '',
'chapter_manager' => e_UC_ADMIN,
'chapter_icon' => '',
'chapter_order' => 0,
'chapter_template' => 'default',
'chapter_visibility' => 0,
'chapter_fields' => null
);
// Fields which must be set up by the caller.
var $mandatory = array(
'chapter_name'
);
// Constructor
function __construct()
{
$this->pageDB = e107::getDb('pagechapter'); // Have our own database object to write to the table
}
// Empty the DB
function emptyTargetDB($inc_admin = FALSE)
{
$this->pageDB->truncate('page_chapters');
$insert = array(
'chapter_id' => '1',
'chapter_parent' => '0',
'chapter_name' => 'General',
'chapter_sef' => 'general',
'chapter_meta_description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec et tempor odio. Quisque volutpat lorem nec lectus congue suscipit. In hac habitasse platea dictumst. Etiam odio nisi, egestas vitae amet.',
'chapter_meta_keywords' => '',
'chapter_manager' => '0',
'chapter_icon' => '',
'chapter_order' => '0',
'chapter_template' => 'default',
'chapter_visibility' => '0',
'chapter_fields' => null
);
$this->pageDB->insert('page_chapters',$insert); // insert a default book.
}
// Set a new default for a particular field
function overrideDefault($key, $value)
{
// echo "Override: {$key} => {$value}<br />";
if (!isset($this->defaults[$key])) return FALSE;
$this->defaults[$key] = $value;
}
// Returns an array with all relevant fields set to the current default
function getDefaults()
{
return $this->defaults;
}
/**
* Insert data into e107 DB
* @param row - array of table data
* @return integer, boolean - error code on failure, TRUE on success
*/
function saveData($row)
{
if(empty($row['chapter_name']))
{
return 3;
}
if(!$result = $this->pageDB->insert('page_chapters',$row))
{
return 4;
}
//if ($result === FALSE) return 6;
return true;
}
function getErrorText($errnum) // these errors are presumptuous and misleading. especially '4' .
{
$errorTexts = array(
0 => 'No error',
1 => 'Can\'t change main admin data',
2 => 'invalid field passed',
3 => 'Mandatory field not set',
4 => 'Entry already exists',
5 => 'Invalid characters in user or login name',
6 => 'Error saving extended user fields'
);
if (isset($errorTexts[$errnum])) return $errorTexts[$errnum];
return 'Unknown: '.$errnum;
}
}
?>

View File

@ -34,11 +34,33 @@ class e107_import extends base_import_class
public $title = 'e107';
public $description = 'Reads 0.7 and 0.8 version files';
public $supported = array('users');
public $supported = array('users', 'page', 'pagechapter');
public $mprefix = 'e107_';
function init()
{
$this->pcontent = intval($_POST['pcontent']);
}
function config()
{
$frm = e107::getForm();
$present = e107::getDb()->isTable('pcontent');
$var[0]['caption'] = "Use old 'Content Management' tables for Pages";
$var[0]['html'] = $frm->radio_switch('pcontent',$present);
// $var[0]['help'] = "Change the author of the news items";
// $var[1]['caption'] = "Include revisions";
// $var[1]['html'] = $frm->checkbox('news_revisions',1);
// $var[1]['help'] = "Change the author of the news items";
return $var;
}
// Set up a query for the specified task.
// Returns TRUE on success. FALSE on error
@ -47,13 +69,27 @@ class e107_import extends base_import_class
if ($this->ourDB == NULL) return FALSE;
switch ($task)
{
case 'users' :
$query = "SELECT * FROM {$this->DBPrefix}user WHERE `user_id` != 1";
$result = $this->ourDB->db_Select_gen($query);
case 'users' :
$query = "SELECT * FROM {$this->DBPrefix}user WHERE `user_id` != 1";
$result = $this->ourDB->db_Select_gen($query);
if ($result === FALSE) return FALSE;
if ($result === false) return false;
break;
case 'page' :
$query = "SELECT * FROM {$this->DBPrefix}pcontent WHERE `content_parent` > 0";
$result = $this->ourDB->gen($query);
if ($result === false) return false;
break;
case 'pagechapter' :
$query = "SELECT * FROM {$this->DBPrefix}pcontent WHERE `content_parent` = '0'";
$result = $this->ourDB->gen($query);
if ($result === false) return false;
break;
default :
@ -66,6 +102,81 @@ class e107_import extends base_import_class
}
/**
* Align source data to e107 Page Table
* @param $target array - default e107 target values for e107_page table.
* @param $source array - WordPress table data
*/
function copyPageData(&$target, &$source)
{
// $target['page_id'] = $source['ID']; // auto increment
$target['page_title'] = $source['content_heading'];
$target['page_sef'] = eHelper::title2sef($source['content_heading'], 'dashl');
$target['page_text'] = $this->checkHtml($source['content_text']) ;
$target['page_chapter'] = $source['content_parent'];
// $target['page_metakeys'] = '';
$target['page_metadscr'] = $source['content_summary'];
$target['page_datestamp'] = $source['content_datestamp'];
$target['page_author'] = (int) $source['content_author'];
// $target['page_category'] = '',
$target['page_comment_flag'] = (int) $source['content_comment'];
$target['page_rating_flag'] = (int) $source['content_rate'];
// $target['page_password'] = $source['post_password'];
$target['page_order'] = (int) $source['content_order'];
$target['page_class'] = (int) $source['content_class'];
return $target; // comment out to debug
}
private function checkHtml($text)
{
$tp = e107::getParser();
if($tp->isHtml($text) && strpos($text,'[html]')!==0)
{
return "[html]".$text."[/html]";
}
return $text;
}
/**
* Align source data to e107 Page Table
* @param $target array - default e107 target values for e107_page table.
* @param $source array - WordPress table data
*/
function copyPageChapterData(&$target, &$source)
{
$target['chapter_id'] = $source['content_id'];
$target['chapter_parent'] = empty($source['content_parent']) ? 1 : (int) $source['content_parent'];
$target['chapter_name'] = $source['content_heading'];
$target['chapter_sef'] = eHelper::title2sef($source['content_heading'], 'dashl');
$target['chapter_meta_description'] = $source['content_text'];
$target['chapter_meta_keywords'] = '';
// $target['chapter_manager'] = '';
$target['chapter_icon'] = $source['content_icon'];
$target['chapter_order'] = 0;
// $target['chapter_template'] = '';
// $target['chapter_visibility'] = 0;
// $target['chapter_fields'] = '';
return $target; // comment out to debug
}
//------------------------------------
// Internal functions below here
//------------------------------------