[bulk] have BulkActionEvent carry its own params

This commit is contained in:
Shish 2024-02-10 00:05:33 +00:00
parent 6d1bf8eede
commit 31dc7f1ee0
5 changed files with 22 additions and 22 deletions

View file

@ -46,13 +46,19 @@ class BulkActionEvent extends Event
{
public string $action;
public \Generator $items;
/** @var array<string, mixed> */
public array $params;
public bool $redirect = true;
public function __construct(string $action, \Generator $items)
/**
* @param array<string, mixed> $params
*/
public function __construct(string $action, \Generator $items, array $params)
{
parent::__construct();
$this->action = $action;
$this->items = $items;
$this->params = $params;
}
}
@ -116,7 +122,7 @@ class BulkActions extends Extension
$query = $input->getArgument('query');
$items = $this->yield_search_results($query);
log_info("bulk_actions", "Performing $action on $query");
send_event(new BulkActionEvent($action, $items));
send_event(new BulkActionEvent($action, $items, []));
return Command::SUCCESS;
});
}
@ -133,13 +139,13 @@ class BulkActions extends Extension
}
break;
case "bulk_tag":
if (!isset($_POST['bulk_tags'])) {
if (!isset($event->params['bulk_tags'])) {
return;
}
if ($user->can(Permissions::BULK_EDIT_IMAGE_TAG)) {
$tags = $_POST['bulk_tags'];
$tags = $event->params['bulk_tags'];
$replace = false;
if (isset($_POST['bulk_tags_replace']) && $_POST['bulk_tags_replace'] == "true") {
if (isset($event->params['bulk_tags_replace']) && $event->params['bulk_tags_replace'] == "true") {
$replace = true;
}
@ -148,11 +154,11 @@ class BulkActions extends Extension
}
break;
case "bulk_source":
if (!isset($_POST['bulk_source'])) {
if (!isset($event->params['bulk_source'])) {
return;
}
if ($user->can(Permissions::BULK_EDIT_IMAGE_SOURCE)) {
$source = $_POST['bulk_source'];
$source = $event->params['bulk_source'];
$i = $this->set_source($event->items, $source);
$page->flash("Set source for $i items");
}
@ -186,7 +192,7 @@ class BulkActions extends Extension
}
shm_set_timeout(null);
$bae = send_event(new BulkActionEvent($action, $items));
$bae = send_event(new BulkActionEvent($action, $items, $event->POST));
if ($bae->redirect) {
$page->set_mode(PageMode::REDIRECT);

View file

@ -613,10 +613,7 @@ class Pools extends Extension
switch ($event->action) {
case "bulk_pool_add_existing":
if (!isset($_POST['bulk_pool_select'])) {
return;
}
$pool_id = intval($_POST['bulk_pool_select']);
$pool_id = intval($event->params['bulk_pool_select']);
$pool = $this->get_single_pool($pool_id);
if ($this->have_permission($user, $pool)) {
@ -626,10 +623,7 @@ class Pools extends Extension
}
break;
case "bulk_pool_add_new":
if (!isset($_POST['bulk_pool_new'])) {
return;
}
$new_pool_title = $_POST['bulk_pool_new'];
$new_pool_title = $event->params['bulk_pool_new'];
$pce = send_event(new PoolCreationEvent($new_pool_title));
send_event(new PoolAddPostsEvent($pce->new_id, iterator_map_to_array("Shimmie2\_image_to_id", $event->items)));
break;

View file

@ -354,11 +354,11 @@ class Ratings extends Extension
switch ($event->action) {
case "bulk_rate":
if (!isset($_POST['rating'])) {
if (!isset($event->params['rating'])) {
return;
}
if ($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) {
$rating = $_POST['rating'];
$rating = $event->params['rating'];
$total = 0;
foreach ($event->items as $image) {
send_event(new RatingSetEvent($image, $rating));

View file

@ -285,11 +285,11 @@ class TranscodeImage extends Extension
switch ($event->action) {
case self::ACTION_BULK_TRANSCODE:
if (!isset($_POST['transcode_mime'])) {
if (!isset($event->params['transcode_mime'])) {
return;
}
if ($user->can(Permissions::EDIT_FILES)) {
$mime = $_POST['transcode_mime'];
$mime = $event->params['transcode_mime'];
$total = 0;
$size_difference = 0;
foreach ($event->items as $image) {

View file

@ -147,11 +147,11 @@ class TranscodeVideo extends Extension
switch ($event->action) {
case self::ACTION_BULK_TRANSCODE:
if (!isset($_POST['transcode_format'])) {
if (!isset($event->params['transcode_format'])) {
return;
}
if ($user->can(Permissions::EDIT_FILES)) {
$format = $_POST['transcode_format'];
$format = $event->params['transcode_format'];
$total = 0;
foreach ($event->items as $image) {
try {