slightly more robustness during upgrade, and sanity if it breaks

git-svn-id: file:///home/shish/svn/shimmie2/trunk@7 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-04-23 22:58:44 +00:00
parent f219e199e9
commit 65be47dbb7

View file

@ -278,15 +278,19 @@ function upgrade_process() { // {{{
print "<p>If everything looks OK, <a href='index.php?q=user/login'>continue</a>"; print "<p>If everything looks OK, <a href='index.php?q=user/login'>continue</a>";
} // }}} } // }}}
function move_data($old_dsn, $new_dsn, $old_data) { function move_data($old_dsn, $new_dsn, $old_data) {
print("<br>Upping PHP resource limits...");
set_time_limit(600);
ini_set("memory_limit", "32M");
print("<br>Fetching old data..."); print("<br>Fetching old data...");
$old_db = NewADOConnection($old_dsn); $old_db = NewADOConnection($old_dsn);
$old_db->SetFetchMode(ADODB_FETCH_ASSOC); $old_db->SetFetchMode(ADODB_FETCH_ASSOC);
# tmpfile & serialize? # tmpfile & serialize?
$anon_id = -1; $anon_id = -1;
$users = $old_db->GetAll("SELECT id, name, pass, joindate FROM users"); $users = $old_db->GetAll("SELECT id, name, pass, joindate FROM users ORDER BY id");
$admins = $old_db->GetCol("SELECT owner_id FROM user_configs WHERE name='isadmin' AND value='true'"); $admins = $old_db->GetCol("SELECT owner_id FROM user_configs WHERE name='isadmin' AND value='true'");
$images = $old_db->GetAll("SELECT id, owner_id, owner_ip, filename, hash, ext FROM images"); $images = $old_db->GetAll("SELECT id, owner_id, owner_ip, filename, hash, ext FROM images ORDER BY id");
$comments = $old_db->GetAll("SELECT id, image_id, owner_id, owner_ip, posted, comment FROM comments"); $comments = $old_db->GetAll("SELECT id, image_id, owner_id, owner_ip, posted, comment FROM comments ORDER BY id");
$tags = $old_db->GetAll("SELECT image_id, tag FROM tags"); $tags = $old_db->GetAll("SELECT image_id, tag FROM tags");
$old_db->Close(); $old_db->Close();
@ -325,6 +329,18 @@ function move_data($old_dsn, $new_dsn, $old_data) {
$new_db->Execute(" $new_db->Execute("
INSERT INTO images(id, owner_id, owner_ip, filename, hash, ext, filesize, width, height, source, posted) INSERT INTO images(id, owner_id, owner_ip, filename, hash, ext, filesize, width, height, source, posted)
VALUES (?, ?, ?, ?, ?, ?, 0, 0, 0, NULL, now())", $images); VALUES (?, ?, ?, ?, ?, ?, 0, 0, 0, NULL, now())", $images);
print("<br>Setting orphan images to anonymous...");
$orphans = $new_db->GetCol("
SELECT images.id
FROM images
LEFT JOIN users ON users.id = images.owner_id
WHERE isnull(users.name)");
if($orphans) {
foreach($orphans as $orphan) {
$new_db->Execute("UPDATE images SET owner_id=? WHERE id=?", array($anon_id, $orphan));
}
}
} }
if($comments) { if($comments) {
@ -364,18 +380,6 @@ function move_data($old_dsn, $new_dsn, $old_data) {
$new_db->Execute("UPDATE comments SET owner_id=? WHERE id=?", array($anon_id, $orphan)); $new_db->Execute("UPDATE comments SET owner_id=? WHERE id=?", array($anon_id, $orphan));
} }
} }
print("<br>Setting orphan images to anonymous...");
$orphans = $new_db->GetCol("
SELECT images.id
FROM images
LEFT JOIN users ON users.id = images.owner_id
WHERE isnull(users.name)");
if($orphans) {
foreach($orphans as $orphan) {
$new_db->Execute("UPDATE images SET owner_id=? WHERE id=?", array($anon_id, $orphan));
}
}
} }
if($tags) { if($tags) {