Showing
6 changed files
with
26 additions
and
10 deletions
| ... | @@ -135,9 +135,9 @@ class BookController extends Controller | ... | @@ -135,9 +135,9 @@ class BookController extends Controller |
| 135 | */ | 135 | */ |
| 136 | public function destroy($bookSlug) | 136 | public function destroy($bookSlug) |
| 137 | { | 137 | { |
| 138 | - $bookName = $this->bookRepo->getBySlug($bookSlug)->name; | 138 | + $book = $this->bookRepo->getBySlug($bookSlug); |
| 139 | + Activity::addMessage('book_delete', 0, $book->name); | ||
| 139 | $this->bookRepo->destroyBySlug($bookSlug); | 140 | $this->bookRepo->destroyBySlug($bookSlug); |
| 140 | - Activity::addMessage('book_delete', 0, $bookName); | ||
| 141 | return redirect('/books'); | 141 | return redirect('/books'); |
| 142 | } | 142 | } |
| 143 | } | 143 | } | ... | ... |
| ... | @@ -137,15 +137,15 @@ class ChapterController extends Controller | ... | @@ -137,15 +137,15 @@ class ChapterController extends Controller |
| 137 | { | 137 | { |
| 138 | $book = $this->bookRepo->getBySlug($bookSlug); | 138 | $book = $this->bookRepo->getBySlug($bookSlug); |
| 139 | $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id); | 139 | $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id); |
| 140 | - $chapterName = $chapter->name; | ||
| 141 | if(count($chapter->pages) > 0) { | 140 | if(count($chapter->pages) > 0) { |
| 142 | foreach($chapter->pages as $page) { | 141 | foreach($chapter->pages as $page) { |
| 143 | $page->chapter_id = 0; | 142 | $page->chapter_id = 0; |
| 144 | $page->save(); | 143 | $page->save(); |
| 145 | } | 144 | } |
| 146 | } | 145 | } |
| 146 | + Activity::removeEntity($chapter); | ||
| 147 | + Activity::addMessage('chapter_delete', $book->id, $chapter->name); | ||
| 147 | $chapter->delete(); | 148 | $chapter->delete(); |
| 148 | - Activity::addMessage('chapter_delete', $book->id, $chapterName); | ||
| 149 | return redirect($book->getUrl()); | 149 | return redirect($book->getUrl()); |
| 150 | } | 150 | } |
| 151 | } | 151 | } | ... | ... |
| ... | @@ -4,15 +4,11 @@ namespace Oxbow\Http\Controllers; | ... | @@ -4,15 +4,11 @@ namespace Oxbow\Http\Controllers; |
| 4 | 4 | ||
| 5 | use Illuminate\Filesystem\Filesystem as File; | 5 | use Illuminate\Filesystem\Filesystem as File; |
| 6 | use Illuminate\Http\Request; | 6 | use Illuminate\Http\Request; |
| 7 | - | ||
| 8 | use Illuminate\Support\Facades\Auth; | 7 | use Illuminate\Support\Facades\Auth; |
| 9 | use Intervention\Image\Facades\Image as ImageTool; | 8 | use Intervention\Image\Facades\Image as ImageTool; |
| 10 | use Illuminate\Support\Facades\DB; | 9 | use Illuminate\Support\Facades\DB; |
| 11 | use Oxbow\Http\Requests; | 10 | use Oxbow\Http\Requests; |
| 12 | use Oxbow\Image; | 11 | use Oxbow\Image; |
| 13 | -use RecursiveDirectoryIterator; | ||
| 14 | -use RecursiveIteratorIterator; | ||
| 15 | -use RegexIterator; | ||
| 16 | 12 | ||
| 17 | class ImageController extends Controller | 13 | class ImageController extends Controller |
| 18 | { | 14 | { | ... | ... |
| ... | @@ -219,6 +219,7 @@ class PageController extends Controller | ... | @@ -219,6 +219,7 @@ class PageController extends Controller |
| 219 | $book = $this->bookRepo->getBySlug($bookSlug); | 219 | $book = $this->bookRepo->getBySlug($bookSlug); |
| 220 | $page = $this->pageRepo->getBySlug($pageSlug, $book->id); | 220 | $page = $this->pageRepo->getBySlug($pageSlug, $book->id); |
| 221 | Activity::addMessage('page_delete', $book->id, $page->name); | 221 | Activity::addMessage('page_delete', $book->id, $page->name); |
| 222 | + Activity::removeEntity($page); | ||
| 222 | $page->delete(); | 223 | $page->delete(); |
| 223 | return redirect($book->getUrl()); | 224 | return redirect($book->getUrl()); |
| 224 | } | 225 | } | ... | ... |
| ... | @@ -70,7 +70,6 @@ Route::group(['middleware' => 'auth'], function() { | ... | @@ -70,7 +70,6 @@ Route::group(['middleware' => 'auth'], function() { |
| 70 | Route::get('/images/all', 'ImageController@getAll'); | 70 | Route::get('/images/all', 'ImageController@getAll'); |
| 71 | Route::put('/images/update/{imageId}', 'ImageController@update'); | 71 | Route::put('/images/update/{imageId}', 'ImageController@update'); |
| 72 | Route::delete('/images/{imageId}', 'ImageController@destroy'); | 72 | Route::delete('/images/{imageId}', 'ImageController@destroy'); |
| 73 | - Route::get('/images/{imageId}/delete', 'ImageController@destroy'); | ||
| 74 | Route::get('/images/all/{page}', 'ImageController@getAll'); | 73 | Route::get('/images/all/{page}', 'ImageController@getAll'); |
| 75 | Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*'); | 74 | Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*'); |
| 76 | 75 | ... | ... |
| ... | @@ -21,9 +21,10 @@ class ActivityService | ... | @@ -21,9 +21,10 @@ class ActivityService |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * Add activity data to database. | 23 | * Add activity data to database. |
| 24 | - * @para Entity $entity | 24 | + * @param Entity $entity |
| 25 | * @param $activityKey | 25 | * @param $activityKey |
| 26 | * @param int $bookId | 26 | * @param int $bookId |
| 27 | + * @param bool $extra | ||
| 27 | */ | 28 | */ |
| 28 | public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false) | 29 | public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false) |
| 29 | { | 30 | { |
| ... | @@ -54,6 +55,25 @@ class ActivityService | ... | @@ -54,6 +55,25 @@ class ActivityService |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | /** | 57 | /** |
| 58 | + * Removes the entity attachment from each of its activities | ||
| 59 | + * and instead uses the 'extra' field with the entities name. | ||
| 60 | + * Used when an entity is deleted. | ||
| 61 | + * @param Entity $entity | ||
| 62 | + * @return mixed | ||
| 63 | + */ | ||
| 64 | + public function removeEntity(Entity $entity) | ||
| 65 | + { | ||
| 66 | + $activities = $entity->activity; | ||
| 67 | + foreach($activities as $activity) { | ||
| 68 | + $activity->extra = $entity->name; | ||
| 69 | + $activity->entity_id = 0; | ||
| 70 | + $activity->entity_type = null; | ||
| 71 | + $activity->save(); | ||
| 72 | + } | ||
| 73 | + return $activities; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 57 | * Gets the latest activity. | 77 | * Gets the latest activity. |
| 58 | * @param int $count | 78 | * @param int $count |
| 59 | * @param int $page | 79 | * @param int $page | ... | ... |
-
Please register or sign in to post a comment