Merge pull request #909 from yls4/master

Bulk Actions for setting a chain of parent child relationships in the…
This commit is contained in:
Shish 2023-03-29 00:04:15 +01:00 committed by GitHub
commit eea4866e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 0 deletions

View File

@ -118,4 +118,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";
}

View File

@ -223,6 +223,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,

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
class BulkParentChildInfo extends ExtensionInfo
{
public const KEY = "bulk_parent_child";
public string $key = self::KEY;
public string $name = "Bulk Parent Child";
public array $authors = ["Flatty"=>""];
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];
}

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
class BulkParentChildConfig
{
}
class BulkParentChildException extends BulkActionException
{
}
class BulkParentChild extends Extension
{
private const PARENT_CHILD_ACTION_NAME = "bulk_parent_child";
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
{
global $user;
if ($user->can(Permissions::BULK_PARENT_CHILD)) {
$event->add_action(BulkParentChild::PARENT_CHILD_ACTION_NAME, "Set Parent Child");
}
}
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;
}
}
}
}