1
0

Better checks to see if the local PEAR inclusion is required

This commit is contained in:
Garvin Hicking
2007-02-22 11:56:26 +00:00
parent ad469c127c
commit f0c9a37804
3 changed files with 169 additions and 131 deletions

View File

@ -3,6 +3,12 @@
Version 1.2 () Version 1.2 ()
------------------------------------------------------------------------ ------------------------------------------------------------------------
* Improve memory usage of WordPress importer, add debug output
(garvinhicking)
* EXPERIMENTAL: Modify session language fetch function to allow
earlier plugin API calls (Rob Richards)
* No longer accept trackbacks to draft entries.Thanks to j_b_poquelin * No longer accept trackbacks to draft entries.Thanks to j_b_poquelin
(garvinhicking) (garvinhicking)
@ -64,7 +70,13 @@ Version 1.2 ()
* Allow to call permalinks that end with a "/" the same as if not * Allow to call permalinks that end with a "/" the same as if not
ending with a "/" (garvinhicking) ending with a "/" (garvinhicking)
Version 1.1.1 () Version 1.1.2 ()
-----------------------------------------------------------------------
* Better checks to see if the local PEAR inclusion is required
(garvinhicking)
Version 1.1.1 (February 22nd, 2007)
------------------------------------------------------------------------ ------------------------------------------------------------------------
* Patch plugin permissionship management to properly indicate * Patch plugin permissionship management to properly indicate

View File

@ -68,6 +68,7 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
function import() { function import() {
global $serendipity; global $serendipity;
static $debug = true;
// Save this so we can return it to its original value at the end of this method. // Save this so we can return it to its original value at the end of this method.
$noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
@ -84,7 +85,11 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
$entries = array(); $entries = array();
if ( !extension_loaded('mysql') ) { if ( !extension_loaded('mysql') ) {
return MYSQL_REQUIRED;; return MYSQL_REQUIRED;
}
if (function_exists('set_time_limit')) {
@set_time_limit(300);
} }
$wpdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); $wpdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
@ -96,14 +101,17 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
return sprintf(COULDNT_SELECT_DB, mysql_error($wpdb)); return sprintf(COULDNT_SELECT_DB, mysql_error($wpdb));
} }
// This will hold the s9y <-> WP ID associations.
$assoc = array();
/* Users */ /* Users */
// Fields: ID, user_login, user_pass, user_email, user_level // Fields: ID, user_login, user_pass, user_email, user_level
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}users;", $wpdb); $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}users;", $wpdb);
if (!$res) { if (!$res) {
return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($wpdb)); printf(COULDNT_SELECT_USER_INFO, mysql_error($wpdb));
} } else {
if ($debug) echo "Importing users...<br />\n";
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ ) { for ($x=0, $c = mysql_num_rows($res) ; $x < $c ; $x++) {
$users[$x] = mysql_fetch_assoc($res); $users[$x] = mysql_fetch_assoc($res);
$data = array('right_publish' => (!isset($users[$x]['user_level']) || $users[$x]['user_level'] >= 1) ? 1 : 0, $data = array('right_publish' => (!isset($users[$x]['user_level']) || $users[$x]['user_level'] >= 1) ? 1 : 0,
@ -125,31 +133,45 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
serendipity_db_insert('authors', $this->strtrRecursive($data)); serendipity_db_insert('authors', $this->strtrRecursive($data));
$users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
// Set association.
$assoc['users'][$users[$x]['ID']] = $users[$x]['authorid'];
}
if ($debug) echo "Imported users.<br />\n";
// Clean memory
unset($users);
} }
/* Categories */ /* Categories */
$res = @$this->nativeQuery("SELECT cat_ID, cat_name, category_description, category_parent FROM {$this->data['prefix']}categories ORDER BY category_parent, cat_ID;", $wpdb); $res = @$this->nativeQuery("SELECT cat_ID, cat_name, category_description, category_parent
FROM {$this->data['prefix']}categories
ORDER BY category_parent, cat_ID;", $wpdb);
if (!$res) { if (!$res) {
return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($wpdb)); printf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($wpdb));
} } else {
if ($debug) echo "Importing categories...<br />\n";
// Get all the info we need // Get all the info we need
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ ) for ($x=0 ; $x<mysql_num_rows($res) ; $x++) {
$categories[] = mysql_fetch_assoc($res); $categories[] = mysql_fetch_assoc($res);
}
// Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
for ( $x=0 ; $x<sizeof($categories) ; $x++ ) { for ($x=0, $c = sizeof($categories) ; $x < $c ; $x++) {
$cat = array('category_name' => $categories[$x]['cat_name'], $cat = array('category_name' => $categories[$x]['cat_name'],
'category_description' => $categories[$x]['category_description'], 'category_description' => $categories[$x]['category_description'],
'parentid' => 0, // <--- 'parentid' => 0,
'category_left' => 0, 'category_left' => 0,
'category_right' => 0); 'category_right' => 0);
serendipity_db_insert('category', $this->strtrRecursive($cat)); serendipity_db_insert('category', $this->strtrRecursive($cat));
$categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
// Set association.
$assoc['categories'][$categories[$x]['cat_ID']] = $categories[$x]['categoryid'];
} }
// There has to be a more efficient way of doing this...
foreach ($categories as $cat) { foreach ($categories as $cat) {
if ($cat['category_parent'] != 0) { if ($cat['category_parent'] != 0) {
// Find the parent // Find the parent
@ -162,12 +184,22 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
} }
if ($par_id != 0) { if ($par_id != 0) {
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category SET parentid={$par_id} WHERE categoryid={$cat['categoryid']};"); serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category
} // else { echo "D'oh! " . random_string_of_profanity(); } SET parentid={$par_id}
WHERE categoryid={$cat['categoryid']};");
}
} }
} }
// Clean memory
unset($categories);
if ($debug) echo "Imported categories.<br />\n";
if ($debug) echo "Rebuilding category tree...<br />\n";
serendipity_rebuildCategoryTree(); serendipity_rebuildCategoryTree();
if ($debug) echo "Rebuilt category tree.<br />\n";
}
/* Entries */ /* Entries */
if (serendipity_db_bool($this->data['import_all'])) { if (serendipity_db_bool($this->data['import_all'])) {
@ -175,11 +207,12 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
} else { } else {
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY post_date;", $wpdb); $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY post_date;", $wpdb);
} }
if ( !$res ) {
return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
}
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ ) { if (!$res) {
printf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
} else {
if ($debug) echo "Importing entries...<br />\n";
for ($x=0, $c = mysql_num_rows($res) ; $x < $c ; $x++ ) {
$entries[$x] = mysql_fetch_assoc($res); $entries[$x] = mysql_fetch_assoc($res);
$content = explode('<!--more-->', $entries[$x]['post_content'], 2); $content = explode('<!--more-->', $entries[$x]['post_content'], 2);
@ -191,52 +224,46 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
'allow_comments' => ($entries[$x]['comment_status'] == 'open' ) ? 'true' : 'false', 'allow_comments' => ($entries[$x]['comment_status'] == 'open' ) ? 'true' : 'false',
'timestamp' => strtotime($entries[$x]['post_date']), 'timestamp' => strtotime($entries[$x]['post_date']),
'body' => $this->strtr($body), 'body' => $this->strtr($body),
'extended' => $this->strtr($extended)); 'extended' => $this->strtr($extended),
'authorid' => $assoc['users'][$entries[$x]['post_author']]);
foreach ( $users as $user ) {
if ( $user['ID'] == $entries[$x]['post_author'] ) {
$entry['authorid'] = $user['authorid'];
break;
}
}
if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
printf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
echo "ID: {$entries[$x]['ID']} - {$entry['title']}<br />\n";
return $entries[$x]['entryid']; return $entries[$x]['entryid'];
} }
$assoc['entries'][$entries[$x]['ID']] = $entries[$x]['entryid'];
}
if ($debug) echo "Imported entries...<br />\n";
// Clean memory
unset($entries);
} }
/* Entry/category */ /* Entry/category */
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}post2cat;", $wpdb); $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}post2cat;", $wpdb);
if (!$res) { if (!$res) {
return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb)); printf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
} } else {
if ($debug) echo "Importing category associations...<br />\n";
while ($a = mysql_fetch_assoc($res)) { while ($a = mysql_fetch_assoc($res)) {
foreach ( $categories as $category ) { $data = array('entryid' => $assoc['entries'][$a['post_id']],
if ( $category['cat_ID'] == $a['category_id'] ) { 'categoryid' => $assoc['categories'][$a['category_id']]);
foreach ( $entries as $entry ) {
if ( $a['post_id'] == $entry['ID'] ) {
$data = array('entryid' => $entry['entryid'],
'categoryid' => $category['categoryid']);
serendipity_db_insert('entrycat', $this->strtrRecursive($data)); serendipity_db_insert('entrycat', $this->strtrRecursive($data));
break;
}
}
break;
}
} }
if ($debug) echo "Imported category associations.<br />\n";
} }
/* Comments */ /* Comments */
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $wpdb); $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $wpdb);
if (!$res) { if (!$res) {
return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($wpdb)); printf(COULDNT_SELECT_COMMENT_INFO, mysql_error($wpdb));
} } else {
$serendipity['allowSubscriptions'] = false;
if ($debug) echo "Importing comments...<br />\n";
while ($a = mysql_fetch_assoc($res)) { while ($a = mysql_fetch_assoc($res)) {
foreach ( $entries as $entry ) { $comment = array('entry_id ' => $assoc['entries'][$a['comment_post_ID']],
if ( $entry['ID'] == $a['comment_post_ID'] ) {
$comment = array('entry_id ' => $entry['entryid'],
'parent_id' => 0, 'parent_id' => 0,
'timestamp' => strtotime($a['comment_date']), 'timestamp' => strtotime($a['comment_date']),
'author' => $a['comment_author'], 'author' => $a['comment_author'],
@ -251,10 +278,10 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
serendipity_db_insert('comments', $this->strtrRecursive($comment)); serendipity_db_insert('comments', $this->strtrRecursive($comment));
if ($comment['status'] == 'approved') { if ($comment['status'] == 'approved') {
$cid = serendipity_db_insert_id('comments', 'id'); $cid = serendipity_db_insert_id('comments', 'id');
serendipity_approveComment($cid, $entry['entryid'], true); serendipity_approveComment($cid, $comment['entry_id'], true);
}
} }
} }
if ($debug) echo "Imported comments.<br />\n";
} }
$serendipity['noautodiscovery'] = $noautodiscovery; $serendipity['noautodiscovery'] = $noautodiscovery;
@ -267,4 +294,3 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
return 'Serendipity_Import_WordPress'; return 'Serendipity_Import_WordPress';
/* vim: set sts=4 ts=4 expandtab : */ /* vim: set sts=4 ts=4 expandtab : */
?>

View File

@ -183,7 +183,7 @@ if (function_exists('set_include_path')) {
$use_include = @ini_set('include_path', $new_include); $use_include = @ini_set('include_path', $new_include);
} }
if ($use_include) { if ($use_include !== $false && $use_include == $new_include) {
@define('S9Y_PEAR', true); @define('S9Y_PEAR', true);
@define('S9Y_PEAR_PATH', ''); @define('S9Y_PEAR_PATH', '');
} else { } else {