diff --git a/app/CMS/Interactions/Admin/Content/ChangeStatus.php b/app/CMS/Interactions/Admin/Content/ChangeStatus.php index 07386aa4..ec8577ab 100644 --- a/app/CMS/Interactions/Admin/Content/ChangeStatus.php +++ b/app/CMS/Interactions/Admin/Content/ChangeStatus.php @@ -2,23 +2,37 @@ namespace App\CMS\Interactions\Admin\Content; use App\CMS\Contracts\Interaction; -use App\Http\Requests\Request; +use App\CMS\Enumerations\ContentStatuses; -class ChangeStatus implements Interaction { - public function handle(Request $data, $parameters) +class ChangeStatus implements Interaction +{ + /** + * Change status of content page + * + * @param array $data + * @param array $parameters + * + * @return mixed|void + */ + public function handle($data, $parameters) + { + list ($page) = $parameters; + + $page->status = $data['status']; + $page->save(); + } + + /** + * Check if status is valid + * + * @param array $parameters + * + * @return array + */ + public function getValidationRules($parameters = []) { $statuses = ContentStatuses::getWithTranslations(); - // check if given status is valid - if (!isset($statuses[$status])) { - return redirect() - ->route('content.overview') - ->with('error', trans('admin/contents.invalidStatus')); - } - } - - public function getValidationRules($parameters) - { - // TODO: Implement getValidationRules() method. + return ['status' => 'in:' . implode(',', array_keys($statuses))]; } } \ No newline at end of file diff --git a/app/CMS/Interactions/Admin/Content/DeletePage.php b/app/CMS/Interactions/Admin/Content/DeletePage.php index e69de29b..c4364f7f 100644 --- a/app/CMS/Interactions/Admin/Content/DeletePage.php +++ b/app/CMS/Interactions/Admin/Content/DeletePage.php @@ -0,0 +1,45 @@ +delete(); + + // let module to delete some extra content created during page's life + $module->callOnString($page->moduleHandler, 'delete', [$page]); + } + + /** + * @param $data array input data + * + * @return array + */ + public function getValidationRules($data = []) + { + return []; + } +} \ No newline at end of file diff --git a/app/CMS/Interactions/Admin/Content/SetHomepage.php b/app/CMS/Interactions/Admin/Content/SetHomepage.php index e69de29b..1b7eb3cc 100644 --- a/app/CMS/Interactions/Admin/Content/SetHomepage.php +++ b/app/CMS/Interactions/Admin/Content/SetHomepage.php @@ -0,0 +1,43 @@ +where('language', LaravelLocalization::getCurrentLocale()) + ->update(['isHomepage' => false]); + + // set new homepage + $page->isHomepage = true; + $page->save(); + } + + /** + * Check if status is valid + * + * @param array $parameters + * + * @return array + */ + public function getValidationRules($parameters = []) + { + return []; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Admin/Contents/ContentActions.php b/app/Http/Controllers/Admin/Contents/ContentActions.php index 7fdd4773..c73c4085 100644 --- a/app/Http/Controllers/Admin/Contents/ContentActions.php +++ b/app/Http/Controllers/Admin/Contents/ContentActions.php @@ -1,19 +1,25 @@ content = $content; + } + /** * Method for changing page status * This method is called in static page overview from quick actions. It checks if status is valid, if page exists @@ -26,36 +32,9 @@ class ContentActions extends Controller */ public function changeStatus($id, $status) { - // get possible statuses - $statuses = ContentStatuses::getWithTranslations(); - - // check if given status is valid - if (!isset($statuses[$status])) { - return redirect() - ->route('content.overview') - ->with('error', trans('admin/contents.invalidStatus')); - } - - // try to find this page - $page = Content::findOrFail($id); - - // try to change the page - list ($revision, $changedColumns) = $page->updateWithHistory(['status' => 'status'], ['status' => $status]); - // fire events - if ($status != Content::STATUS_DRAFT) { - Event::fire(new PublishContent($page, $revision)); - } else { - Event::fire(new MakeDraftFromContent($page, $revision)); - } - - // was something changed? - if ($changedColumns == 0) { - return redirect() - ->route('content.edit', ['id' => $page->id]) - ->with('error', trans('admin/contents.nothingToEdit')); - } - + $page = $this->content->getOne($id); + Interaction::handle(ChangeStatus::class, ['status' => $status], $page); // redirect back to overview with info for user return redirect() @@ -72,36 +51,15 @@ class ContentActions extends Controller */ public function delete($id) { - try { - // try to find this page - $page = Content::findOrFail($id); - } catch (NotFoundHttpException $e) { - // page not found - return redirect() - ->route('content.overview') - ->with('error', trans('admin/contents.invalidPage')); - } + $page = $this->content->getOne($id); - // change url to something unique - $oldURL = $page->url; - $page->url .= uniqid('_deleted_'); - $page->save(); - - // delete page - $page->delete(); - - // let module to delete some extra content created during page's life - call_user_func([$page->moduleHandler, 'delete'], $page); - - // trigger delete event - Event::fire(new DeleteContent($page)); + Interaction::handle(DeletePage::class, [], $page); // redirect back to overview with info for user return redirect() ->route('content.overview') ->with('success', trans('admin/contents.pageDeleted', [ - 'name' => $page->title, - 'url' => $oldURL + 'name' => $page->title ])); } @@ -114,36 +72,9 @@ class ContentActions extends Controller */ public function setHomepage($id) { - try { - // try to find this page - /** - * @var $page Content - */ - $page = Content::findOrFail($id); - } catch (NotFoundHttpException $e) { - // page not found - return redirect() - ->back() - ->with('error', trans('admin/contents.invalidPage')); - } + $page = $this->content->getOne($id); - // disable any other existing homepage - Content::where('isHomepage', 1) - ->where('language', LaravelLocalization::getCurrentLocale()) - ->update(['isHomepage' => 0]); - - // set new homepage - list ($revision, $changedColumns) = $page->updateWithHistory(['isHomepage' => 'isHomepage'], ['isHomepage' => 1]); - - // was something changed? - if ($changedColumns == 0) { - return redirect() - ->back() - ->with('error', trans('admin/contents.nothingToEdit')); - } - - // trigger delete event - Event::fire(new SetHomepage($page, $revision)); + Interaction::handle(SetHomepage::class, [], $page); // redirect back to overview with info for user return redirect()