/**
  * @param string $log
  * @param mixed $object
  * @return int
  */
 public static function logWithBackup($log, $object)
 {
     // default text if log string empty
     $log = $log ?: 'Backed up \'' . substr(strrchr(get_class($object), '\\'), 1) . '\'  ID ' . $object->id;
     // record and get log ID
     $logId = static::log($log);
     // backup object
     Backup::new_backup($logId, get_class($object), $object);
     return $logId;
 }
Exemple #2
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 delete()
 {
     $log_id = AdminLog::new_log('User role \'' . $this->name . '\' deleted');
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\UserRole', $this);
     $actions = UserRoleAction::where('role_id', '=', $this->id);
     $page_actions = UserRolePageAction::where('role_id', '=', $this->id);
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\UserRoleAction', $actions->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\UserRolePageAction', $page_actions->get());
     // delete data
     parent::delete();
     $actions->delete();
     $page_actions->delete();
     return $log_id;
 }
Exemple #4
0
 public function delete()
 {
     $log_id = AdminLog::new_log('User \'' . $this->email . '\' deleted');
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\User', $this);
     // delete data
     parent::delete();
     return $log_id;
 }