From a352a02b2e4b686a786b46bc0c5e109b1ebc55ea Mon Sep 17 00:00:00 2001 From: myname Date: Sun, 26 Mar 2023 17:01:46 -0500 Subject: [PATCH 1/3] Bulk Actions for setting a chain of parent child relationships in the order of images selected. Does not support setting multiple children to one parent in bulk. --- core/permissions.php | 1 + core/userclass.php | 1 + ext/bulk_parent_child/info.php | 16 +++++++++++ ext/bulk_parent_child/main.php | 51 ++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 ext/bulk_parent_child/info.php create mode 100644 ext/bulk_parent_child/main.php diff --git a/core/permissions.php b/core/permissions.php index 351fa2a9..28142259 100644 --- a/core/permissions.php +++ b/core/permissions.php @@ -109,4 +109,5 @@ abstract class Permissions public const BULK_IMPORT = "bulk_import"; public const BULK_EXPORT = "bulk_export"; public const BULK_DOWNLOAD = "bulk_download"; + public const BULK_PARENT_CHILD = "bulk_parent_child"; } diff --git a/core/userclass.php b/core/userclass.php index a15d1767..a68ebb1b 100644 --- a/core/userclass.php +++ b/core/userclass.php @@ -199,6 +199,7 @@ new UserClass("admin", "base", [ Permissions::BULK_IMPORT =>true, Permissions::BULK_EXPORT =>true, Permissions::BULK_DOWNLOAD => true, + Permissions::BULK_PARENT_CHILD => true, Permissions::SET_PRIVATE_IMAGE => true, Permissions::SET_OTHERS_PRIVATE_IMAGES => true, diff --git a/ext/bulk_parent_child/info.php b/ext/bulk_parent_child/info.php new file mode 100644 index 00000000..f4a6b673 --- /dev/null +++ b/ext/bulk_parent_child/info.php @@ -0,0 +1,16 @@ +""]; + public string $license = self::LICENSE_WTFPL; + public string $description = "Allows bulk setting of parent-child relationships, in order of manual selection"; + public array $dependencies = [BulkActionsInfo::KEY]; +} diff --git a/ext/bulk_parent_child/main.php b/ext/bulk_parent_child/main.php new file mode 100644 index 00000000..9362debd --- /dev/null +++ b/ext/bulk_parent_child/main.php @@ -0,0 +1,51 @@ +can(Permissions::BULK_PARENT_CHILD)) { + $event->add_action(BulkParentChild::PARENT_CHILD_ACTION_NAME, "Set Parent Child"); + } + } + + public function onSetupBuilding(SetupBuildingEvent $event) + { + $sb = $event->panel->create_new_block("Bulk Parent Child"); + $sb->start_table(); + $sb->end_table(); + } + + public function onBulkAction(BulkActionEvent $event) + { + global $user, $page, $config; + if ($user->can(Permissions::BULK_PARENT_CHILD)&& + ($event->action == BulkParentChild::PARENT_CHILD_ACTION_NAME)) { + $prev_id = null; + foreach ($event->items as $image) { + if ($prev_id != null) { + send_event(new ImageRelationshipSetEvent($image->id, $prev_id)); + } + $prev_id = $image->id; + } + } + } +} From 0b5f6c310d1250c590fc0c2d6d6d436c3a0eb1b7 Mon Sep 17 00:00:00 2001 From: myname Date: Mon, 27 Mar 2023 14:26:39 -0500 Subject: [PATCH 2/3] Adding namespace --- ext/bulk_parent_child/info.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/bulk_parent_child/info.php b/ext/bulk_parent_child/info.php index f4a6b673..4f30a9d8 100644 --- a/ext/bulk_parent_child/info.php +++ b/ext/bulk_parent_child/info.php @@ -2,6 +2,7 @@ declare(strict_types=1); +namespace Shimmie2; class BulkParentChildInfo extends ExtensionInfo { From f43ed0ee7176738206e9a28ce65d8f3b0dad7c31 Mon Sep 17 00:00:00 2001 From: myname Date: Mon, 27 Mar 2023 14:28:44 -0500 Subject: [PATCH 3/3] Removing unnecessary lines, fixing namespace --- ext/bulk_parent_child/main.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/ext/bulk_parent_child/main.php b/ext/bulk_parent_child/main.php index 9362debd..296c9af8 100644 --- a/ext/bulk_parent_child/main.php +++ b/ext/bulk_parent_child/main.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace Shimmie2; + class BulkParentChildConfig { } @@ -13,11 +15,6 @@ class BulkParentChild extends Extension { private const PARENT_CHILD_ACTION_NAME = "bulk_parent_child"; - public function onInitExt(InitExtEvent $event) - { - global $config; - } - public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event) { global $user; @@ -27,13 +24,6 @@ class BulkParentChild extends Extension } } - public function onSetupBuilding(SetupBuildingEvent $event) - { - $sb = $event->panel->create_new_block("Bulk Parent Child"); - $sb->start_table(); - $sb->end_table(); - } - public function onBulkAction(BulkActionEvent $event) { global $user, $page, $config;