Skip to content

Commit

Permalink
API Update API to reflect changes to CLI interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Sep 18, 2024
1 parent 4f164fc commit 90fe773
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 66 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ composer require silverstripe/contentreview
composer require silverstripe/contentreview
```

You'll also need to run `dev/build`.

Run dev/build either via the web server by opening the URL `http://<your-host>/dev/build?flush` or
by running the dev/build via a CLI: `sake dev/build flush=1`
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`

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The module is set up in the `Settings` section of the CMS, see the [User guide](
In order for the contentreview module to send emails, you need to *either*:

* Setup the `ContentReviewEmails` script to run daily via a system cron job.
* 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.
* 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.

## Using

Expand Down
7 changes: 6 additions & 1 deletion src/Jobs/ContentReviewNotificationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use SilverStripe\ContentReview\Tasks\ContentReviewEmails;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Config\Config;
use SilverStripe\PolyExecution\PolyOutput;
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJobService;
use Symfony\Component\Console\Input\ArrayInput;

if (!class_exists(AbstractQueuedJob::class)) {
return;
Expand Down Expand Up @@ -94,7 +96,10 @@ public function process()
$this->queueNextRun();

$task = ContentReviewEmails::create();
$task->run(new HTTPRequest("GET", "/dev/tasks/ContentReviewEmails"));
$output = PolyOutput::create(PolyOutput::FORMAT_ANSI);
$input = new ArrayInput([]);
$input->setInteractive(false);
$task->run($input, $output);

$this->currentStep = 1;
$this->isComplete = true;
Expand Down
28 changes: 17 additions & 11 deletions src/Tasks/ContentReviewEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace SilverStripe\ContentReview\Tasks;

use Page;
use RuntimeException;
use SilverStripe\ContentReview\Compatibility\ContentReviewCompatability;
use SilverStripe\Control\Email\Email;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\BuildTask;
use SilverStripe\PolyExecution\PolyOutput;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBField;
Expand All @@ -16,6 +15,8 @@
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;

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

/**
* @param HTTPRequest $request
* @throws RuntimeException
*/
public function run($request)
protected static string $commandName = 'content-review-emails';

protected static string $description = 'Daily task to send emails to the owners of content items when the review'
. ' date rolls around';

protected function execute(InputInterface $input, PolyOutput $output): int
{
if (!$this->isValidEmail($senderEmail = SiteConfig::current_site_config()->ReviewFrom)) {
throw new RuntimeException(
$output->writeln(
sprintf(
'Provided sender email address is invalid: "%s".',
'<error>Provided sender email address is invalid: "%s".</>',
$senderEmail
)
);
return Command::FAILURE;
}

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

if (is_array($this->invalid_emails) && count($this->invalid_emails) > 0) {
$plural = count($this->invalid_emails) > 1 ? 's are' : ' is';
throw new RuntimeException(
$output->writeln(
sprintf(
'Provided email' . $plural . ' invalid: "%s".',
'<error>Provided email' . $plural . ' invalid: "%s".</>',
implode(', ', $this->invalid_emails)
)
);
return Command::FAILURE;
}

return Command::SUCCESS;
}

/**
Expand Down
47 changes: 0 additions & 47 deletions src/Tasks/ContentReviewOwnerMigrationTask.php

This file was deleted.

15 changes: 13 additions & 2 deletions tests/php/ContentReviewNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use SilverStripe\Security\Member;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\ContentReview\Models\ContentReviewLog;
use SilverStripe\PolyExecution\PolyOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;

class ContentReviewNotificationTest extends SapphireTest
{
Expand Down Expand Up @@ -58,7 +61,11 @@ public function testContentReviewEmails()
$childParentPage->write();

$task = new ContentReviewEmails();
$task->run(new HTTPRequest('GET', '/dev/tasks/ContentReviewEmails'));
$buffer = new BufferedOutput();
$output = new PolyOutput(PolyOutput::FORMAT_ANSI, wrappedOutput: $buffer);
$input = new ArrayInput([]);
$input->setInteractive(false);
$task->run($input, $output);

// Set template variables (as per variable case)
$ToEmail = '[email protected]';
Expand Down Expand Up @@ -124,7 +131,11 @@ public function testContentReviewNeeded()
$this->assertCount(1, $childParentPage->ReviewLogs());

$task = new ContentReviewEmails();
$task->run(new HTTPRequest('GET', '/dev/tasks/ContentReviewEmails'));
$buffer = new BufferedOutput();
$output = new PolyOutput(PolyOutput::FORMAT_ANSI, wrappedOutput: $buffer);
$input = new ArrayInput([]);
$input->setInteractive(false);
$task->run($input, $output);

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

0 comments on commit 90fe773

Please sign in to comment.