fix download all images not working

This commit is contained in:
Daku 2014-02-18 12:33:10 +00:00
parent 5a4b089a61
commit daad8d00d5
2 changed files with 8 additions and 13 deletions

View File

@ -197,26 +197,21 @@ class AdminPage extends Extension {
private function download_all_images() { private function download_all_images() {
global $database, $page; global $database, $page;
$zip = new ZipArchive; $images = $database->get_all("SELECT hash, ext FROM images");
$images = $database->get_all("SELECT * FROM images");
$filename = data_path('imgdump-'.date('Ymd').'.zip'); $filename = data_path('imgdump-'.date('Ymd').'.zip');
if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE) === TRUE){ $zip = new ZipArchive;
if($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) === TRUE){
foreach($images as $img){ foreach($images as $img){
$hash = $img["hash"]; $img_loc = warehouse_path("images", $img["hash"], FALSE);
preg_match("^[A-Za-z0-9]{2}^", $hash, $matches); $zip->addFile($img_loc, $img["hash"].".".$img["ext"]);
$img_loc = "images/".$matches[0]."/".$hash;
if(file_exists($img_loc)){
$zip->addFile($img_loc, $hash.".".$img["ext"]);
}
} }
$zip->close(); $zip->close();
} }
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link($filename)); //Fairly sure there is better way to do this.. $page->set_redirect(make_link($filename)); //TODO: Delete file after downloaded?
//TODO: Delete file after downloaded?
return false; // we do want a redirect, but a manual one return false; // we do want a redirect, but a manual one
} }

View File

@ -39,7 +39,7 @@ class AdminPageTheme extends Themelet {
$html = ""; $html = "";
$html .= $this->button("All tags to lowercase", "lowercase_all_tags", true); $html .= $this->button("All tags to lowercase", "lowercase_all_tags", true);
$html .= $this->button("Recount tag use", "recount_tag_use", false); $html .= $this->button("Recount tag use", "recount_tag_use", false);
$html .= $this->button("Download all images", "image_dump", false); $html .= $this->button("Download all images", "download_all_images", false);
$html .= $this->button("Download database contents", "database_dump", false); $html .= $this->button("Download database contents", "database_dump", false);
if($database->get_driver_name() == "mysql") if($database->get_driver_name() == "mysql")
$html .= $this->button("Reset image IDs", "reset_image_ids", true); $html .= $this->button("Reset image IDs", "reset_image_ids", true);