[admin] have AdminActionEvent carry its own params

This commit is contained in:
Shish 2024-02-10 00:00:49 +00:00
parent f95e59cbae
commit 6d1bf8eede
7 changed files with 27 additions and 21 deletions

View file

@ -26,11 +26,17 @@ class AdminActionEvent extends Event
{ {
public string $action; public string $action;
public bool $redirect = true; public bool $redirect = true;
/** @var array<string, mixed> */
public array $params;
public function __construct(string $action) /**
* @param array<string, mixed> $params
*/
public function __construct(string $action, array $params)
{ {
parent::__construct(); parent::__construct();
$this->action = $action; $this->action = $action;
$this->params = $params;
} }
} }
@ -51,7 +57,7 @@ class AdminPage extends Extension
send_event(new AdminBuildingEvent($page)); send_event(new AdminBuildingEvent($page));
} else { } else {
$action = $event->get_arg(0); $action = $event->get_arg(0);
$aae = new AdminActionEvent($action); $aae = new AdminActionEvent($action, $_POST);
if ($user->check_auth_token()) { if ($user->check_auth_token()) {
log_info("admin", "Util: $action"); log_info("admin", "Util: $action");

View file

@ -88,7 +88,7 @@ class Approval extends Extension
$action = $event->action; $action = $event->action;
$event->redirect = true; $event->redirect = true;
if ($action === "approval") { if ($action === "approval") {
$approval_action = $_POST["approval_action"]; $approval_action = $event->params["approval_action"];
switch ($approval_action) { switch ($approval_action) {
case "approve_all": case "approve_all":
$database->set_timeout(null); // These updates can take a little bit $database->set_timeout(null); // These updates can take a little bit

View file

@ -113,8 +113,8 @@ class CronUploader extends Extension
break; break;
case "cron_uploader_restage": case "cron_uploader_restage":
$event->redirect = true; $event->redirect = true;
if (array_key_exists("failed_dir", $_POST) && !empty($_POST["failed_dir"])) { if (array_key_exists("failed_dir", $event->params) && !empty($event->params["failed_dir"])) {
$this->restage_folder($_POST["failed_dir"]); $this->restage_folder($event->params["failed_dir"]);
} }
break; break;
} }

View file

@ -322,14 +322,14 @@ class Ratings extends Extension
switch ($action) { switch ($action) {
case "update_ratings": case "update_ratings":
$event->redirect = true; $event->redirect = true;
if (!array_key_exists("rating_old", $_POST) || empty($_POST["rating_old"])) { if (!array_key_exists("rating_old", $event->params) || empty($event->params["rating_old"])) {
return; return;
} }
if (!array_key_exists("rating_new", $_POST) || empty($_POST["rating_new"])) { if (!array_key_exists("rating_new", $event->params) || empty($event->params["rating_new"])) {
return; return;
} }
$old = $_POST["rating_old"]; $old = $event->params["rating_old"];
$new = $_POST["rating_new"]; $new = $event->params["rating_new"];
if ($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) { if ($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) {
$database->execute("UPDATE images SET rating = :new WHERE rating = :old", ["new" => $new, "old" => $old ]); $database->execute("UPDATE images SET rating = :new WHERE rating = :old", ["new" => $new, "old" => $old ]);

View file

@ -103,17 +103,17 @@ class RegenThumb extends Extension
case "regen_thumbs": case "regen_thumbs":
$event->redirect = true; $event->redirect = true;
$force = false; $force = false;
if (isset($_POST["regen_thumb_force"]) && $_POST["regen_thumb_force"] == "true") { if (isset($event->params["regen_thumb_force"]) && $event->params["regen_thumb_force"] == "true") {
$force = true; $force = true;
} }
$limit = 1000; $limit = 1000;
if (isset($_POST["regen_thumb_limit"]) && is_numeric($_POST["regen_thumb_limit"])) { if (isset($event->params["regen_thumb_limit"]) && is_numeric($event->params["regen_thumb_limit"])) {
$limit = intval($_POST["regen_thumb_limit"]); $limit = intval($event->params["regen_thumb_limit"]);
} }
$mime = ""; $mime = "";
if (isset($_POST["regen_thumb_mime"])) { if (isset($event->params["regen_thumb_mime"])) {
$mime = $_POST["regen_thumb_mime"]; $mime = $event->params["regen_thumb_mime"];
} }
$images = Search::find_images(tags: ["mime=" . $mime]); $images = Search::find_images(tags: ["mime=" . $mime]);
@ -138,8 +138,8 @@ class RegenThumb extends Extension
case "delete_thumbs": case "delete_thumbs":
$event->redirect = true; $event->redirect = true;
if (isset($_POST["delete_thumb_mime"]) && $_POST["delete_thumb_mime"] != "") { if (isset($event->params["delete_thumb_mime"]) && $event->params["delete_thumb_mime"] != "") {
$images = Search::find_images(tags: ["mime=" . $_POST["delete_thumb_mime"]]); $images = Search::find_images(tags: ["mime=" . $event->params["delete_thumb_mime"]]);
$i = 0; $i = 0;
foreach ($images as $image) { foreach ($images as $image) {
@ -149,7 +149,7 @@ class RegenThumb extends Extension
$i++; $i++;
} }
} }
$page->flash("Deleted $i thumbnails for ".$_POST["delete_thumb_mime"]." images"); $page->flash("Deleted $i thumbnails for ".$event->params["delete_thumb_mime"]." images");
} else { } else {
$dir = "data/thumbs/"; $dir = "data/thumbs/";
deltree($dir); deltree($dir);

View file

@ -59,7 +59,7 @@ class S3 extends Extension
if($event->action == "s3_process") { if($event->action == "s3_process") {
foreach($database->get_all( foreach($database->get_all(
"SELECT * FROM s3_sync_queue ORDER BY time ASC LIMIT :count", "SELECT * FROM s3_sync_queue ORDER BY time ASC LIMIT :count",
["count" => isset($_POST['count']) ? int_escape($_POST["count"]) : 10] ["count" => isset($event->params['count']) ? int_escape($event->params["count"]) : 10]
) as $row) { ) as $row) {
if($row['action'] == "S") { if($row['action'] == "S") {
$image = Image::by_hash($row['hash']); $image = Image::by_hash($row['hash']);

View file

@ -18,7 +18,7 @@ class TagToolsTest extends ShimmiePHPUnitTestCase
$this->assertEquals("Post $image_id_1: TeStCase$ts", $page->title); $this->assertEquals("Post $image_id_1: TeStCase$ts", $page->title);
// Fix // Fix
send_event(new AdminActionEvent('lowercase_all_tags')); send_event(new AdminActionEvent('lowercase_all_tags', []));
// Validate fix // Validate fix
$this->get_page("post/view/$image_id_1"); $this->get_page("post/view/$image_id_1");
@ -26,7 +26,7 @@ class TagToolsTest extends ShimmiePHPUnitTestCase
// Change // Change
$_POST["tag"] = "TestCase$ts"; $_POST["tag"] = "TestCase$ts";
send_event(new AdminActionEvent('set_tag_case')); send_event(new AdminActionEvent('set_tag_case', []));
// Validate change // Validate change
$this->get_page("post/view/$image_id_1"); $this->get_page("post/view/$image_id_1");
@ -47,7 +47,7 @@ class TagToolsTest extends ShimmiePHPUnitTestCase
); );
// Fix // Fix
send_event(new AdminActionEvent('recount_tag_use')); send_event(new AdminActionEvent('recount_tag_use', []));
// Validate fix // Validate fix
$this->assertEquals( $this->assertEquals(