Support scheduled publish and unpublish

Created on 21 June 2024, 6 months ago
Updated 13 July 2024, 5 months ago

Problem/Motivation

It would be nice if users could schedule the publishing (and unpublishing) of modals. That way, a modal could be set to appear on a given date/time and then go away automatically.

For example, a modal warning of system maintenance could be set to appear the day before the maintenance started and to go away after it occured.

Proposed resolution

I looked into creating a plugin to work with the Scheduler β†’ module, but I don't think that is possible. I don't think that module will work with config entities. At least, I couldn't figure it out.

This could be done by adding "Publish on" and "Unpublish on" fields to the Modal entity and adding a hook_cron() implementation to publish/unpublish based on the current time and those dates.

I've got working code that I will add here shortly.

Remaining tasks

  1. Add "Publish on" and "Unpublish on" fields to the Modal entity.
  2. Add a hook_cron() implementation to publish/unpublish based on the current time and those dates.
  3. Add tests.
  4. Merge code.

User interface changes

"Publish on" and "Unpublish on" fields will be added to the Modal entity add/edit form.

Data model changes

"publish_on" and "unpublish_on" fields will be added to the Modal entity.

✨ Feature request
Status

Fixed

Version

5.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jrb Raleigh-Durham Area, NC, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jrb
  • Assigned to jrb
  • πŸ‡ΊπŸ‡ΈUnited States jrb Raleigh-Durham Area, NC, USA
  • πŸ‡§πŸ‡·Brazil renatog Campinas

    Hello @jrb, I hope you're doing well

    It would be nice if users could schedule the publishing (and unpublishing) of modals. That way, a modal could be set to appear on a given date/time and then go away automatically.
    For example, a modal warning of system maintenance could be set to appear the day before the maintenance started and to go away after it occured.

    Amazing feature!
    It can also be used to publish Modals on planned campaigns for example

    I looked into creating a plugin to work with the Scheduler

    When reading, it was the first solution on my mind as well lol

    I don't think that is possible. I don't think that module will work with config entities. At least, I couldn't figure it out

    Right
    I'm using Scheduler on my site but it's a Content Entities and not for Config Entities. Nice catch

    This could be done by adding "Publish on" and "Unpublish on" fields to the Modal entity and adding a hook_cron() implementation to publish/unpublish based on the current time and those dates.

    Agreed!
    It's a good alternative and makes sense for me

    I've got working code that I will add here shortly.

    Deal!
    I'll stay tunned and available to test and commit it

    Thank you so much for the great suggestion and if you like Modal I'd ask to consider giving a star to encourage the project

  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jrb Raleigh-Durham Area, NC, USA

    I've pushed changes to the issue fork. Attached is a patch. This isn't live yet for us, but does work in local testing.

    I added some basic documentation to the README:

    Modal pages can be scheduled to be published or unpublished at specified times.

    When you have set up Drupal's standard crontab job, the Modal page scheduling will be processed during each cron run. However, if you would like finer granularity for scheduling but don't want to run Drupal's cron more often, you may use the Modal Page cron handler provided. This is an independent cron job which only runs the scheduler process and does not execute any cron tasks defined by Drupal core or any other modules.

    Modal page's cron is at /modal-page/cron/{cron-key}. A sample crontab entry to run the scheduler every minute might look like:

    * * * * * wget -q -O /dev/null "https://example.com/modal-page/cron/{cron-key}"
    

    or

    * * * * * curl -s -o /dev/null "https://example.com/modal-page/cron/{cron-key}"
    

    The scheduler may also be run with a Drush command:

    drush modal_page:cron
    
  • πŸ‡§πŸ‡·Brazil renatog Campinas

    Great, thanks! I'll test that

  • πŸ‡§πŸ‡·Brazil renatog Campinas

    About functionality is working fine

    phpcs pointed few errors, but it's minor

    FILE:/modal_page/README.md
    ----------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ----------------------------------------------------------------------
     112 | WARNING | Line exceeds 80 characters; contains 426 characters
     114 | WARNING | Line exceeds 80 characters; contains 128 characters
    ----------------------------------------------------------------------
    
    
    FILE:/modal_page/src/Service/ModalPageScheduler.php
    ------------------------------------------------------------------------------
    FOUND 4 ERRORS AFFECTING 2 LINES
    ------------------------------------------------------------------------------
     48 | ERROR | [x] Expected 1 space between double arrow and "$modal"; 2 found
     48 | ERROR | [x] Expected 1 space after "=>"; 2 found
     61 | ERROR | [x] Expected 1 space between double arrow and "$modal"; 2 found
     61 | ERROR | [x] Expected 1 space after "=>"; 2 found
    ------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------
    
    
    FILE:/modal_page/src/Drush/Commands/ModalPageCommands.php
    ---------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------------
     36 | ERROR | [ ] Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
     41 | ERROR | [x] Missing function doc comment
    ---------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------
    
    FILE:/modal_page/src/Service/ModalPageScheduler.php
    --------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------
     73 | WARNING | There must be no blank line following an inline comment
    --------------------------------------------------------------------------
    
    • 9c29b7d5 committed on 5.0.x
      Issue #3456333 by jrb, renatog: Support scheduled publish and unpublish
      
  • πŸ‡§πŸ‡·Brazil renatog Campinas

    fixed items listed above and since it's working fine, moved to the dev branch

  • Issue was unassigned.
  • Status changed to Fixed 6 months ago
  • πŸ‡§πŸ‡·Brazil renatog Campinas

    fixed items listed above and since it's working fine, moved to the dev branch

    Thank you so much @jrb

    • 1a5a98cc committed on 5.0.x
      Issue #3456333 by jrb, renatog: Support scheduled publish and unpublish
      
    • d3614857 committed on 5.0.x
      Issue #3456333 by jrb, renatog: Support scheduled publish and unpublish
      
  • πŸ‡§πŸ‡·Brazil renatog Campinas
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024