mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-24 22:59:52 +08:00
3a402f6adc
On restore, added a link to the parent deletion restore if any exists on a cascading parent. Added a test to cover this case to ensure its shown. Also tweaked default empty state message on recycle bin item list to align with new column count. Also done a little existing code cleanup including a getUrl helper on the deletion items. Related to #2682 & #2594
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php namespace BookStack\Entities\Models;
|
|
|
|
use BookStack\Auth\User;
|
|
use BookStack\Entities\Models\Entity;
|
|
use BookStack\Interfaces\Loggable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
/**
|
|
* @property Model deletable
|
|
*/
|
|
class Deletion extends Model implements Loggable
|
|
{
|
|
|
|
/**
|
|
* Get the related deletable record.
|
|
*/
|
|
public function deletable(): MorphTo
|
|
{
|
|
return $this->morphTo('deletable')->withTrashed();
|
|
}
|
|
|
|
/**
|
|
* The the user that performed the deletion.
|
|
*/
|
|
public function deleter(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'deleted_by');
|
|
}
|
|
|
|
/**
|
|
* Create a new deletion record for the provided entity.
|
|
*/
|
|
public static function createForEntity(Entity $entity): Deletion
|
|
{
|
|
$record = (new self())->forceFill([
|
|
'deleted_by' => user()->id,
|
|
'deletable_type' => $entity->getMorphClass(),
|
|
'deletable_id' => $entity->id,
|
|
]);
|
|
$record->save();
|
|
return $record;
|
|
}
|
|
|
|
public function logDescriptor(): string
|
|
{
|
|
$deletable = $this->deletable()->first();
|
|
return "Deletion ({$this->id}) for {$deletable->getType()} ({$deletable->id}) {$deletable->name}";
|
|
}
|
|
|
|
/**
|
|
* Get a URL for this specific deletion.
|
|
*/
|
|
public function getUrl($path): string
|
|
{
|
|
return url("/settings/recycle-bin/{$this->id}/" . ltrim($path, '/'));
|
|
}
|
|
}
|