public function boot() { parent::boot(); Models\Asset::observe(CreationLogObserver::class); Models\AssetVersion::observe(CreationLogObserver::class); Models\Page::observe(CreationLogObserver::class); Models\PageVersion::observe(CreationLogObserver::class); Models\Asset::observe(SetSiteObserver::class); Models\Group::observe(SetSiteObserver::class); Models\Page::observe(SetSiteObserver::class); Models\Tag::observe(SetSiteObserver::class); Models\URL::observe(SetSiteObserver::class); Models\Page::observe(DeletionLogObserver::class); }
/** * 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; }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('page_versions', function (Blueprint $table) { $table->string(PageVersion::ATTR_CHUNK_TYPE, 15); $table->integer(PageVersion::ATTR_CHUNK_ID)->unsigned(); }); $versions = PageVersion::where(PageVersion::ATTR_EMBARGOED_UNTIL, null)->get(); $types = ['text', 'feature', 'asset', 'slideshow', 'linkset', 'link', 'location', 'timestamp', 'html', 'calendar', 'library']; foreach ($versions as $version) { foreach ($types as $type) { $className = 'BoomCMS\\Database\\Models\\Chunk\\' . ucfirst($type); $count = (new $className())->where('page_vid', $version->getId())->count(); if ($count === 1) { $chunk = (new $className())->where('page_vid', $version->getId())->first(); $version->{PageVersion::ATTR_CHUNK_TYPE} = $type; $version->{PageVersion::ATTR_CHUNK_ID} = $chunk->id; $version->save(); break; } } } }
/** * Returns the last published version for the page. * * @return PageVersionInterface */ public function getLastPublished() { return PageVersion::forPage($this)->lastPublished()->first(); }
public function getLastPublishedTime() { $m = PageVersion::forPage($this)->lastPublished()->first(); return (new DateTime())->setTimestamp($m['embargoed_until']); }
public function testPendingApproval() { $version = new Version(['pending_approval' => true]); $this->assertTrue($version->isPendingApproval()); }