/** * Save a revision * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming $revision = Request::getVar('revision', array(), 'post', 'none', 2); $revision = array_map('trim', $revision); // Initiate extended database class $version = Version::oneOrNew($revision['id']); // Get the "approved" state before binding incoming data $before = $version->get('approved'); // Bind data $version->set($revision); // Get the parent page $page = Page::oneOrFail(intval($version->get('page_id'))); // Parse text $parser = Parser::getInstance(); $version->set('pagehtml', $parser->parse($version->get('pagetext'), array('option' => $this->_option, 'scope' => $page->get('scope'), 'scope_id' => $page->get('scope_id'), 'path' => $page->get('path'), 'pagename' => $page->get('pagename'), 'pageid' => $page->get('id'), 'filepath' => ''))); // Store new content if (!$version->save()) { Notify::error($version->getError()); return $this->editTask($version); } // Get the most recent revision and compare to the set "current" version if ($before != 1 && $version->get('approved') == 1) { $current = $page->versions()->whereEquals('approved', 1)->ordered()->row(); if ($current->get('id') == $version->get('id')) { // The newly approved revision is now the most current // So, we need to update the page's version_id $page->set('version_id', $version->get('id')); $page->save(); } $page->log('revision_approved'); } // Set the success message Notify::success(Lang::txt('COM_WIKI_REVISION_SAVED')); // Fall through to the edit form if ($this->getTask() == 'apply') { return $this->editTask($version); } // Redirect to listing App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $version->get('page_id'), false)); }