Problem/Motivation

Sitewide alerts could be set by Deploy pipelines (Jenkins, GHA...) if there were drush commands available.

As a site maintainer who deploys using Jenkins, I would like a drush command available so I can create a site alert shortly before deploy so that users may know downtime is coming.

As a site maintainer who deploys using Jenkins, I would like a drush command so I can delete a site alert after the deploy.

sitewide-alert:create (with flags for start and end times)
sitewide-alert:delete
sitewide-alert:disable
sitewide-alert:enable

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

swirt created an issue. See original summary.

swirt’s picture

Issue summary: View changes

tjh made their first commit to this issue’s fork.

chrissnyder’s picture

I like this idea!

Some initial questions/thoughts that come to mind on how we would implement this:

  • How would we know which alert to enable/disable/delete? Would we make the UUID of the alert be an argument?
  • Which entity fields/parameters would be available/required via the command line?
  • Which user would we add to these alert entities created by the drush command?
swirt’s picture

Good Questions @ChrisSnyder,
I think @tjh is already started on a solution ^^

>Which user would we add to these alert entities created by the drush command?

I think Drush runs as user 1. In the use case I am thinking of, there would be no problem with user 1, but there may be a case where it is worth having a User ID as an argument on the command.

> How would we know which alert to enable/disable/delete? Would we make the UUID of the alert be an argument?

In our use case, we need Jenkins to create an alert and then later delete it. under a different task, so it would have no idea what the UUID is of the first run. It would need to be more generic. like being able to delete by a label or title of some kind.

Which entity fields/parameters would be available/required via the command line?
At first glance, I would think all of the default fields would be available, and requiredness would reflect what is required in the UI.

chrissnyder’s picture

>Which user would we add to these alert entities created by the drush command?

I think Drush runs as user 1. In the use case I am thinking of, there would be no problem with user 1, but there may be a case where it is worth having a User ID as an argument on the command.

I agree. This would be an acceptable approach for the initial versions of these drush commands.

> How would we know which alert to enable/disable/delete? Would we make the UUID of the alert be an argument?

In our use case, we need Jenkins to create an alert and then later delete it. under a different task, so it would have no idea what the UUID is of the first run. It would need to be more generic. like being able to delete by a label or title of some kind.

Labels are not always unique, so that could cause unintended alerts to be enabled(active)/disabled/deleted. Maybe we provide several options/parameters to identify the alert that needs to be acted on. For example: by label, by uuid, and/or by alert author username/id?

> Which entity fields/parameters would be available/required via the command line?

At first glance, I would think all of the default fields would be available, and requiredness would reflect what is required in the UI.

In order to get something functional working, I am okay with limiting the scope of this. For example, the initial version may not need to support all of the features available in the UI, like translated fields or content moderation workflows. With that in mind, we may want to add this functionality as a submodule and label it "experimental".

tjh’s picture

StatusFileSize
new24.73 KB

Here's a first pass at a patch for this feature. It is based heavily on the site_alert module's implementation of this functionality.

The only equivalent test between the two I couldn't port over easily was a test for creating alerts with a start time but no end date... I dropped that one here for now, as both start and end times are required in this module. If only the end value is being passed in, the start time defaults to 'now'.

Sorry for the noise with the git.drupalcode branch... I pushed my code there, but I'm not seeing where in the interface to create a PR with it.. https://git.drupalcode.org/issue/sitewide_alert-3290964/-/tree/2.x ... I may have gone to the wrong branch?

Attaching the patch file to this comment as well just in case.

swirt’s picture

Status: Active » Reviewed & tested by the community

This tests out great for our use. Thank you @tjh for your contribution.

swirt’s picture

Testing samples:

create alert:
ddev drush sitewide-alert:create "'test-alert 7' 'testing my new alert' --style=warning --dismissible"

ddev drush sitewide-alert:create "'schedule-end' 'a brand new world' --style=shield --end='20 minutes'"

ddev drush sitewide-alert:create "'test-alert 4' 'testing my new alert' --style=warning --status=0 --dismissible=0"

enable alert:
ddev drush sitewide-alert:enable "'test-alert 4'" -y

delete alert:
ddev drush sitewide-alert:delete "'test-alert 4'" -y

disable alert:
ddev drush sitewide-alert:disable "'test-alert 7'" -y

chrissnyder’s picture

chrissnyder’s picture

@tjh, I added your patch to the issue branch you created.

The "Show commands" link above the issue fork can be helpful in making sure you are committing to the right branch.

chrissnyder’s picture

Status: Reviewed & tested by the community » Needs work

Tanner,

Thank you for your work on this! I had some time so I took a first pass and left some comments on the PR.

It looks like the tests are not running. We need to get that fixed.

edmund.dunn’s picture

StatusFileSize
new493 bytes

Posting the static patch because using the MR doesn't allow pinning to a specific commit, so anyone can submit pretty much anything and inject it into our codebase IIRC. Rerolled for 2.1. This also fixed our issue.

edmund.dunn’s picture

StatusFileSize
new23.73 KB

I messed up the above patch. Here's the correct one.

chrissnyder’s picture

Status: Needs work » Needs review
tsquared212’s picture

Status: Needs review » Reviewed & tested by the community

Attesting that the proposed feature works as intended. However, I've experienced issues running the supplied functional tests for the patch--in one case, I got a "service 'lock' has a dependency on a non-existent service 'memcache.lock.factory'". And in another, "class 'Drupal\Tests\BrowserTestCase' not found" occurred. This may be due to my ignorance or possibly other factors. The patch works fine for my requirements, although I'd encourage others to review and share their experience.

edmund.dunn’s picture

StatusFileSize
new23.76 KB

I had to update the patch to add an accessCheck() to the query for the getAlertsByLabel method. Missed that!

edmund.dunn’s picture

StatusFileSize
new23.76 KB

And missed one change for the patch.

chrissnyder’s picture

  • ChrisSnyder committed f3a08e92 on 2.x authored by tjh
    Issue #3290964 by edmund.dunn, ChrisSnyder, tjh, swirt, tsquared212:...
chrissnyder’s picture

Status: Reviewed & tested by the community » Fixed
swirt’s picture

Thank you Chris for getting this across the finish line.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.