Add query tags to let other modules alter the SchedulerManager queries.
The alter hooks can be used to change the list of ids, but they would require new query executions. In many cases it is enough to alter the SchedulerManager's queries.

CommentFileSizeAuthor
#2 3360744-add-query-tags-2.patch1.12 KBaludescher

Issue fork scheduler-3360744

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

aludescher created an issue. See original summary.

aludescher’s picture

StatusFileSize
new1.12 KB
aludescher’s picture

Status: Active » Needs review

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

jonathan1055’s picture

Thanks aludescher, this looks useful. I have converted your patch into an MR.

Do you have some examples where you have used these tags, to modify the queries?

It will need test coverage too. Let's see if we can re-use one of the existing test modules.

jonathan1055’s picture

This is working well. I have read through the examples found in api/drupal/core/lib/Drupal/Core/Database/database.api.php/function/hook_query_TAG_alter/10 and can add some tests.

I have a question - you have added four tags:

  $query->addTag('scheduler');
  $query->addTag('scheduler_publish');
  $query->addTag('scheduler_' . $plugin->getPluginId() . '_publish');
  $query->addTag('scheduler_' . $entityTypeId . '_publish');

and these resolve to

[alterTags:protected] => Array (
  [scheduler] => 1
  [scheduler_publish] => 1
  [scheduler_node_scheduler_publish] => 1   << do not need this tag
  [scheduler_node_publish] => 1
)

I'm not sure why we need the third tag, the one using $plugin->getPluginId(), as that does not give any extra flexibility that the $entityTypId does not provide. Or maybe I have missed something?

jonathan1055’s picture

As expected, the new tests fail (see MR pipeline) in two different places, due to only adding one publish tag, and no unpublish tags

There were 4 failures:
1) Drupal\Tests\scheduler\Functional\SchedulerQueryTagsTest::testPublishingQueryTags with data set "#node" ('node', 'testpage')
After first cron, node 3 should remain unpublished.
2) Drupal\Tests\scheduler\Functional\SchedulerQueryTagsTest::testPublishingQueryTags with data set "#media" ('media', 'test_video')
After first cron, media 3 should remain unpublished.
3) Drupal\Tests\scheduler\Functional\SchedulerQueryTagsTest::testUnpublishingQueryTags with data set "#node" ('node', 'testpage')
After first cron, node 2 should remain published.
4) Drupal\Tests\scheduler\Functional\SchedulerQueryTagsTest::testUnpublishingQueryTags with data set "#media" ('media', 'test_video')
After first cron, media 2 should remain published.

Now adding the remaining tags. Should all pass.

  • jonathan1055 committed 63002a08 on 2.x
    Issue #3360744 by jonathan1055, aludescher: Add query tags to let other...
jonathan1055’s picture

Status: Needs review » Fixed

This is a good addition. Thanks aludescher for providing the initial patch.
Committed to 2.x

  • jonathan1055 committed a676442d on 2.x
    Issue #3360744 by jonathan1055, aludescher: Cater for QueryTag test data...

Status: Fixed » Closed (fixed)

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