/** * Save page. * * @param string $slug */ public function saveAction($slug) { $this->page->set($this->pageParams()); if (Request::$post->get('content') != $this->page->revision()->content) { $revision = new WikiRevision(['wiki_page_id' => $this->page->id, 'revision' => $this->page->revision()->revision + 1, 'content' => Request::$post->get('content'), 'user_id' => $this->currentUser['id']]); } if ($this->page->save()) { if (isset($revision)) { $revision->save(); $this->page->revision_id = $revision->id; } $this->page->save(); return $this->redirectTo('wiki_page', ['slug' => $this->page['slug']]); } else { return $this->render('wiki/edit.phtml'); } }
public function delete() { static::connection()->delete(static::tableName(), ['id' => $this->id]); static::connection()->delete(WikiRevision::tableName(), ['wiki_page_id' => $this->id]); }
/** * Save wiki page. */ public function saveAction() { $this->addCrumb($this->translate('edit_page'), $this->generateUrl('wiki_edit')); $revision = new WikiRevision($this->revisionParams() + ['wiki_page_id' => $this->page['id'], 'revision' => $this->page->revision()['revision'] + 1]); $this->page->set($this->pageParams()); // Validate page and revision $this->page->validate(); $revision->validate(); if (!$this->page->hasErrors() && !$revision->hasErrors()) { // Check if the content is different and create the revision if it is if ($revision['content'] !== $this->page->revision()['content']) { $revision->save(); $this->page['revision_id'] = $revision['id']; } $this->page->save(); return $this->redirectTo('wiki_page', ['slug' => $this->page['slug']]); } return $this->render('wiki/edit.phtml', ['page' => $this->page, 'revision' => $revision]); }
function createWikiPage($project = null, $user = null) { if (!$project) { $project = createProject(); } if (!$user) { $user = createUser(); } $prefix = 'wikipage-' . mkRandomHash(5); $page = new WikiPage(['title' => $prefix . '-title', 'slug' => $prefix . '-slug', 'project_id' => $project['id']]); $revision = new WikiRevision(['content' => $prefix . '-content', 'user_id' => $user['id']]); $page->save(); $revision['wiki_page_id'] = $page['id']; $revision->save(); $page['revision_id'] = $revision['id']; $page->save(); return $page; }