From c74bcaf121c3d240f7f2b7afa13a75ce34bbcf06 Mon Sep 17 00:00:00 2001 From: shish Date: Thu, 22 May 2008 20:41:46 +0000 Subject: [PATCH] database content download button git-svn-id: file:///home/shish/svn/shimmie2/trunk@877 7f39781d-f577-437e-ae19-be835c7a54ca --- ext/admin/main.php | 36 ++++++++++++++++++++++++++++++++++-- ext/admin/theme.php | 1 + 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/ext/admin/main.php b/ext/admin/main.php index ec360bef..f322d40b 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -43,21 +43,30 @@ class AdminPage extends Extension { if(is_a($event, 'PageRequestEvent') && ($event->page_name == "admin_utils")) { if($event->user->is_admin()) { set_time_limit(0); + $redirect = false; switch($_POST['action']) { case 'lowercase all tags': $this->lowercase_all_tags(); + $redirect = true; break; case 'recount tag use': $this->recount_tag_use(); + $redirect = true; break; case 'purge unused tags': $this->purge_unused_tags(); + $redirect = true; + break; + case 'database dump': + $this->dbdump($event->page); break; } - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("admin")); + if($redirect) { + $event->page->set_mode("redirect"); + $event->page->set_redirect(make_link("admin")); + } } } @@ -96,6 +105,29 @@ class AdminPage extends Extension { $database->Execute("DELETE FROM tags WHERE count=0"); } + private function dbdump($page) { + include "config.php"; + + $matches = array(); + preg_match("#(\w+)://(\w+):(\w+)@([\w\.\-]+)/([\w_]+)(\?.*)?#", $database_dsn, $matches); + $software = $matches[1]; + $username = $matches[2]; + $password = $matches[3]; + $hostname = $matches[4]; + $database = $matches[5]; + + switch($software) { + case 'mysql': + $cmd = "mysqldump -h$hostname -u$username -p$password $database"; + break; + } + + $page->set_mode("data"); + $page->set_type("application/x-unknown"); + $page->set_filename('shimmie-'.date('Ymd').'.sql'); + $page->set_data(shell_exec($cmd)); + } + private function check_for_orphanned_images() { $orphans = array(); foreach(glob("images/*") as $dir) { diff --git a/ext/admin/theme.php b/ext/admin/theme.php index 6178f74b..950cf4b5 100644 --- a/ext/admin/theme.php +++ b/ext/admin/theme.php @@ -39,6 +39,7 @@ class AdminPageTheme extends Themelet { +