Skip to content

Commit

Permalink
Merge pull request #110 from silverstripe-terraformers/feature/silver…
Browse files Browse the repository at this point in the history
…stripe-5

Update dependencies for Silverstripe 5. Update webpack build and dependencies
  • Loading branch information
MelissaWu-SS authored Feb 26, 2023
2 parents 19c30f7 + 89200fa commit 0ad2819
Show file tree
Hide file tree
Showing 15 changed files with 4,378 additions and 6,711 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ on:
jobs:
ci:
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
with:
js: false
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
18
15 changes: 0 additions & 15 deletions .scrutinizer.yml

This file was deleted.

2 changes: 1 addition & 1 deletion client/dist/js/embargo-expiry.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"license": "BSD-3-Clause",
"authors": [
{
"name": "SilverStripe Ltd"
"name": "Chris Penny",
"email": "chris.penny@gmail.com"
},
{
"name": "Silverstripe Terraformers",
Expand All @@ -19,17 +20,15 @@
"issues": "https://github.com/silverstripe-terraformers/embargo-expiry/issues"
},
"require": {
"php": "^7.4 || ^8.0",
"silverstripe/vendor-plugin": "^1.6",
"silverstripe/framework": "^4.7",
"silverstripe/cms": "^4.7",
"symbiote/silverstripe-queuedjobs": "^4.1",
"php": "^8",
"silverstripe/cms": "^5",
"symbiote/silverstripe-queuedjobs": "^5",
"opis/closure": "^3.6"
},
"require-dev": {
"silverstripe/recipe-testing": "^2",
"tractorcow/silverstripe-fluent": "^6.0",
"slevomat/coding-standard": "^8.0"
"silverstripe/recipe-testing": "^3",
"tractorcow/silverstripe-fluent": "^7",
"slevomat/coding-standard": "~8.0.0"
},
"extra": {
"expose": [
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "1.0.0",
"description": "Embargo & expiry module for SilverStrip CMS",
"engines": {
"node": "^10.x"
"node": "^18"
},
"scripts": {
"build": "NODE_ENV=production webpack -p --bail --progress",
"build": "NODE_ENV=production webpack --bail --progress",
"watch": "NODE_ENV=development webpack --watch --progress",
"css": "WEBPACK_CHILD=css npm run build",
"lint": "eslint client/src"
Expand All @@ -30,10 +30,12 @@
},
"homepage": "https://github.com/silverstripe-terraformers/silverstripe-embargo-expiry",
"devDependencies": {
"@silverstripe/eslint-config": "0.0.5",
"@silverstripe/webpack-config": "^0.11.0"
"@silverstripe/eslint-config": "^1.0.0-alpha6",
"@silverstripe/webpack-config": "^2.0.0-alpha9",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
},
"dependencies": {
"jquery": "^3.5.0"
"jquery": "^3.6.3"
}
}
5 changes: 5 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<file>src</file>
<file>tests</file>

<!-- Show progress and output sniff names on violation, and add colours -->
<arg value="p" />
<arg name="colors" />
<arg value="s" />

<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
Expand Down
101 changes: 11 additions & 90 deletions src/Extension/EmbargoExpiryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Services\QueuedJobService;
use Terraformers\EmbargoExpiry\Job\PublishTargetJob;
use Terraformers\EmbargoExpiry\Job\State\ActionProcessingState;
use Terraformers\EmbargoExpiry\Job\UnPublishTargetJob;

/**
Expand Down Expand Up @@ -312,7 +313,7 @@ public function unlinkUnPublishJobAndDate(): void
public function clearPublishJob(): void
{
// Can't clear a job while it's in the process of being completed.
if ($this->owner->getIsPublishJobRunning()) {
if (ActionProcessingState::singleton()->getActionIsProcessing()) {
return;
}

Expand All @@ -332,7 +333,7 @@ public function clearPublishJob(): void
public function clearUnPublishJob(): void
{
// Can't clear a job while it's in the process of being completed.
if ($this->owner->getIsUnPublishJobRunning()) {
if (ActionProcessingState::singleton()->getActionIsProcessing()) {
return;
}

Expand Down Expand Up @@ -384,7 +385,7 @@ public function getUnPublishOnDateAsTimestamp(): int
public function ensurePublishJob(): void
{
// Can't clear a job while it's in the process of being completed.
if ($this->owner->getIsPublishJobRunning()) {
if (ActionProcessingState::singleton()->getActionIsProcessing()) {
return;
}

Expand Down Expand Up @@ -417,7 +418,7 @@ public function ensurePublishJob(): void
public function ensureUnPublishJob(): void
{
// Can't clear a job while it's in the process of being completed.
if ($this->owner->getIsUnPublishJobRunning()) {
if (ActionProcessingState::singleton()->getActionIsProcessing()) {
return;
}

Expand Down Expand Up @@ -567,9 +568,6 @@ public function createOrUpdatePublishJob(int $desiredPublishTime): void
$this->updatePublishOnDate($updateTime);
}

/**
* @param int $desiredUnPublishTime
*/
public function createOrUpdateUnPublishJob(int $desiredUnPublishTime): void
{
$now = DBDatetime::now()->getTimestamp();
Expand Down Expand Up @@ -625,8 +623,6 @@ public function createOrUpdateUnPublishJob(int $desiredUnPublishTime): void

/**
* Returns whether a publishing date has been set and is after the current date
*
* @return bool
*/
public function getIsPublishScheduled(): bool
{
Expand All @@ -646,8 +642,6 @@ public function getIsPublishScheduled(): bool

/**
* Returns whether an unpublishing date has been set and is after the current date
*
* @return bool
*/
public function getIsUnPublishScheduled(): bool
{
Expand All @@ -662,24 +656,17 @@ public function getIsUnPublishScheduled(): bool
}

/**
* Default logic for whether or not the DataObject is editable. Feel free to override this method on your DataObject
* if you need to change the logic.
*
* @return bool
* Default logic for whether the DataObject is editable. Feel free to override this method on your DataObject if
* you need to change the logic.
*/
public function isEditable(): ?bool
{
// Need to be able to save the DataObject if this is being called during PublishTargetJob.
if ($this->owner->getIsPublishJobRunning()) {
return true;
}

// Need to be able to save the DataObject if this is being called during UnPublishTargetJob.
if ($this->owner->getIsUnPublishJobRunning()) {
// Need to be able to save the DataObject if this is being called during either of our Jobs.
if (ActionProcessingState::singleton()->getActionIsProcessing()) {
return true;
}

// If the owner object allows embargoed editing, then return null so we can fall back to SiteTree behaviours
// If the owner object allows embargoed editing, then return null, so we can fall back to SiteTree behaviours
// (SiteTree and inherited permissions)
if ($this->owner->config()->get('allow_embargoed_editing')) {
return null;
Expand All @@ -699,9 +686,6 @@ public function isEditable(): ?bool
return null;
}

/**
* @param FieldList $fields
*/
public function addDesiredDateFields(FieldList $fields): void
{
$fields->findOrMakeTab(
Expand Down Expand Up @@ -751,9 +735,6 @@ public function addDesiredDateFields(FieldList $fields): void
$unPublishDateField->setReadonly(true);
}

/**
* @param FieldList $fields
*/
public function addScheduledDateFields(FieldList $fields): void
{
if (!$this->getIsPublishScheduled() && !$this->getIsUnPublishScheduled()) {
Expand Down Expand Up @@ -811,9 +792,6 @@ public function getEmbargoExpiryFieldNoticeMessage(): ?string
);
}

/**
* @param FieldList $fields
*/
public function addNoticeOrWarningFields(FieldList $fields): void
{
$conditions = $this->getEmbargoExpiryNoticeFieldConditions();
Expand Down Expand Up @@ -853,9 +831,6 @@ public function addNoticeOrWarningFields(FieldList $fields): void
);
}

/**
* @return array
*/
public function getEmbargoExpiryNoticeFieldConditions(): array
{
$conditions = [];
Expand Down Expand Up @@ -884,11 +859,7 @@ public function getEmbargoExpiryNoticeFieldConditions(): array
return $conditions;
}

/**
* @param array $conditions
* @return string
*/
public function getEmbargoExpiryNoticeMessage(array $conditions): ?string
private function getEmbargoExpiryNoticeMessage(array $conditions): ?string
{
if (count($conditions) === 0) {
return null;
Expand Down Expand Up @@ -937,45 +908,6 @@ public function getEmbargoExpiryNoticeMessage(array $conditions): ?string
);
}

/**
* Method to decide whether or not this Object is being accessed while a PublishTargetJob is running.
*
* @return bool
*/
public function getIsPublishJobRunning(): bool
{
return $this->isPublishJobRunning;
}

/**
* @param bool $bool
*/
public function setIsPublishJobRunning(bool $bool): void
{
$this->isPublishJobRunning = $bool;
}

/**
* Method to decide whether or not this Object is being accessed while a PublishTargetJob is running.
*
* @return bool
*/
public function getIsUnPublishJobRunning(): bool
{
return $this->isUnPublishJobRunning;
}

/**
* @param $bool
*/
public function setIsUnPublishJobRunning(bool $bool): void
{
$this->isUnPublishJobRunning = $bool;
}

/**
* @param string|null $desiredPublishTime
*/
private function updatePublishOnDate(?string $desiredPublishTime = null): void
{
if ($desiredPublishTime === null) {
Expand All @@ -988,9 +920,6 @@ private function updatePublishOnDate(?string $desiredPublishTime = null): void
$this->owner->DesiredPublishDate = null;
}

/**
* @param string|null $desiredUnPublishTime
*/
private function updateUnPublishOnDate(?string $desiredUnPublishTime = null): void
{
if ($desiredUnPublishTime === null) {
Expand All @@ -1009,8 +938,6 @@ private function updateUnPublishOnDate(?string $desiredUnPublishTime = null): vo
*
* The purpose of this method is to allow you a chance to modify your DataObject in any way you may need to prior
* to it being published. You have access to any $options that you set as part of the PublishTargetJob.
*
* @param array|null $options
*/
public function prePublishTargetJob(?array $options): void
{
Expand All @@ -1023,8 +950,6 @@ public function prePublishTargetJob(?array $options): void
*
* The purpose of this method is to allow you a chance to modify your DataObject in any way you may need to prior
* to it being unpublished. You have access to any $options that you set as part of the PublishTargetJob.
*
* @param array|null $options
*/
public function preUnPublishTargetJob(?array $options): void
{
Expand All @@ -1034,8 +959,6 @@ public function preUnPublishTargetJob(?array $options): void
/**
* A method that can be implemented on your DataObject. This method is run with invokeWithExtensions prior to
* creation of the PublishTargetJob.
*
* @param array|null $options
*/
public function updatePublishTargetJobOptions(?array &$options): void
{
Expand All @@ -1045,8 +968,6 @@ public function updatePublishTargetJobOptions(?array &$options): void
/**
* A method that can be implemented on your DataObject. This method is run with invokeWithExtensions prior to
* creation of the PublishTargetJob.
*
* @param array|null $options
*/
public function updateUnPublishTargetJobOptions(?array &$options): void
{
Expand Down
2 changes: 0 additions & 2 deletions src/Extension/EmbargoExpiryGridFieldItemRequestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ public function removeEmbargoOrExpiry(string $dateField): void
$record->clearPublishJob();

break;

case 'UnPublishOnDate':
$record->clearUnPublishJob();

break;

default:
throw new Exception('Invalid action submitted');
}
Expand Down
5 changes: 3 additions & 2 deletions src/Job/PublishTargetJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SilverStripe\Versioned\Versioned;
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use Terraformers\EmbargoExpiry\Extension\EmbargoExpiryExtension;
use Terraformers\EmbargoExpiry\Job\State\ActionProcessingState;

/**
* @property array $options
Expand Down Expand Up @@ -78,7 +79,7 @@ public function process(): void
return;
}

$target->setIsPublishJobRunning(true);
ActionProcessingState::singleton()->setActionIsProcessing(true);

// Make sure to use local variables for passing by reference as these are job properties
// which are manipulated via magic methods and these do not work with passing by reference directly
Expand All @@ -97,7 +98,7 @@ public function process(): void
$target->invokeWithExtensions('afterPublishTargetJob', $options);
$this->options = $options;

$target->setIsPublishJobRunning(false);
ActionProcessingState::singleton()->setActionIsProcessing(false);
$this->completeJob();
}

Expand Down
Loading

0 comments on commit 0ad2819

Please sign in to comment.