'Serendipity');
var $data = array();
var $inputFields = array();
var $categories = array();
var $execute = true;
var $debug = true;
var $counter = 0;
function getImportNotes() {
return 'This importer is still work in progress. It can currently import most things of the database. HOWEVER it can NOT import previously installed plugins (including their configuration) or any database tables of installed plugins. Those must be migrated manually. Also, you must use FTP to transfer your uploaded images to the new location.
Please do a test-run first if you are SQL-savvy. If you encounter any errors, save the message output you get - it will definitely help debugging!
This is NOT an importer meant for upgrading Serendipity. This importer assumes that both Serendipity installations use the same version.';
}
function Serendipity_Import_Serendipity ($data) {
global $serendipity;
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',
'name' => 'host',
'default' => $serendipity['dbHost']),
array('text' => INSTALL_DBUSER,
'type' => 'input',
'name' => 'user',
'default' => $serendipity['dbUser']),
array('text' => INSTALL_DBPASS,
'type' => 'fullprotected',
'name' => 'pass'),
array('text' => INSTALL_DBNAME,
'type' => 'input',
'name' => 'name',
'default' => $serendipity['dbName']),
array('text' => INSTALL_DBPREFIX,
'type' => 'input',
'name' => 'prefix',
'default' => $serendipity['dbPrefix'] . 'import_'),
array('text' => CHARSET,
'type' => 'list',
'name' => 'charset',
'value' => 'UTF-8',
'default' => $this->getCharsets(true)),
array('text' => CONVERT_HTMLENTITIES,
'type' => 'bool',
'name' => 'use_strtr',
'default' => 'false'),
array('text' => 'Import Targets',
'type' => 'multilist',
'name' => 'targets',
'select_size' => 6,
'default' => array(
array('confkey' => 'groups' , 'confvalue' => 'Groups'),
array('confkey' => 'authors', 'confvalue' => 'Authors'),
array('confkey' => 'entries', 'confvalue' => 'Entries'),
array('confkey' => 'media' , 'confvalue' => 'Media'),
array('confkey' => 'cat' , 'confvalue' => 'Categories')
)
),
array('text' => 'Make a verbose test run',
'type' => 'bool',
'name' => 'preflight',
'default' => 'false')
);
}
function validateData() {
return sizeof($this->data);
}
function getInputFields() {
return $this->inputFields;
}
function import_table(&$s9ydb, $table, $primary_keys, $where = null, $dupe_check = false, $fix_relations = false, $skip_dupes = false) {
global $serendipity;
echo "
Starting with table {$table}...
\n";
if ($dupe_check) {
$dupes = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}" . $table . " " . $where, false, 'both', false, $dupe_check);
if (!$this->execute) {
echo 'Dupe-Check:
' . print_r($dupes, true) . ''; } } $res = $this->nativeQuery("SELECT * FROM {$this->data['prefix']}" . $table . " " . $where, $s9ydb); echo mysql_error($s9ydb); if (!$res || mysql_num_rows($res) < 1) { return false; } $this->counter = 100; while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $this->counter++; if (is_array($primary_keys)) { foreach($primary_keys AS $primary_key) { $primary_vals[$primary_key] = $row[$primary_key]; unset($row[$primary_key]); } } else { $primary_vals = array(); } $insert = true; if (is_array($fix_relations)) { foreach($fix_relations AS $primary_key => $fix_relation) { foreach($fix_relation AS $fix_relation_table => $fix_relation_primary_key) { if (isset($primary_vals[$fix_relation_primary_key])) { $assoc_val = $primary_vals[$fix_relation_primary_key]; } else { $assoc_val = $row[$primary_key]; } if (!$this->execute && empty($assoc_val)) { if ($this->debug) { echo '
';
print_r($row);
print_r($fix_relation);
echo '';
}
}
$new_val = $this->storage[$fix_relation_table][$fix_relation_primary_key][$assoc_val];
if ($skip_dupes && $assoc_val == $new_val) {
$insert = false;
}
if (!empty($new_val)) {
$row[$primary_key] = $new_val;
}
if (!$this->execute && $this->debug) {
echo "Fix relation from $fix_relation_table.$fix_relation_primary_key={$primary_vals[$fix_relation_primary_key]} to {$row[$primary_key]} (assoc_val: $assoc_val)" . print_r($dupes[$row[$dupe_check]], true) . "
' . print_r($row, true) . ''; } foreach($primary_vals AS $primary_key => $primary_val) { $this->storage[$table][$primary_key][$primary_val] = $this->counter; } } } else { if ($this->debug && !$this->execute) { echo "Ignoring Duplicate.
' . print_r($this->storage[$table], true) . ''; } else { echo "Finished table {$table}