REFACTORING #1880 @4h30m: another ugly refactoring commit
This commit is contained in:
@@ -36,18 +36,17 @@ class ContentActions extends Controller
|
||||
->with('error', trans('admin/contents.invalidStatus'));
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -56,12 +55,7 @@ class ContentActions extends Controller
|
||||
->with('error', trans('admin/contents.nothingToEdit'));
|
||||
}
|
||||
|
||||
// fire events
|
||||
if ($status != Content::STATUS_DRAFT) {
|
||||
Event::fire(new PublishContent($page, $revision));
|
||||
} else {
|
||||
Event::fire(new MakeDraftFromContent($page, $revision));
|
||||
}
|
||||
|
||||
|
||||
// redirect back to overview with info for user
|
||||
return redirect()
|
||||
@@ -97,7 +91,7 @@ class ContentActions extends Controller
|
||||
$page->delete();
|
||||
|
||||
// let module to delete some extra content created during page's life
|
||||
call_user_func([$page->module_handler, 'delete'], $page);
|
||||
call_user_func([$page->moduleHandler, 'delete'], $page);
|
||||
|
||||
// trigger delete event
|
||||
Event::fire(new DeleteContent($page));
|
||||
@@ -134,12 +128,12 @@ class ContentActions extends Controller
|
||||
}
|
||||
|
||||
// disable any other existing homepage
|
||||
Content::where('is_homepage', 1)
|
||||
Content::where('isHomepage', 1)
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->update(['is_homepage' => 0]);
|
||||
->update(['isHomepage' => 0]);
|
||||
|
||||
// set new homepage
|
||||
list ($revision, $changedColumns) = $page->updateWithHistory(['is_homepage' => 'is_homepage'], ['is_homepage' => 1]);
|
||||
list ($revision, $changedColumns) = $page->updateWithHistory(['isHomepage' => 'isHomepage'], ['isHomepage' => 1]);
|
||||
|
||||
// was something changed?
|
||||
if ($changedColumns == 0) {
|
||||
|
||||
@@ -103,8 +103,11 @@ class CreateNewContent extends Controller
|
||||
{
|
||||
$module = $this->module->getOne($moduleId);
|
||||
|
||||
$titlePhoto = $request->file('titlePhoto');
|
||||
$relatedFiles = $request->all()['files'];
|
||||
|
||||
// create new page
|
||||
Interaction::handle($request, new NewContent(), $module->handler);
|
||||
Interaction::handle(NewContent::class, $request->all(), $module->handler, $titlePhoto, $relatedFiles);
|
||||
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
|
||||
@@ -71,24 +71,24 @@ class EditContent extends Controller
|
||||
/**
|
||||
* Display form for editing static page
|
||||
*
|
||||
* @param $url
|
||||
* @param $id
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($url)
|
||||
public function edit($id)
|
||||
{
|
||||
$statuses = ContentStatuses::getWithTranslations();
|
||||
$page = $this->content->getOne($url);
|
||||
$page = $this->content->getOne($id);
|
||||
|
||||
// get module ID
|
||||
$module = $this->module->getByHandler($page->module_handler);
|
||||
$module = $this->module->getByHandler($page->moduleHandler);
|
||||
$pageHeading = $this->module->getUpdateContentTitle($module, $page);
|
||||
$templates = $this->template->getForModule($module);
|
||||
$categories = $this->category->getForModule($module);
|
||||
$history = $this->history->getStructuredHistoryOf($page);
|
||||
|
||||
// modify data for edit form according to installed template
|
||||
call_user_func_array([CurrentTemplate::handler(), 'beforePopulatingEditForm'], [&$page]);
|
||||
CurrentTemplate::beforePopulatingEditForm($page);
|
||||
|
||||
// render view
|
||||
return view('admin.content.edit', [
|
||||
@@ -132,14 +132,10 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// edit page
|
||||
list($page, $revision, $changedColumns) = Interaction::handle($request, new EditContentInteraction(), $page);
|
||||
$titlePhoto = $request->file('titlePhoto');
|
||||
$relatedFiles = $request->all()['files'];
|
||||
|
||||
// was something changed?
|
||||
if ($changedColumns == 0) {
|
||||
return redirect()
|
||||
->route('content.edit', ['id' => $page->id])
|
||||
->with('error', trans('admin/contents.nothingToEdit'));
|
||||
}
|
||||
Interaction::handle(EditContentInteraction::class, $request->all(), $page, $titlePhoto, $relatedFiles);
|
||||
|
||||
// something was changed, inform user
|
||||
return redirect()
|
||||
@@ -150,12 +146,12 @@ class EditContent extends Controller
|
||||
/**
|
||||
* Convert object of all request data into array of only wanted fields
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $request
|
||||
* @param $fields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getFields(Request $request, $fields)
|
||||
public static function getFields($request, $fields)
|
||||
{
|
||||
$requestData = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user