2022-04-07 04:57:18 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Entities\Repos;
|
|
|
|
|
2023-05-18 00:56:55 +08:00
|
|
|
use BookStack\Activity\ActivityType;
|
2022-04-07 04:57:18 +08:00
|
|
|
use BookStack\Entities\Models\Deletion;
|
|
|
|
use BookStack\Entities\Tools\TrashCan;
|
|
|
|
use BookStack\Facades\Activity;
|
|
|
|
|
|
|
|
class DeletionRepo
|
|
|
|
{
|
|
|
|
private TrashCan $trashCan;
|
|
|
|
|
|
|
|
public function __construct(TrashCan $trashCan)
|
|
|
|
{
|
|
|
|
$this->trashCan = $trashCan;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function restore(int $id): int
|
|
|
|
{
|
|
|
|
/** @var Deletion $deletion */
|
|
|
|
$deletion = Deletion::query()->findOrFail($id);
|
|
|
|
Activity::add(ActivityType::RECYCLE_BIN_RESTORE, $deletion);
|
2022-04-21 04:58:16 +08:00
|
|
|
|
2022-04-07 04:57:18 +08:00
|
|
|
return $this->trashCan->restoreFromDeletion($deletion);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(int $id): int
|
|
|
|
{
|
|
|
|
/** @var Deletion $deletion */
|
|
|
|
$deletion = Deletion::query()->findOrFail($id);
|
|
|
|
Activity::add(ActivityType::RECYCLE_BIN_DESTROY, $deletion);
|
2022-04-21 04:58:16 +08:00
|
|
|
|
2022-04-07 04:57:18 +08:00
|
|
|
return $this->trashCan->destroyFromDeletion($deletion);
|
|
|
|
}
|
|
|
|
}
|