Source of file PublishableSiteTree.php
Size: 2,940 Bytes - Last Modified: 2021-12-23T10:34:48+00:00
/var/www/docs.ssmods.com/process/src/src/Extension/Publishable/PublishableSiteTree.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 | <?php namespace SilverStripe\StaticPublishQueue\Extension\Publishable; use SilverStripe\CMS\Model\VirtualPage; use SilverStripe\Control\Director; use SilverStripe\ORM\DataExtension; use SilverStripe\StaticPublishQueue\Contract\StaticallyPublishable; use SilverStripe\StaticPublishQueue\Contract\StaticPublishingTrigger; /** * Bare-bones implementation of a publishable page. * * You can override this either by implementing one of the interfaces the class directly, or by applying * an extension via the config system ordering (inject your extension "before" the PublishableSiteTree). * * @TODO: re-implement optional publishing of all the ancestors up to the root? Currently it only republishes the parent * * @see SiteTreePublishingEngine */ class PublishableSiteTree extends DataExtension implements StaticallyPublishable, StaticPublishingTrigger { public function getMyVirtualPages() { return VirtualPage::get()->filter(['CopyContentFrom.ID' => $this->owner->ID]); } /** * @param array $context * @return array */ public function objectsToUpdate($context) { $list = []; switch ($context['action']) { case 'publish': // Trigger refresh of the page itself. $list[] = $this->getOwner(); // Refresh the parent. if ($this->getOwner()->ParentID) { $list[] = $this->getOwner()->Parent(); } // Refresh related virtual pages. $virtuals = $this->getOwner()->getMyVirtualPages(); if ($virtuals->exists()) { foreach ($virtuals as $virtual) { $list[] = $virtual; } } break; case 'unpublish': // Refresh the parent if ($this->getOwner()->ParentID) { $list[] = $this->getOwner()->Parent(); } break; } return $list; } /** * @param array $context * @return array */ public function objectsToDelete($context) { $list = []; switch ($context['action']) { case 'unpublish': // Trigger cache removal for this page. $list[] = $this->getOwner(); // Trigger removal of the related virtual pages. $virtuals = $this->getOwner()->getMyVirtualPages(); if ($virtuals->exists()) { foreach ($virtuals as $virtual) { $list[] = $virtual; } } break; } return $list; } /** * The only URL belonging to this object is it's own URL. */ public function urlsToCache() { return [Director::absoluteURL($this->getOwner()->Link()) => 0]; } } |