]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Models/Deletion.php
Fixed failing test after drawio default url change
[bookstack] / app / Entities / Models / Deletion.php
index dab44d4ad31e94841ec83b9c9d4aea4a843c9771..181c9c5803d6441254bd89fc92e66cbddf27c4d0 100644 (file)
@@ -1,14 +1,19 @@
-<?php namespace BookStack\Entities;
+<?php
+
+namespace BookStack\Entities\Models;
 
 use BookStack\Auth\User;
+use BookStack\Interfaces\Deletable;
 use BookStack\Interfaces\Loggable;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Database\Eloquent\Relations\MorphTo;
 
+/**
+ * @property Deletable $deletable
+ */
 class Deletion extends Model implements Loggable
 {
-
     /**
      * Get the related deletable record.
      */
@@ -18,7 +23,7 @@ class Deletion extends Model implements Loggable
     }
 
     /**
-     * The the user that performed the deletion.
+     * Get the user that performed the deletion.
      */
     public function deleter(): BelongsTo
     {
@@ -28,20 +33,34 @@ class Deletion extends Model implements Loggable
     /**
      * Create a new deletion record for the provided entity.
      */
-    public static function createForEntity(Entity $entity): Deletion
+    public static function createForEntity(Entity $entity): self
     {
         $record = (new self())->forceFill([
-            'deleted_by' => user()->id,
+            'deleted_by'     => user()->id,
             'deletable_type' => $entity->getMorphClass(),
-            'deletable_id' => $entity->id,
+            '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}";
+
+        if ($deletable instanceof Entity) {
+            return "Deletion ({$this->id}) for {$deletable->getType()} ({$deletable->id}) {$deletable->name}";
+        }
+
+        return "Deletion ({$this->id})";
+    }
+
+    /**
+     * Get a URL for this specific deletion.
+     */
+    public function getUrl(string $path = 'restore'): string
+    {
+        return url("/settings/recycle-bin/{$this->id}/" . ltrim($path, '/'));
     }
 }