X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b94b945fb03e21a1997cfe6e50148967586cb26d..refs/pull/3918/head:/app/Console/Commands/CopyShelfPermissions.php diff --git a/app/Console/Commands/CopyShelfPermissions.php b/app/Console/Commands/CopyShelfPermissions.php index d9a1c1d72..ec4c875ff 100644 --- a/app/Console/Commands/CopyShelfPermissions.php +++ b/app/Console/Commands/CopyShelfPermissions.php @@ -2,8 +2,8 @@ namespace BookStack\Console\Commands; -use BookStack\Entities\Bookshelf; -use BookStack\Entities\Repos\BookshelfRepo; +use BookStack\Entities\Models\Bookshelf; +use BookStack\Entities\Tools\PermissionsUpdater; use Illuminate\Console\Command; class CopyShelfPermissions extends Command @@ -23,21 +23,18 @@ class CopyShelfPermissions extends Command * * @var string */ - protected $description = 'Copy shelf permissions to all child books.'; + protected $description = 'Copy shelf permissions to all child books'; - /** - * @var BookshelfRepo - */ - protected $bookshelfRepo; + protected PermissionsUpdater $permissionsUpdater; /** * Create a new command instance. * * @return void */ - public function __construct(BookshelfRepo $repo) + public function __construct(PermissionsUpdater $permissionsUpdater) { - $this->bookshelfRepo = $repo; + $this->permissionsUpdater = $permissionsUpdater; parent::__construct(); } @@ -54,13 +51,14 @@ class CopyShelfPermissions extends Command if (!$cascadeAll && !$shelfSlug) { $this->error('Either a --slug or --all option must be provided.'); + return; } if ($cascadeAll) { $continue = $this->confirm( - 'Permission settings for all shelves will be cascaded. '. - 'Books assigned to multiple shelves will receive only the permissions of it\'s last processed shelf. '. + 'Permission settings for all shelves will be cascaded. ' . + 'Books assigned to multiple shelves will receive only the permissions of it\'s last processed shelf. ' . 'Are you sure you want to proceed?' ); @@ -68,18 +66,18 @@ class CopyShelfPermissions extends Command return; } - $shelves = Bookshelf::query()->get(['id', 'restricted']); + $shelves = Bookshelf::query()->get(['id']); } if ($shelfSlug) { - $shelves = Bookshelf::query()->where('slug', '=', $shelfSlug)->get(['id', 'restricted']); + $shelves = Bookshelf::query()->where('slug', '=', $shelfSlug)->get(['id']); if ($shelves->count() === 0) { $this->info('No shelves found with the given slug.'); } } foreach ($shelves as $shelf) { - $this->bookshelfRepo->copyDownPermissions($shelf, false); + $this->permissionsUpdater->updateBookPermissionsFromShelf($shelf, false); $this->info('Copied permissions for shelf [' . $shelf->id . ']'); }