/** * Approve a revision * * @return void */ public function approveTask() { // Check if they are logged in if (User::isGuest()) { $url = Request::getVar('REQUEST_URI', '', 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url), false)); } // Incoming $id = Request::getInt('oldid', 0); if (!$id || !$this->page->access('manage')) { App::redirect(Route::url($this->page->link())); } // Load the revision, approve it, and save $revision = Version::oneOrFail($id); $revision->set('approved', 1); if (!$revision->save()) { App::abort(500, $revision->getError()); } // Get the most recent revision and compare to the set "current" version $last = $this->page->versions()->whereEquals('approved', 1)->order('version', 'desc')->row(); if ($last->get('id') == $revision->get('id')) { // The newly approved revision is now the most current // So, we need to update the page's version_id $this->page->set('version_id', $last->get('id')); $this->page->save(); } $this->page->log('revision_approved'); // Log activity $recipients = array(['wiki.site', 1], ['user', $this->page->get('created_by')], ['user', $revision->get('created_by')]); if ($this->page->get('scope') != 'site') { $recipients[] = [$this->page->get('scope'), $this->page->get('scope_id')]; $recipients[0] = ['wiki.' . $this->page->get('scope'), $this->page->get('scope_id')]; } Event::trigger('system.logActivity', ['activity' => ['action' => 'approved', 'scope' => 'wiki.page.revision', 'scope_id' => $this->page->get('id'), 'description' => Lang::txt('COM_WIKI_ACTIVITY_REVISION_APPROVED', $revision->get('id'), '<a href="' . Route::url($this->page->link()) . '">' . $this->page->title . '</a>'), 'details' => array('title' => $this->page->title, 'url' => Route::url($this->page->link()), 'name' => $this->page->get('pagename'), 'revision' => $revision->get('id'))], 'recipients' => $recipients]); App::redirect(Route::url($this->page->link())); }
/** * Set the approval state for a revision * * @return void */ public function approveTask() { // Check for request forgeries Request::checkToken('get'); if (!User::authorise('core.edit.state', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming $id = Request::getInt('id', 0); if ($id) { // Load the revision, approve it, and save $version = Version::oneOrFail($id); $version->set('approved', Request::getInt('approve', 0)); if (!$version->save()) { Notify::error($version->getError()); } } $this->cancelTask(); }