]> BookStack Code Mirror - bookstack/commitdiff
Fixed entity messages on delete. Fixes #21.
authorDan Brown <redacted>
Sun, 23 Aug 2015 13:20:34 +0000 (14:20 +0100)
committerDan Brown <redacted>
Sun, 23 Aug 2015 13:20:34 +0000 (14:20 +0100)
app/Http/Controllers/BookController.php
app/Http/Controllers/ChapterController.php
app/Http/Controllers/ImageController.php
app/Http/Controllers/PageController.php
app/Http/routes.php
app/Services/ActivityService.php

index 69052b748ffe54077282c09cc1ce43cdbc9fc2e7..dd919c6c268a317f0228f5015b16eac51a929523 100644 (file)
@@ -135,9 +135,9 @@ class BookController extends Controller
      */
     public function destroy($bookSlug)
     {
-        $bookName = $this->bookRepo->getBySlug($bookSlug)->name;
+        $book = $this->bookRepo->getBySlug($bookSlug);
+        Activity::addMessage('book_delete', 0, $book->name);
         $this->bookRepo->destroyBySlug($bookSlug);
-        Activity::addMessage('book_delete', 0, $bookName);
         return redirect('/books');
     }
 }
index 0d7d09c6417eedd86db5ddd30ed9f3389796fa14..12bbeeab04a636a0aa1bd62b36032550f6c2e5a8 100644 (file)
@@ -137,15 +137,15 @@ class ChapterController extends Controller
     {
         $book = $this->bookRepo->getBySlug($bookSlug);
         $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
-        $chapterName = $chapter->name;
         if(count($chapter->pages) > 0) {
             foreach($chapter->pages as $page) {
                 $page->chapter_id = 0;
                 $page->save();
             }
         }
+        Activity::removeEntity($chapter);
+        Activity::addMessage('chapter_delete', $book->id, $chapter->name);
         $chapter->delete();
-        Activity::addMessage('chapter_delete', $book->id, $chapterName);
         return redirect($book->getUrl());
     }
 }
index aa8cc9ee899572bb99c1dce291a5a7736e51572d..50341fe1fdeb1c99b081571c372976c17b16b08b 100644 (file)
@@ -4,15 +4,11 @@ namespace Oxbow\Http\Controllers;
 
 use Illuminate\Filesystem\Filesystem as File;
 use Illuminate\Http\Request;
-
 use Illuminate\Support\Facades\Auth;
 use Intervention\Image\Facades\Image as ImageTool;
 use Illuminate\Support\Facades\DB;
 use Oxbow\Http\Requests;
 use Oxbow\Image;
-use RecursiveDirectoryIterator;
-use RecursiveIteratorIterator;
-use RegexIterator;
 
 class ImageController extends Controller
 {
@@ -192,7 +188,7 @@ class ImageController extends Controller
                 }
             }
         }
-        
+
         // Delete file and database entry
         unlink($folder . '/' . $fileName);
         $image->delete();
index e26af8d4aa52d24e8f705b07597557577680a808..5921fce3f133c995c6d98c1d27ea03a2fb584e20 100644 (file)
@@ -219,6 +219,7 @@ class PageController extends Controller
         $book = $this->bookRepo->getBySlug($bookSlug);
         $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
         Activity::addMessage('page_delete', $book->id, $page->name);
+        Activity::removeEntity($page);
         $page->delete();
         return redirect($book->getUrl());
     }
index a3db08a0de85a9b9688ed79dfa42437b3f98fc13..a6cda78e6dbc0d4cbbd872c227d57b907defb041 100644 (file)
@@ -70,7 +70,6 @@ Route::group(['middleware' => 'auth'], function() {
     Route::get('/images/all', 'ImageController@getAll');
     Route::put('/images/update/{imageId}', 'ImageController@update');
     Route::delete('/images/{imageId}', 'ImageController@destroy');
-    Route::get('/images/{imageId}/delete', 'ImageController@destroy');
     Route::get('/images/all/{page}', 'ImageController@getAll');
     Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*');
 
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