mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-23 23:29:59 +08:00
Fixed entity messages on delete. Fixes #21.
This commit is contained in:
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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', '.*');
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user