diff --git a/_config/model.yml b/_config/model.yml new file mode 100644 index 0000000..dce46c0 --- /dev/null +++ b/_config/model.yml @@ -0,0 +1,6 @@ +--- +Name: embargoexpirymodel +--- +SilverStripe\ORM\DataObject: + allow_embargoed_editing: true + enforce_sequential_dates: false diff --git a/src/Extension/EmbargoExpiryCMSMainExtension.php b/src/Extension/EmbargoExpiryCMSMainExtension.php index 078d8ec..6284f5b 100644 --- a/src/Extension/EmbargoExpiryCMSMainExtension.php +++ b/src/Extension/EmbargoExpiryCMSMainExtension.php @@ -7,10 +7,19 @@ use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Core\Extension; use SilverStripe\Forms\Form; +use SilverStripe\ORM\DataObject; use Symfony\Component\Finder\Exception\AccessDeniedException; +/** + * Class EmbargoExpiryCMSMainExtension + * + * @package Terraformers\EmbargoExpiry\Extension + */ class EmbargoExpiryCMSMainExtension extends Extension { + /** + * @var array + */ private static $allowed_actions = array( 'removeEmbargoAction', 'removeExpiryAction', @@ -42,10 +51,7 @@ public function updateEditForm($form) */ public function removeEmbargoAction($data, $form) { - // Find the record. - $id = $data['ID']; - - $this->removeEmbargoOrExpiry($id, 'PublishOnDate'); + $this->removeEmbargoOrExpiry($data['ClassName'], $data['ID'], 'PublishOnDate', 'PublishJobID'); $this->owner->getResponse()->addHeader( 'X-Status', @@ -66,10 +72,7 @@ public function removeEmbargoAction($data, $form) */ public function removeExpiryAction($data, $form) { - // Find the record. - $id = $data['ID']; - - $this->removeEmbargoOrExpiry($id, 'UnPublishOnDate'); + $this->removeEmbargoOrExpiry($data['ClassName'], $data['ID'], 'UnPublishOnDate', 'UnPublishJobID'); $this->owner->getResponse()->addHeader( 'X-Status', @@ -80,14 +83,15 @@ public function removeExpiryAction($data, $form) } /** - * @param $id - * @param $field + * @param string $className + * @param string $id + * @param string $field * @throws HTTPResponse_Exception */ - protected function removeEmbargoOrExpiry($id, $field) + protected function removeEmbargoOrExpiry($className, $id, $dateField, $jobField) { - /** @var SiteTree|EmbargoExpiryExtension $record */ - $record = SiteTree::get()->byID($id); + /** @var DataObject|EmbargoExpiryExtension $record */ + $record = DataObject::get($className)->byID($id); if (!$record || !$record->exists()) { throw new HTTPResponse_Exception("Bad record ID #$id", 404); } @@ -97,7 +101,8 @@ protected function removeEmbargoOrExpiry($id, $field) } // Writing the record with no embargo set will automatically remove the queued jobs. - $record->$field = null; + $record->$dateField = null; + $record->$jobField = 0; $record->write(); } diff --git a/src/Extension/EmbargoExpiryExtension.php b/src/Extension/EmbargoExpiryExtension.php index 27fa5ab..9abdf15 100644 --- a/src/Extension/EmbargoExpiryExtension.php +++ b/src/Extension/EmbargoExpiryExtension.php @@ -2,6 +2,7 @@ namespace Terraformers\EmbargoExpiry\Extension; +use Exception; use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\DatetimeField; @@ -60,21 +61,6 @@ class EmbargoExpiryExtension extends DataExtension implements PermissionProvider */ public $isPublishJobRunning = false; - /** - * Config variable to decide whether or not pages can be edited while they are embargoed. - * - * @var bool - */ - public static $allow_embargoed_editing = false; - - /** - * Config variable that you can set to true if you want to always enforce that publish dates are before unpublish - * dates. - * - * @var bool - */ - public static $enforce_sequential_dates = false; - /** * @param FieldList $fields */ @@ -537,6 +523,8 @@ public function isEditable() */ public function addPublishingScheduleFields(FieldList $fields) { + $message = $this->getEmbargoExpiryFieldNoticeMessage(); + $fields->findOrMakeTab( 'Root.PublishingSchedule', _t(__CLASS__ . '.TAB_TITLE', 'Publishing Schedule') @@ -561,12 +549,12 @@ public function addPublishingScheduleFields(FieldList $fields) ] ); - if (($message = $this->getEmbargoExpiryFieldNoticeMessage()) !== null) { + if ($message !== null) { $fields->addFieldToTab( 'Root.PublishingSchedule', LiteralField::create( 'PublishDateIntro', - "