Skip to content

Commit 1f997f1

Browse files
Chris Pennychrispenny
authored andcommitted
Bugfix: Check Job class and regenerate if mismatched
1 parent ed86d20 commit 1f997f1

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

phpcs.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<!-- Class length does not equal complexity. We absolutely don't care about class length -->
3535
<exclude name="SlevomatCodingStandard.Classes.ClassLength.ClassTooLong"/>
3636
<exclude name="SlevomatCodingStandard.Files.FileLength.FileTooLong"/>
37+
<!-- We'll be the ones to decide "complexity", not PHPCS -->
38+
<exclude name="SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh"/>
3739
<!-- Don't force the use of early exit. We do try to use it though, and you might get PR feedback where -->
3840
<!-- early exit is appropriate -->
3941
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>

src/Extension/EmbargoExpiryExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ public function createOrUpdatePublishJob(int $desiredPublishTime): void
525525
if ($job !== null
526526
&& $job->exists()
527527
&& DBDatetime::create()->setValue($job->StartAfter)->getTimestamp() === $desiredPublishTime
528+
// This check is (mostly) to support migrations from Workflow to E&E. If we previously had a Workflow job,
529+
// we would want to clear and update this to an E&E job
530+
&& $job->Implementation === PublishTargetJob::class
528531
) {
529532
// Make sure our PublishOnDate is up to date.
530533
$this->updatePublishOnDate();
@@ -579,6 +582,9 @@ public function createOrUpdateUnPublishJob(int $desiredUnPublishTime): void
579582
if ($job !== null
580583
&& $job->exists()
581584
&& DBDatetime::create()->setValue($job->StartAfter)->getTimestamp() === $desiredUnPublishTime
585+
// This check is (mostly) to support migrations from Workflow to E&E. If we previously had a Workflow job,
586+
// we would want to clear and update this to an E&E job
587+
&& $job->Implementation === UnPublishTargetJob::class
582588
) {
583589
// Make sure our UnPublishOnDate is up to date.
584590
$this->updateUnPublishOnDate();

tests/Extension/EmbargoExpiryExtensionTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use DateTimeImmutable;
66
use Exception;
7+
use Page;
78
use SilverStripe\CMS\Model\SiteTree;
89
use SilverStripe\Core\Config\Config;
910
use SilverStripe\Dev\SapphireTest;
@@ -143,6 +144,39 @@ public function testIsNotEditableWithEmbargo(): void
143144
$this->assertFalse($page->isEditable());
144145
}
145146

147+
public function testCreateOrUpdateJobMethods(): void
148+
{
149+
$embargo = '2014-02-05 12:00:00';
150+
$expiry = '2014-02-07 12:00:00';
151+
152+
/** @var Page|EmbargoExpiryExtension $page */
153+
$page = Page::create();
154+
$page->Title = 'Test Page';
155+
// This won't yet generate Jobs, as the Page first needs to exist
156+
$page->write();
157+
// Now we can set our dates
158+
$page->DesiredPublishDate = $embargo;
159+
$page->DesiredUnPublishDate = $expiry;
160+
// This should generate Jobs for the two dates above
161+
$page->write();
162+
163+
$this->assertNotNull($page->PublishJob());
164+
$this->assertTrue($page->PublishJob()->exists());
165+
$this->assertNotNull($page->UnPublishJob());
166+
$this->assertTrue($page->UnPublishJob()->exists());
167+
168+
// Save away the Job IDs for comparison later
169+
$publishJobId = $page->PublishJobID;
170+
$unPublishJobId = $page->UnPublishJobID;
171+
172+
// This should NOT generate any new Jobs, they should remain exactly the same
173+
$page->createOrUpdatePublishJob(strtotime($embargo));
174+
$page->createOrUpdateUnPublishJob(strtotime($expiry));
175+
176+
$this->assertEquals($publishJobId, $page->PublishJobID);
177+
$this->assertEquals($unPublishJobId, $page->UnPublishJobID);
178+
}
179+
146180
/**
147181
* @throws ValidationException
148182
* @throws Exception

0 commit comments

Comments
 (0)