admin wibbles
This commit is contained in:
parent
25bab5d672
commit
df4e4050a0
@ -35,6 +35,14 @@ class AdminBuildingEvent extends Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AdminActionEvent extends Event {
|
||||||
|
var $action;
|
||||||
|
var $redirect = true;
|
||||||
|
public function __construct(/*string*/ $action) {
|
||||||
|
$this->action = $action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class AdminPage extends Extension {
|
class AdminPage extends Extension {
|
||||||
public function onPageRequest(PageRequestEvent $event) {
|
public function onPageRequest(PageRequestEvent $event) {
|
||||||
global $page, $user;
|
global $page, $user;
|
||||||
@ -44,52 +52,23 @@ class AdminPage extends Extension {
|
|||||||
$this->theme->display_permission_denied();
|
$this->theme->display_permission_denied();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
send_event(new AdminBuildingEvent($page));
|
if($event->count_args() == 0) {
|
||||||
}
|
send_event(new AdminBuildingEvent($page));
|
||||||
}
|
|
||||||
|
|
||||||
if($event->page_matches("admin_utils")) {
|
|
||||||
if($user->is_admin() && $user->check_auth_token()) {
|
|
||||||
log_info("admin", "Util: {$_POST['action']}");
|
|
||||||
set_time_limit(0);
|
|
||||||
$redirect = false;
|
|
||||||
|
|
||||||
switch($_POST['action']) {
|
|
||||||
case 'delete by query':
|
|
||||||
$this->delete_by_query($_POST['query']);
|
|
||||||
$redirect = true;
|
|
||||||
break;
|
|
||||||
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 'convert to innodb':
|
|
||||||
$this->convert_to_innodb();
|
|
||||||
$redirect = true;
|
|
||||||
break;
|
|
||||||
case 'database dump':
|
|
||||||
$this->dbdump($page);
|
|
||||||
break;
|
|
||||||
case 'reset image ids':
|
|
||||||
$this->reset_imageids();
|
|
||||||
$redirect = true;
|
|
||||||
break;
|
|
||||||
case 'image dump':
|
|
||||||
$this->imgdump($page);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$action = $event->get_arg(0);
|
||||||
|
$aae = new AdminActionEvent($action);
|
||||||
|
|
||||||
if($redirect) {
|
if($user->check_auth_token()) {
|
||||||
$page->set_mode("redirect");
|
log_info("admin", "Util: $action");
|
||||||
$page->set_redirect(make_link("admin"));
|
set_time_limit(0);
|
||||||
|
send_event($aae);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($aae->redirect) {
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("admin"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,17 +87,30 @@ class AdminPage extends Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function delete_by_query(/*array(string)*/ $query) {
|
public function onAdminAction(AdminActionEvent $event) {
|
||||||
|
$action = $event->action;
|
||||||
|
if(function_exists($this, $action)) {
|
||||||
|
$event->redirect = $this->$action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function delete_by_query() {
|
||||||
global $page, $user;
|
global $page, $user;
|
||||||
|
$query = $_POST['query'];
|
||||||
assert(strlen($query) > 1);
|
assert(strlen($query) > 1);
|
||||||
|
|
||||||
foreach(Image::find_images(0, 1000000, Tag::explode($query)) as $image) {
|
foreach(Image::find_images(0, 1000000, Tag::explode($query)) as $image) {
|
||||||
send_event(new ImageDeletionEvent($image));
|
send_event(new ImageDeletionEvent($image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function lowercase_all_tags() {
|
private function lowercase_all_tags() {
|
||||||
global $database;
|
global $database;
|
||||||
$database->execute("UPDATE tags SET tag=lower(tag)");
|
$database->execute("UPDATE tags SET tag=lower(tag)");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function recount_tag_use() {
|
private function recount_tag_use() {
|
||||||
@ -128,16 +120,21 @@ class AdminPage extends Extension {
|
|||||||
SET count = COALESCE(
|
SET count = COALESCE(
|
||||||
(SELECT COUNT(image_id) FROM image_tags WHERE tag_id=tags.id GROUP BY tag_id),
|
(SELECT COUNT(image_id) FROM image_tags WHERE tag_id=tags.id GROUP BY tag_id),
|
||||||
0
|
0
|
||||||
)");
|
)
|
||||||
|
");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function purge_unused_tags() {
|
private function purge_unused_tags() {
|
||||||
global $database;
|
global $database;
|
||||||
$this->recount_tag_use();
|
$this->recount_tag_use();
|
||||||
$database->Execute("DELETE FROM tags WHERE count=0");
|
$database->Execute("DELETE FROM tags WHERE count=0");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function dbdump(Page $page) {
|
private function dump_database() {
|
||||||
|
global $page;
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
preg_match("#^(?P<proto>\w+)\:(?:user=(?P<user>\w+)(?:;|$)|password=(?P<password>\w+)(?:;|$)|host=(?P<host>[\w\.\-]+)(?:;|$)|dbname=(?P<dbname>[\w_]+)(?:;|$))+#", DATABASE_DSN, $matches);
|
preg_match("#^(?P<proto>\w+)\:(?:user=(?P<user>\w+)(?:;|$)|password=(?P<password>\w+)(?:;|$)|host=(?P<host>[\w\.\-]+)(?:;|$)|dbname=(?P<dbname>[\w_]+)(?:;|$))+#", DATABASE_DSN, $matches);
|
||||||
$software = $matches['proto'];
|
$software = $matches['proto'];
|
||||||
@ -157,6 +154,8 @@ class AdminPage extends Extension {
|
|||||||
$page->set_type("application/x-unknown");
|
$page->set_type("application/x-unknown");
|
||||||
$page->set_filename('shimmie-'.date('Ymd').'.sql');
|
$page->set_filename('shimmie-'.date('Ymd').'.sql');
|
||||||
$page->set_data(shell_exec($cmd));
|
$page->set_data(shell_exec($cmd));
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function check_for_orphanned_images() {
|
private function check_for_orphanned_images() {
|
||||||
@ -169,23 +168,29 @@ class AdminPage extends Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
private function convert_to_innodb() {
|
private function convert_to_innodb() {
|
||||||
global $database;
|
global $database;
|
||||||
if($database->engine->name == "mysql") {
|
|
||||||
$tables = $database->db->MetaTables();
|
if($database->engine->name != "mysql") return;
|
||||||
foreach($tables as $table) {
|
|
||||||
log_info("upgrade", "converting $table to innodb");
|
$tables = $database->db->MetaTables();
|
||||||
$database->execute("ALTER TABLE $table TYPE=INNODB");
|
foreach($tables as $table) {
|
||||||
}
|
log_info("upgrade", "converting $table to innodb");
|
||||||
|
$database->execute("ALTER TABLE $table TYPE=INNODB");
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private function reset_imageids() {
|
private function reset_image_ids() {
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
|
if($database->engine->name != "mysql") return;
|
||||||
|
|
||||||
//This might be a bit laggy on boards with lots of images (?)
|
//This might be a bit laggy on boards with lots of images (?)
|
||||||
//Seems to work fine with 1.2k~ images though.
|
//Seems to work fine with 1.2k~ images though.
|
||||||
$i = 0;
|
$i = 0;
|
||||||
@ -221,15 +226,17 @@ class AdminPage extends Extension {
|
|||||||
}
|
}
|
||||||
$count = (count($image)) + 1;
|
$count = (count($image)) + 1;
|
||||||
$database->execute("ALTER TABLE images AUTO_INCREMENT=".$count);
|
$database->execute("ALTER TABLE images AUTO_INCREMENT=".$count);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function imgdump(Page $page) {
|
private function download_all_images() {
|
||||||
global $database;
|
global $database, $page;
|
||||||
|
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
$images = $database->get_all("SELECT * FROM images");
|
$images = $database->get_all("SELECT * FROM images");
|
||||||
$filename = 'imgdump-'.date('Ymd').'.zip';
|
$filename = 'imgdump-'.date('Ymd').'.zip';
|
||||||
|
|
||||||
if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE){
|
if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE) === TRUE){
|
||||||
foreach($images as $img){
|
foreach($images as $img){
|
||||||
$hash = $img["hash"];
|
$hash = $img["hash"];
|
||||||
preg_match("^[A-Za-z0-9]{2}^", $hash, $matches);
|
preg_match("^[A-Za-z0-9]{2}^", $hash, $matches);
|
||||||
@ -241,9 +248,11 @@ class AdminPage extends Extension {
|
|||||||
}
|
}
|
||||||
$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)); //Fairly sure there is better way to do this..
|
||||||
//TODO: Delete file after downloaded?
|
//TODO: Delete file after downloaded?
|
||||||
|
return false; // we do want a redirect, but a manual one
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user