forked from Cavemanon/cavepaintings
Merge pull request #107 from DakuTree/master
Reset Image ids & Download all images
This commit is contained in:
@@ -78,6 +78,13 @@ class AdminPage extends SimpleExtension {
|
||||
case 'database dump':
|
||||
$this->dbdump($page);
|
||||
break;
|
||||
case 'reset image ids':
|
||||
$this->reset_imageids();
|
||||
$redirect = true;
|
||||
break;
|
||||
case 'image dump':
|
||||
$this->imgdump($page);
|
||||
break;
|
||||
}
|
||||
|
||||
if($redirect) {
|
||||
@@ -175,5 +182,67 @@ class AdminPage extends SimpleExtension {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private function reset_imageids() {
|
||||
global $database;
|
||||
//This might be a bit laggy on boards with lots of images (?)
|
||||
//Seems to work fine with 1.2k~ images though.
|
||||
$i = 0;
|
||||
$image = $database->get_all("SELECT * FROM images ORDER BY images.id ASC");
|
||||
/*$score_log = $database->get_all("SELECT message FROM score_log");*/
|
||||
foreach($image as $img){
|
||||
$xid = $img[0];
|
||||
$i = $i + 1;
|
||||
$table = array( //Might be missing some tables?
|
||||
"image_tags", "tag_histories", "image_reports", "comments", "user_favorites", "tag_histories",
|
||||
"numeric_score_votes", "pool_images", "slext_progress_cache", "notes");
|
||||
|
||||
$sql =
|
||||
"SET FOREIGN_KEY_CHECKS=0;
|
||||
UPDATE images
|
||||
SET id=".$i.
|
||||
" WHERE id=".$xid.";"; //id for images
|
||||
|
||||
foreach($table as $tbl){
|
||||
$sql .= "
|
||||
UPDATE ".$tbl."
|
||||
SET image_id=".$i."
|
||||
WHERE image_id=".$xid.";";
|
||||
}
|
||||
|
||||
/*foreach($score_log as $sl){
|
||||
//This seems like a bad idea.
|
||||
//TODO: Might be better for log_info to have an $id option (which would then affix the id to the table?)
|
||||
preg_replace(".Image \\#[0-9]+.", "Image #".$i, $sl);
|
||||
}*/
|
||||
$sql .= " SET FOREIGN_KEY_CHECKS=1;";
|
||||
$database->execute($sql);
|
||||
}
|
||||
$count = (count($image)) + 1;
|
||||
$database->execute("ALTER TABLE images AUTO_INCREMENT=".$count);
|
||||
}
|
||||
|
||||
private function imgdump($page) {
|
||||
global $database;
|
||||
$zip = new ZipArchive;
|
||||
$images = $database->get_all("SELECT * FROM images");
|
||||
$filename = 'imgdump-'.date('Ymd').'.zip';
|
||||
|
||||
if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE){
|
||||
foreach($images as $img){
|
||||
$hash = $img["hash"];
|
||||
preg_match("^[A-Za-z0-9]{2}^", $hash, $matches);
|
||||
$img_loc = "images/".$matches[0]."/".$hash;
|
||||
if(file_exists($img_loc)){
|
||||
$zip->addFile($img_loc, $hash.".".$img["ext"]);
|
||||
}
|
||||
|
||||
}
|
||||
$zip->close();
|
||||
}
|
||||
$page->set_mode("redirect");
|
||||
$page->set_redirect(make_link($filename)); //Fairly sure there is better way to do this..
|
||||
//TODO: Delete file after downloaded?
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -19,13 +19,26 @@ class AdminPageTheme extends Themelet {
|
||||
public function display_form(Page $page) {
|
||||
global $user;
|
||||
|
||||
$html = "
|
||||
".make_form(make_link("admin_utils"))."
|
||||
<select name='action'>
|
||||
$html = '
|
||||
<script type="text/javascript">
|
||||
function imgidconfirm(){
|
||||
if(document.getElementById("misc").selectedIndex == 4){
|
||||
if(confirm("This function WILL break any bookmarks & links.\n The event log will also not be updated with new ids. \n Are you sure you wish to continue?")){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
'.make_form(make_link("admin_utils"),"post", false, false, "return imgidconfirm()")."
|
||||
<select name='action' id='misc'>
|
||||
<option value='lowercase all tags'>All tags to lowercase</option>
|
||||
<option value='recount tag use'>Recount tag use</option>
|
||||
<option value='purge unused tags'>Purge unused tags</option>
|
||||
<option value='database dump'>Download database contents</option>
|
||||
<option value='reset image ids'>Reset image ids</option>
|
||||
<option value='image dump'>Download all images</option>
|
||||
<!--<option value='convert to innodb'>Convert database to InnoDB (MySQL only)</option>-->
|
||||
</select>
|
||||
<input type='submit' value='Go'>
|
||||
|
Reference in New Issue
Block a user