Skip to content

Commit acd9400

Browse files
committed
API Update API to reflect changes to CLI interaction
1 parent 4b8f758 commit acd9400

6 files changed

+38
-66
lines changed

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ composer require silverstripe/contentreview
3939
composer require silverstripe/contentreview
4040
```
4141

42-
You'll also need to run `dev/build`.
43-
44-
Run dev/build either via the web server by opening the URL `http://<your-host>/dev/build?flush` or
45-
by running the dev/build via a CLI: `sake dev/build flush=1`
42+
You'll also need to build the database either via the web server by opening the URL `http://<your-host>/dev/build?flush` or via a CLI: `sake db:build --flush`
4643

4744
## Documentation
4845

docs/en/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The module is set up in the `Settings` section of the CMS, see the [User guide](
1111
In order for the contentreview module to send emails, you need to *either*:
1212

1313
* Setup the `ContentReviewEmails` script to run daily via a system cron job.
14-
* Install the [queuedjobs](https://github.com/symbiote/silverstripe-queuedjobs) module and follow the configuration steps to create a cron job for that module. Once installed, you can just run `dev/build` to have a job created, which will run at 9am every day by default.
14+
* Install the [queuedjobs](https://github.com/symbiote/silverstripe-queuedjobs) module and follow the configuration steps to create a cron job for that module. Once installed, you can just run `sake db:build` to have a job created, which will run at 9am every day by default.
1515

1616
## Using
1717

src/Jobs/ContentReviewNotificationJob.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
use SilverStripe\ContentReview\Tasks\ContentReviewEmails;
66
use SilverStripe\Control\HTTPRequest;
77
use SilverStripe\Core\Config\Config;
8+
use SilverStripe\PolyExecution\PolyOutput;
89
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
910
use Symbiote\QueuedJobs\Services\QueuedJob;
1011
use Symbiote\QueuedJobs\Services\QueuedJobService;
12+
use Symfony\Component\Console\Input\ArrayInput;
1113

1214
if (!class_exists(AbstractQueuedJob::class)) {
1315
return;
@@ -94,7 +96,10 @@ public function process()
9496
$this->queueNextRun();
9597

9698
$task = ContentReviewEmails::create();
97-
$task->run(new HTTPRequest("GET", "/dev/tasks/ContentReviewEmails"));
99+
$output = PolyOutput::create(PolyOutput::FORMAT_ANSI);
100+
$input = new ArrayInput([]);
101+
$input->setInteractive(false);
102+
$task->run($input, $output);
98103

99104
$this->currentStep = 1;
100105
$this->isComplete = true;

src/Tasks/ContentReviewEmails.php

+17-11
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
namespace SilverStripe\ContentReview\Tasks;
44

55
use Page;
6-
use RuntimeException;
76
use SilverStripe\ContentReview\Compatibility\ContentReviewCompatability;
87
use SilverStripe\Control\Email\Email;
9-
use SilverStripe\Control\HTTPRequest;
108
use SilverStripe\Dev\BuildTask;
9+
use SilverStripe\PolyExecution\PolyOutput;
1110
use SilverStripe\Model\List\ArrayList;
1211
use SilverStripe\ORM\FieldType\DBDatetime;
1312
use SilverStripe\ORM\FieldType\DBField;
@@ -16,6 +15,8 @@
1615
use SilverStripe\SiteConfig\SiteConfig;
1716
use SilverStripe\Model\ArrayData;
1817
use SilverStripe\View\SSViewer;
18+
use Symfony\Component\Console\Command\Command;
19+
use Symfony\Component\Console\Input\InputInterface;
1920

2021
/**
2122
* Daily task to send emails to the owners of content items when the review date rolls around.
@@ -24,19 +25,21 @@ class ContentReviewEmails extends BuildTask
2425
{
2526
private array $invalid_emails = [];
2627

27-
/**
28-
* @param HTTPRequest $request
29-
* @throws RuntimeException
30-
*/
31-
public function run($request)
28+
protected static string $commandName = 'content-review-emails';
29+
30+
protected static string $description = 'Daily task to send emails to the owners of content items when the review'
31+
. ' date rolls around';
32+
33+
protected function execute(InputInterface $input, PolyOutput $output): int
3234
{
3335
if (!$this->isValidEmail($senderEmail = SiteConfig::current_site_config()->ReviewFrom)) {
34-
throw new RuntimeException(
36+
$output->writeln(
3537
sprintf(
36-
'Provided sender email address is invalid: "%s".',
38+
'<error>Provided sender email address is invalid: "%s".</>',
3739
$senderEmail
3840
)
3941
);
42+
return Command::FAILURE;
4043
}
4144

4245
$compatibility = ContentReviewCompatability::start();
@@ -57,13 +60,16 @@ public function run($request)
5760

5861
if (is_array($this->invalid_emails) && count($this->invalid_emails) > 0) {
5962
$plural = count($this->invalid_emails) > 1 ? 's are' : ' is';
60-
throw new RuntimeException(
63+
$output->writeln(
6164
sprintf(
62-
'Provided email' . $plural . ' invalid: "%s".',
65+
'<error>Provided email' . $plural . ' invalid: "%s".</>',
6366
implode(', ', $this->invalid_emails)
6467
)
6568
);
69+
return Command::FAILURE;
6670
}
71+
72+
return Command::SUCCESS;
6773
}
6874

6975
/**

src/Tasks/ContentReviewOwnerMigrationTask.php

-47
This file was deleted.

tests/php/ContentReviewNotificationTest.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use SilverStripe\Security\Member;
1919
use SilverStripe\SiteConfig\SiteConfig;
2020
use SilverStripe\ContentReview\Models\ContentReviewLog;
21+
use SilverStripe\PolyExecution\PolyOutput;
22+
use Symfony\Component\Console\Input\ArrayInput;
23+
use Symfony\Component\Console\Output\BufferedOutput;
2124

2225
class ContentReviewNotificationTest extends SapphireTest
2326
{
@@ -58,7 +61,11 @@ public function testContentReviewEmails()
5861
$childParentPage->write();
5962

6063
$task = new ContentReviewEmails();
61-
$task->run(new HTTPRequest('GET', '/dev/tasks/ContentReviewEmails'));
64+
$buffer = new BufferedOutput();
65+
$output = new PolyOutput(PolyOutput::FORMAT_ANSI, wrappedOutput: $buffer);
66+
$input = new ArrayInput([]);
67+
$input->setInteractive(false);
68+
$task->run($input, $output);
6269

6370
// Set template variables (as per variable case)
6471
$ToEmail = 'author@example.com';
@@ -124,7 +131,11 @@ public function testContentReviewNeeded()
124131
$this->assertCount(1, $childParentPage->ReviewLogs());
125132

126133
$task = new ContentReviewEmails();
127-
$task->run(new HTTPRequest('GET', '/dev/tasks/ContentReviewEmails'));
134+
$buffer = new BufferedOutput();
135+
$output = new PolyOutput(PolyOutput::FORMAT_ANSI, wrappedOutput: $buffer);
136+
$input = new ArrayInput([]);
137+
$input->setInteractive(false);
138+
$task->run($input, $output);
128139

129140
// Expecting to not send the email as content review for page is done
130141
$email = $this->findEmail($member->Email);

0 commit comments

Comments
 (0)