/** * Store changes to this entry * * @param boolean $check Perform data validation check? * @return boolean False if error, True on success */ public function store($check = true) { // Get the entry before changes were made $old = new self($this->get('id')); // Store entry if (!parent::store($check)) { return false; } // If the section is marked as "deleted" and it wasn't already marked as such if ($this->get('state') == self::APP_STATE_DELETED && $old->get('state') != self::APP_STATE_DELETED) { // Collect a list of category IDs $cats = array(); foreach ($this->categories('list', array('state' => -1)) as $category) { $cats[] = $category->get('id'); } if (count($cats) > 0) { // Set all the threads/posts in all the categories to "deleted" $post = new Tables\Post($this->_db); if (!$post->setStateByCategory($cats, self::APP_STATE_DELETED)) { $this->setError($post->getError()); } // Set all the categories to "deleted" $cModel = new Tables\Category($this->_db); if (!$cModel->setStateBySection($this->get('id'), self::APP_STATE_DELETED)) { $this->setError($cModel->getError()); } } } return true; }
/** * Delete a category * * @return void */ public function deleteTask() { // Is the user logged in? if (User::isGuest()) { App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url('index.php?option=' . $this->_option, false, true))), Lang::txt('COM_FORUM_LOGIN_NOTICE'), 'warning'); return; } // Load the section $section = $this->model->section(Request::getVar('section', '')); // Load the category $category = $section->category(Request::getVar('category', '')); // Make the sure the category exist if (!$category->exists()) { App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_MISSING_ID'), 'error'); return; } // Check if user is authorized to delete entries $this->_authorize('category', $category->get('id')); if (!$this->config->get('access-delete-category')) { App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_NOT_AUTHORIZED'), 'warning'); return; } // Set all the threads/posts in all the categories to "deleted" $tModel = new Tables\Post($this->database); if (!$tModel->setStateByCategory($category->get('id'), 2)) { $this->setError($tModel->getError()); } // Set the category to "deleted" $category->set('state', 2); /* 0 = unpublished, 1 = published, 2 = deleted */ if (!$category->store()) { App::redirect(Route::url('index.php?option=' . $this->_option), $category->getError(), 'error'); return; } // Redirect to main listing App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_CATEGORY_DELETED'), 'message'); }