2020-10-03 19:44:12 +02:00
|
|
|
<?php namespace BookStack\Http\Controllers;
|
|
|
|
|
2020-11-19 00:38:44 +01:00
|
|
|
use BookStack\Actions\ActivityType;
|
2020-10-03 19:44:12 +02:00
|
|
|
use BookStack\Entities\Deletion;
|
2020-11-22 00:20:54 +01:00
|
|
|
use BookStack\Entities\Tools\TrashCan;
|
2020-10-03 19:44:12 +02:00
|
|
|
|
|
|
|
class RecycleBinController extends Controller
|
|
|
|
{
|
2020-11-02 23:47:48 +01:00
|
|
|
|
|
|
|
protected $recycleBinBaseUrl = '/settings/recycle-bin';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On each request to a method of this controller check permissions
|
|
|
|
* using a middleware closure.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware(function ($request, $next) {
|
|
|
|
$this->checkPermission('settings-manage');
|
|
|
|
$this->checkPermission('restrictions-manage-all');
|
|
|
|
return $next($request);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-03 19:44:12 +02:00
|
|
|
/**
|
|
|
|
* Show the top-level listing for the recycle bin.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10);
|
|
|
|
|
2020-11-21 18:03:24 +01:00
|
|
|
$this->setPageTitle(trans('settings.recycle_bin'));
|
2020-11-02 23:47:48 +01:00
|
|
|
return view('settings.recycle-bin.index', [
|
2020-10-03 19:44:12 +02:00
|
|
|
'deletions' => $deletions,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-11-02 23:47:48 +01:00
|
|
|
/**
|
|
|
|
* Show the page to confirm a restore of the deletion of the given id.
|
|
|
|
*/
|
|
|
|
public function showRestore(string $id)
|
|
|
|
{
|
|
|
|
/** @var Deletion $deletion */
|
|
|
|
$deletion = Deletion::query()->findOrFail($id);
|
|
|
|
|
|
|
|
return view('settings.recycle-bin.restore', [
|
|
|
|
'deletion' => $deletion,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the element attached to the given deletion.
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function restore(string $id)
|
|
|
|
{
|
|
|
|
/** @var Deletion $deletion */
|
|
|
|
$deletion = Deletion::query()->findOrFail($id);
|
2020-11-19 00:38:44 +01:00
|
|
|
$this->logActivity(ActivityType::RECYCLE_BIN_RESTORE, $deletion);
|
2020-11-02 23:47:48 +01:00
|
|
|
$restoreCount = (new TrashCan())->restoreFromDeletion($deletion);
|
|
|
|
|
|
|
|
$this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount]));
|
|
|
|
return redirect($this->recycleBinBaseUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the page to confirm a Permanent deletion of the element attached to the deletion of the given id.
|
|
|
|
*/
|
|
|
|
public function showDestroy(string $id)
|
|
|
|
{
|
|
|
|
/** @var Deletion $deletion */
|
|
|
|
$deletion = Deletion::query()->findOrFail($id);
|
|
|
|
|
|
|
|
return view('settings.recycle-bin.destroy', [
|
|
|
|
'deletion' => $deletion,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Permanently delete the content associated with the given deletion.
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function destroy(string $id)
|
|
|
|
{
|
|
|
|
/** @var Deletion $deletion */
|
|
|
|
$deletion = Deletion::query()->findOrFail($id);
|
2020-11-20 19:53:01 +01:00
|
|
|
$this->logActivity(ActivityType::RECYCLE_BIN_DESTROY, $deletion);
|
2020-11-02 23:47:48 +01:00
|
|
|
$deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
|
|
|
|
|
|
|
|
$this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
|
|
|
|
return redirect($this->recycleBinBaseUrl);
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:44:12 +02:00
|
|
|
/**
|
|
|
|
* Empty out the recycle bin.
|
2020-11-02 23:47:48 +01:00
|
|
|
* @throws \Exception
|
2020-10-03 19:44:12 +02:00
|
|
|
*/
|
|
|
|
public function empty()
|
|
|
|
{
|
2020-11-06 13:54:39 +01:00
|
|
|
$deleteCount = (new TrashCan())->empty();
|
2020-10-03 19:53:09 +02:00
|
|
|
|
2020-11-19 00:38:44 +01:00
|
|
|
$this->logActivity(ActivityType::RECYCLE_BIN_EMPTY);
|
2020-11-02 23:47:48 +01:00
|
|
|
$this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
|
|
|
|
return redirect($this->recycleBinBaseUrl);
|
2020-10-03 19:44:12 +02:00
|
|
|
}
|
|
|
|
}
|