public function handle(PageSearchSettingsWereUpdated $event) { $page = $event->getPage(); $version = $page->getCurrentVersion(); $standfirst = Chunk::find('text', 'standfirst', $version); $description = $page->getDescription(); $description = $description == $standfirst ? '' : $description; SearchText::where('page_vid', '=', $version->getId())->update(['meta' => $page->getKeywords() . ' ' . $description]); }
public function handle(PageVersionEvent $event) { $page = $event->getPage(); $version = $event->getVersion(); $standfirst = Chunk::find('text', 'standfirst', $version); $bodycopy = Chunk::find('text', 'bodycopy', $version); $description = $page->getDescription(); $description = $description == $standfirst ? '' : $description; SearchText::create(['page_id' => $page->getId(), 'page_vid' => $version->getId(), 'embargoed_until' => $version->getEmbargoedUntil()->getTimestamp(), 'title' => $version->getTitle(), 'standfirst' => $standfirst ? $standfirst->text : '', 'text' => $bodycopy ? strip_tags($bodycopy->text) : '', 'meta' => $page->getKeywords() . ' ' . $description]); }
/** * Restore an older version of a page. * * Creates a new version based on the old one. * * @param Model $version * * @return Model */ public function restore(Model $version) { $attrs = $version->toArray(); $newVersion = new Model($attrs); $newVersion->setEditedAt(new DateTime('now'))->setEditedBy(Auth::user())->setRestoredFrom($version)->save(); $types = Chunk::since($version); foreach ($types as $type => $chunks) { $className = Chunk::getModelName($type); foreach ($chunks as $chunk) { $old = Chunk::find($type, $chunk->slotname, $version); $new = new $className(); $new->page_id = $newVersion->getPageId(); $new->slotname = $chunk->slotname; $new->page_vid = $newVersion->getId(); $new->save(); if ($old !== null) { $new->fill(array_except($old->toArray(), ['page_vid'])); $new->save(); } } } return $newVersion; }