reset_image_ids should properly change id for all possible tables
This commit is contained in:
parent
daad8d00d5
commit
5df6c09da6
@ -218,41 +218,38 @@ class AdminPage extends Extension {
|
|||||||
private function reset_image_ids() {
|
private function reset_image_ids() {
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
//This might be a bit laggy on boards with lots of images (?)
|
//TODO: Make work with PostgreSQL + SQLite
|
||||||
//Seems to work fine with 1.2k~ images though.
|
//TODO: Update score_log (Having an optional ID column for score_log would be nice..)
|
||||||
$i = 0;
|
preg_match("#^(?P<proto>\w+)\:(?:user=(?P<user>\w+)(?:;|$)|password=(?P<password>\w*)(?:;|$)|host=(?P<host>[\w\.\-]+)(?:;|$)|dbname=(?P<dbname>[\w_]+)(?:;|$))+#", DATABASE_DSN, $matches);
|
||||||
$image = $database->get_all("SELECT * FROM images ORDER BY images.id ASC");
|
|
||||||
/*$score_log = $database->get_all("SELECT message FROM score_log");*/
|
if($matches['proto'] == "mysql"){
|
||||||
foreach($image as $img){
|
$tables = $database->get_col("SELECT TABLE_NAME
|
||||||
$xid = $img[0];
|
FROM information_schema.KEY_COLUMN_USAGE
|
||||||
$i = $i + 1;
|
WHERE TABLE_SCHEMA = :db
|
||||||
$table = array( //Might be missing some tables?
|
AND REFERENCED_COLUMN_NAME = 'id'
|
||||||
"image_tags", "tag_histories", "image_reports", "comments", "user_favorites", "tag_histories",
|
AND REFERENCED_TABLE_NAME = 'images'", array("db" => $matches['dbname']));
|
||||||
"numeric_score_votes", "pool_images", "slext_progress_cache", "notes");
|
|
||||||
|
$i = 1;
|
||||||
$sql =
|
$ids = $database->get_col("SELECT id FROM images ORDER BY images.id ASC");
|
||||||
"SET FOREIGN_KEY_CHECKS=0;
|
foreach($ids as $id){
|
||||||
UPDATE images
|
$sql = "SET FOREIGN_KEY_CHECKS=0;
|
||||||
SET id=".$i.
|
UPDATE images SET id={$i} WHERE image_id={$id};";
|
||||||
" WHERE id=".$xid.";"; //id for images
|
|
||||||
|
foreach($tables as $table){
|
||||||
foreach($table as $tbl){
|
$sql .= "UPDATE {$table} SET image_id={$i} WHERE image_id={$id};";
|
||||||
$sql .= "
|
}
|
||||||
UPDATE ".$tbl."
|
|
||||||
SET image_id=".$i."
|
$sql .= " SET FOREIGN_KEY_CHECKS=1;";
|
||||||
WHERE image_id=".$xid.";";
|
$database->execute($sql);
|
||||||
}
|
|
||||||
|
$i++;
|
||||||
/*foreach($score_log as $sl){
|
}
|
||||||
//This seems like a bad idea.
|
$database->execute("ALTER TABLE images AUTO_INCREMENT=".(count($ids) + 1));
|
||||||
//TODO: Might be better for log_info to have an $id option (which would then affix the id to the table?)
|
}elseif($matches['proto'] == "pgsql"){
|
||||||
preg_replace(".Image \\#[0-9]+.", "Image #".$i, $sl);
|
//TODO: Make this work with PostgreSQL
|
||||||
}*/
|
}elseif($matches['proto'] == "sqlite"){
|
||||||
$sql .= " SET FOREIGN_KEY_CHECKS=1;";
|
//TODO: Make this work with SQLite
|
||||||
$database->execute($sql);
|
}
|
||||||
}
|
|
||||||
$count = (count($image)) + 1;
|
|
||||||
$database->execute("ALTER TABLE images AUTO_INCREMENT=".$count);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user