Rescheduling Drupal Scheduler Content Safely, and a Gap Check That Only Looked Forward

By Lars Nielsen ·

This site's articles are scheduled ahead with the Drupal Scheduler module: each one is an unpublished node with a publish_on date, and cron publishes it when the time comes. In September, I learned the hard way that rescheduling with SQL doesn't work, because Scheduler reads a table I hadn't updated. In October, I had to move and edit scheduled articles again, and I also found a bug in how the pipeline decided which days needed articles. This is the version that works.

The gap check that only looked forward

The pipeline that drafts articles is told to keep the next 14 days covered. Its instructions said: find the latest date that already has an article scheduled, and fill the days after it. That sounds right and isn't. On 15 October the latest scheduled article was on the 28th, so by that rule the queue was full. In fact five days in between had nothing: the 19th, 20th, 24th, 25th and 26th. The rule only ever filled the end of the window, never holes in the middle, and holes appear naturally when articles get moved or deleted.

The fix redefined the gap. Every day in the window is checked on its own: a day is covered if at least one article is scheduled inside that day's publishing window, or, for today only, if an article already went live today. Every day that isn't covered is a gap, wherever it falls. Running that check against the live site immediately listed exactly the five empty days. Unpublished articles with no date at all now get listed in the run's summary too, because Scheduler will never publish them.

Moving scheduled articles safely

Filling the gaps at one new article a day meant some existing days would get four or five, so four already-scheduled articles had to move. The incident in September came from writing new dates straight into node_field_data, which is what the API reads back, while Scheduler finds due content through the latest revision, which lives in node_field_revision. The two disagreed, and the API looked right while Scheduler did something else.

This time every change went through Drupal's entity API, using a JSON:API PATCH of just the publish_on field, with the same account the pipeline publishes with. An entity save creates a new revision and writes both tables. The method I trust is the check afterwards, not the save: for every scheduled node, a read-only query on the production database comparing publish_on in node_field_data with the value in that node's latest revision, and checking that the latest revision is also the default one. All of them matched. The query, for MySQL or MariaDB, run read-only through drush sql:query; an empty result means everything agrees:

-- Scheduled nodes whose Scheduler date differs between the data table and the
-- latest revision, or whose latest revision isn't the default one.
-- An empty result means every scheduled node is consistent.
SELECT d.nid, d.publish_on, r.publish_on AS latest_revision_publish_on,
       n.vid AS default_vid, r.vid AS latest_vid
FROM node_field_data d
JOIN node n ON n.nid = d.nid
JOIN node_field_revision r
  ON r.vid = (SELECT MAX(vid) FROM node_revision WHERE nid = d.nid)
WHERE d.status = 0
  AND d.publish_on IS NOT NULL
  AND (NOT d.publish_on <=> r.publish_on OR n.vid <> r.vid);

And the change itself, with curl. Only the field being changed is sent, and the response shows the stored value:

# Move one scheduled article: PATCH only publish_on, through JSON:API.
# Drupal saves it as a new revision, which updates both tables.
uuid=THE-NODE-UUID
curl --fail-with-body -sS -u "$LINKHUB_USER:$LINKHUB_PASS" \
  -X PATCH "https://www.example.com/jsonapi/node/article/$uuid" \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{"data": {"type": "node--article", "id": "'"$uuid"'",
       "attributes": {"publish_on": "2026-12-05T22:20:00+00:00"}}}' \
  | python3 -c 'import json,sys; a=json.load(sys.stdin)["data"]["attributes"]; print(a["publish_on"], a["status"])'

Two more rules for the move itself. Before moving an article later, check which scheduled articles link to it: an article that links to one going live after it shows visitors a 403 until the target is published. Here, every article that linked to one being moved still went live after its target, and no live article linked to any of them. And back up the scheduler state for every scheduled node before changing anything.

Editing scheduled articles

The same week, a manual check found factual errors in six newly scheduled articles. Those were fixed the same way: back up each node's current body, PATCH only the body field with the corrected text, and read it back. Each edit created a new revision, numbered 496 to 501, and the same two-table check confirmed that every publish_on was unchanged and that the new revision was the one Scheduler would look at.

The checklist

  • Check coverage day by day, not from the latest date.
  • Change scheduled content only through the entity API, never with SQL.
  • After any change, compare publish_on between the data table and the latest revision, and check that the latest revision is the default.
  • Before moving an article later, check what links to it.
  • Back up before changing, and keep the backup until the article is live.

None of it is complicated. The September incident happened because the obvious tool, a single SQL update, looked right in every view I checked and was invisible to the one component that mattered.

Filed under

Leave a comment

Comments are reviewed before they appear.

Basic HTML allowed: links, emphasis, code and lists. Web addresses become links automatically.