Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions app/Activity/Models/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,4 @@ public static function incrementFor(Viewable $viewable): int

return $view->views;
}

/**
* Clear all views from the system.
*/
public static function clearAll()
{
static::query()->truncate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Console\Command;
use Symfony\Component\Console\Output\OutputInterface;

class CleanupImages extends Command
class CleanupImagesCommand extends Command
{
/**
* The name and signature of the console command.
Expand All @@ -25,60 +25,49 @@ class CleanupImages extends Command
*/
protected $description = 'Cleanup images and drawings';

protected $imageService;

/**
* Create a new command instance.
*
* @param \BookStack\Uploads\ImageService $imageService
*/
public function __construct(ImageService $imageService)
{
$this->imageService = $imageService;
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle(ImageService $imageService): int
{
$checkRevisions = $this->option('all') ? false : true;
$dryRun = $this->option('force') ? false : true;
$checkRevisions = !$this->option('all');
$dryRun = !$this->option('force');

if (!$dryRun) {
$proceed = $this->confirm("This operation is destructive and is not guaranteed to be fully accurate.\nEnsure you have a backup of your images.\nAre you sure you want to proceed?");
$this->warn("This operation is destructive and is not guaranteed to be fully accurate.\nEnsure you have a backup of your images.\n");
$proceed = $this->confirm("Are you sure you want to proceed?");
if (!$proceed) {
return;
return 0;
}
}

$deleted = $this->imageService->deleteUnusedImages($checkRevisions, $dryRun);
$deleted = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
$deleteCount = count($deleted);

if ($dryRun) {
$this->comment('Dry run, No images have been deleted');
$this->comment('Dry run, no images have been deleted');
$this->comment($deleteCount . ' images found that would have been deleted');
$this->showDeletedImages($deleted);
$this->comment('Run with -f or --force to perform deletions');

return;
return 0;
}

$this->showDeletedImages($deleted);
$this->comment($deleteCount . ' images deleted');
return 0;
}

protected function showDeletedImages($paths)
protected function showDeletedImages($paths): void
{
if ($this->getOutput()->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL) {
return;
}

if (count($paths) > 0) {
$this->line('Images to delete:');
}

foreach ($paths as $path) {
$this->line($path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use BookStack\Activity\Models\Activity;
use Illuminate\Console\Command;

class ClearActivity extends Command
class ClearActivityCommand extends Command
{
/**
* The name and signature of the console command.
Expand All @@ -21,27 +21,13 @@ class ClearActivity extends Command
*/
protected $description = 'Clear user activity from the system';

protected $activity;

/**
* Create a new command instance.
*
* @param Activity $activity
*/
public function __construct(Activity $activity)
{
$this->activity = $activity;
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle(): int
{
$this->activity->newQuery()->truncate();
Activity::query()->truncate();
$this->comment('System activity cleared');
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use BookStack\Entities\Models\PageRevision;
use Illuminate\Console\Command;

class ClearRevisions extends Command
class ClearRevisionsCommand extends Command
{
/**
* The name and signature of the console command.
Expand All @@ -23,28 +23,14 @@ class ClearRevisions extends Command
*/
protected $description = 'Clear page revisions';

protected $pageRevision;

/**
* Create a new command instance.
*
* @param PageRevision $pageRevision
*/
public function __construct(PageRevision $pageRevision)
{
$this->pageRevision = $pageRevision;
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle(): int
{
$deleteTypes = $this->option('all') ? ['version', 'update_draft'] : ['version'];
$this->pageRevision->newQuery()->whereIn('type', $deleteTypes)->delete();
PageRevision::query()->whereIn('type', $deleteTypes)->delete();
$this->comment('Revisions deleted');
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use BookStack\Activity\Models\View;
use Illuminate\Console\Command;

class ClearViews extends Command
class ClearViewsCommand extends Command
{
/**
* The name and signature of the console command.
Expand All @@ -21,22 +21,13 @@ class ClearViews extends Command
*/
protected $description = 'Clear all view-counts for all entities';

/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle(): int
{
View::clearAll();
View::query()->truncate();
$this->comment('Views cleared');
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use BookStack\Entities\Tools\PermissionsUpdater;
use Illuminate\Console\Command;

class CopyShelfPermissions extends Command
class CopyShelfPermissionsCommand extends Command
{
/**
* The name and signature of the console command.
Expand All @@ -25,25 +25,10 @@ class CopyShelfPermissions extends Command
*/
protected $description = 'Copy shelf permissions to all child books';

protected PermissionsUpdater $permissionsUpdater;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct(PermissionsUpdater $permissionsUpdater)
{
$this->permissionsUpdater = $permissionsUpdater;
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle(PermissionsUpdater $permissionsUpdater): int
{
$shelfSlug = $this->option('slug');
$cascadeAll = $this->option('all');
Expand All @@ -52,7 +37,7 @@ public function handle()
if (!$cascadeAll && !$shelfSlug) {
$this->error('Either a --slug or --all option must be provided.');

return;
return 1;
}

if ($cascadeAll) {
Expand All @@ -63,7 +48,7 @@ public function handle()
);

if (!$continue && !$this->hasOption('no-interaction')) {
return;
return 0;
}

$shelves = Bookshelf::query()->get(['id']);
Expand All @@ -77,10 +62,11 @@ public function handle()
}

foreach ($shelves as $shelf) {
$this->permissionsUpdater->updateBookPermissionsFromShelf($shelf, false);
$permissionsUpdater->updateBookPermissionsFromShelf($shelf, false);
$this->info('Copied permissions for shelf [' . $shelf->id . ']');
}

$this->info('Permissions copied for ' . $shelves->count() . ' shelves.');
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace BookStack\Console\Commands;

use BookStack\Exceptions\NotFoundException;
use BookStack\Users\Models\Role;
use BookStack\Users\UserRepo;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules\Password;
use Illuminate\Validation\Rules\Unique;
use Symfony\Component\Console\Command\Command as SymfonyCommand;

class CreateAdmin extends Command
class CreateAdminCommand extends Command
{
/**
* The name and signature of the console command.
Expand All @@ -32,25 +30,10 @@ class CreateAdmin extends Command
*/
protected $description = 'Add a new admin user to the system';

protected $userRepo;

/**
* Create a new command instance.
*/
public function __construct(UserRepo $userRepo)
{
$this->userRepo = $userRepo;
parent::__construct();
}

/**
* Execute the console command.
*
* @throws NotFoundException
*
* @return mixed
*/
public function handle()
public function handle(UserRepo $userRepo): int
{
$details = $this->snakeCaseOptions();

Expand Down Expand Up @@ -82,17 +65,17 @@ public function handle()
$this->error($error);
}

return SymfonyCommand::FAILURE;
return 1;
}

$user = $this->userRepo->createWithoutActivity($validator->validated());
$user = $userRepo->createWithoutActivity($validator->validated());
$user->attachRole(Role::getSystemRole('admin'));
$user->email_confirmed = true;
$user->save();

$this->info("Admin account with email \"{$user->email}\" successfully created!");

return SymfonyCommand::SUCCESS;
return 0;
}

protected function snakeCaseOptions(): array
Expand Down
53 changes: 0 additions & 53 deletions app/Console/Commands/DeleteUsers.php

This file was deleted.

Loading