Exemple #1
0
 public function delete()
 {
     $page_name = PageLang::getName($this->id);
     $log_id = AdminLog::new_log('Page \'' . $page_name . '\' deleted (Page ID ' . $this->id . ')');
     // make backups
     $page_versions = PageVersion::where('page_id', '=', $this->id);
     $page_langs = PageLang::where('page_id', '=', $this->id);
     $page_blocks = PageBlock::where('page_id', '=', $this->id);
     $menu_items = MenuItem::where('page_id', '=', $this->id)->orWhere('page_id', 'LIKE', $this->id . ',%');
     $user_role_page_actions = UserRolePageAction::where('page_id', '=', $this->id);
     $page_groups = PageGroupPage::where('page_id', '=', $this->id);
     $publish_request_ids = [];
     foreach ($page_versions as $page_version) {
         $publish_request_ids[] = $page_version->id;
     }
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\Page', $this);
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageVersion', $page_versions->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageLang', $page_langs->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageBlock', $page_blocks->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\MenuItem', $menu_items->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\UserRolePageAction', $user_role_page_actions->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageGroupPage', $page_groups->get());
     // publish requests
     if (!empty($publish_request_ids)) {
         $page_publish_requests = PagePublishRequests::where('page_version_id', '=', $publish_request_ids);
         Backup::new_backup($log_id, '\\CoasterCms\\Models\\PagePublishRequests', $page_publish_requests->get());
         $page_publish_requests->delete();
     }
     // repeater data
     $repeater_block_ids = Block::getBlockIdsOfType('repeater');
     if (!empty($repeater_block_ids)) {
         $repeater_blocks = PageBlock::whereIn('block_id', $repeater_block_ids)->where('page_id', $this->id)->get();
         if (!$repeater_blocks->isEmpty()) {
             $repeater_ids = [];
             foreach ($repeater_blocks as $repeater_block) {
                 $repeater_ids[] = $repeater_block->content;
             }
             $repeater_row_keys = PageBlockRepeaterRows::whereIn('repeater_id', $repeater_ids);
             $repeater_row_keys_get = $repeater_row_keys->get();
             if (!$repeater_row_keys_get->isEmpty()) {
                 $row_keys = [];
                 foreach ($repeater_row_keys_get as $repeater_row_key) {
                     $row_keys[] = $repeater_row_key->id;
                 }
                 $repeater_data = PageBlockRepeaterData::whereIn('row_key', $row_keys);
                 Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageBlockRepeaterRows', $repeater_row_keys->get());
                 Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageBlockRepeaterData', $repeater_data->get());
                 $repeater_data->delete();
                 $repeater_row_keys->delete();
             }
         }
     }
     // delete data
     $this->groups()->detach();
     $page_versions->delete();
     $page_langs->delete();
     $page_blocks->delete();
     $menu_items->delete();
     $user_role_page_actions->delete();
     PageSearchData::where('page_id', '=', $this->id)->delete();
     parent::delete();
     $return_log_ids = array($log_id);
     $child_pages = self::where('parent', '=', $this->id)->get();
     if (!empty($child_pages)) {
         foreach ($child_pages as $child_page) {
             $log_ids = $child_page->delete();
             $return_log_ids = array_merge($log_ids, $return_log_ids);
         }
     }
     sort($return_log_ids);
     return $return_log_ids;
 }
 public function postEdit($pageId)
 {
     $existingPage = Page::find($pageId);
     if (!$existingPage) {
         return 'Page not found';
     }
     $publish = false;
     $publishing = (bool) config('coaster::admin.publishing');
     $canPublish = Auth::action('pages.version-publish', ['page_id' => $pageId]);
     if ($publishing && $existingPage->link == 0) {
         // check if publish
         if (Request::input('publish') != '' && $canPublish) {
             $publish = true;
             // check if there were requests to publish the version being edited
             $overwriting_page_version = PageVersion::where('version_id', '=', Request::input('versionFrom'))->where('page_id', '=', $pageId)->first();
             $requests = PagePublishRequests::where('page_version_id', '=', $overwriting_page_version->id)->where('status', '=', 'awaiting')->get();
             if (!$requests->isEmpty()) {
                 foreach ($requests as $request) {
                     $request->status = 'approved';
                     $request->mod_id = Auth::user()->id;
                     $request->save();
                 }
             }
         }
     } elseif (!$publishing || $existingPage->link == 1 && $canPublish) {
         $publish = true;
     }
     $page_info = Request::input('page_info') ?: [];
     $page_info_lang = Request::input('page_info_lang') ?: [];
     $page_groups = Request::input('page_groups') ?: [];
     $page_info_other = Request::input('page_info_other') ?: [];
     // run if duplicate button was hit
     if (Request::input('duplicate') == 1) {
         if ($existingPage->canDuplicate()) {
             if ($duplicatePage = $existingPage->saveDuplicateFromPostData($page_info, $page_info_lang, $page_groups, $page_info_other)) {
                 Repeater::setDuplicate();
                 Block::submit($duplicatePage->id, 1, $publish);
                 return \redirect()->route('coaster.admin.pages.edit', ['pageId' => $duplicatePage->id]);
             } else {
                 $this->addAlert('danger', 'Duplication failed');
                 return $this->getEdit($pageId);
             }
         } else {
             return abort(403, 'Action not permitted');
         }
     }
     $version = PageVersion::add_new($pageId);
     // save page info
     if ($existingPage->savePostData($version, $page_info, $page_info_lang, $page_groups, $page_info_other)) {
         AdminLog::new_log('Updated page \'' . $existingPage->pageLang()->name . '\' (Page ID ' . $existingPage->id . ')');
     } else {
         $this->addAlert('warning', '"Page Info" not updated (check tab for errors)');
     }
     // update blocks
     Block::submit($pageId, $version->version_id, $publish);
     $this->addAlert('success', 'Page Content Updated');
     if ($publish) {
         if (Request::input('publish_request') != '') {
             PagePublishRequests::add($pageId, $version->version_id, Request::input('request_note'));
         }
         $version->publish();
     }
     // display page edit form
     return $this->getEdit($pageId, $version->version_id);
 }
 public static function add($page_id, $version_id, $note = null)
 {
     $page_version = PageVersion::where('page_id', '=', $page_id)->where('version_id', '=', $version_id)->first();
     if ($page_version) {
         $page_requests = PagePublishRequests::where('status', '=', 'awaiting')->where('user_id', '=', Auth::user()->id)->get();
         if (!$page_requests->isEmpty()) {
             $page_version_ids = array();
             foreach ($page_requests as $page_request) {
                 $page_version_ids[] = $page_request->page_version_id;
             }
             $previous_requested_page_version = PageVersion::where('page_id', '=', $page_id)->whereIn('id', $page_version_ids)->first();
         }
         if (!empty($previous_requested_page_version)) {
             $page_request = PagePublishRequests::where('page_version_id', '=', $previous_requested_page_version->id)->where('user_id', '=', Auth::user()->id)->where('status', '=', 'awaiting')->first();
             if ($previous_requested_page_version->id == $page_version->id) {
                 $page_request->note = $note;
                 $page_request->save();
                 return 1;
             } else {
                 $page_request->status = 'cancelled';
                 $page_request->save();
             }
         }
         $new_request = new self();
         $new_request->page_version_id = $page_version->id;
         $new_request->status = 'awaiting';
         $new_request->user_id = Auth::user()->id;
         $new_request->mod_id = 0;
         $new_request->note = $note;
         $new_request->save();
         return 1;
     }
     return 0;
 }