]> BookStack Code Mirror - bookstack/blobdiff - app/Services/ActivityService.php
Fixed entity messages on delete. Fixes #21.
[bookstack] / app / Services / ActivityService.php
index f0c52758641551a8d4301210fc30769284096827..4ee05d59f8951c1f6e2d497f6b6aab37541db645 100644 (file)
@@ -21,9 +21,10 @@ class ActivityService
 
     /**
      * Add activity data to database.
-     * @para Entity $entity
+     * @param Entity $entity
      * @param $activityKey
      * @param int $bookId
+     * @param bool $extra
      */
     public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false)
     {
@@ -53,6 +54,25 @@ class ActivityService
         $this->activity->save();
     }
 
+    /**
+     * Removes the entity attachment from each of its activities
+     * and instead uses the 'extra' field with the entities name.
+     * Used when an entity is deleted.
+     * @param Entity $entity
+     * @return mixed
+     */
+    public function removeEntity(Entity $entity)
+    {
+        $activities = $entity->activity;
+        foreach($activities as $activity) {
+            $activity->extra = $entity->name;
+            $activity->entity_id = 0;
+            $activity->entity_type = null;
+            $activity->save();
+        }
+        return $activities;
+    }
+
     /**
      * Gets the latest activity.
      * @param int $count