*/
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');
}
}
{
$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());
}
}
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
{
}
}
}
-
+
// Delete file and database entry
unlink($folder . '/' . $fileName);
$image->delete();
$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());
}
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', '.*');
/**
* 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)
{
$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