This plugin has been discontinued.

The Resave Expired plugin resaves elements when their future post or expiry dates pass. It requires a console command to be run on a regular schedule via a cron job.

This is especially useful with plugins like Scout, that sync entries to Algolia only on save. Caching plugins can also benefit from this.

Blitz already has this functionality built in, so does not require this plugin.

License #

This plugin is licensed for free under the MIT License.

Requirements #

This plugin requires Craft CMS 4.0.0 or later.

Installation #

Install manually using composer.

composer require putyourlightson/craft-resave-expired

Console Commands #

Elements with future post or expiry dates can switch status (pendinglive / liveexpired) at any time, therefore a cron job must be set up that runs on a regular schedule. How frequently the cron job should run depends on how time-sensitive changed element statuses are to your site.

It is a good idea to set a convention with your content authors. For example, you could agree that post and expiry dates must be set on the hour, in which case it would make sense to schedule the cron job to run hourly at 1 minute past the hour (1 * * * *).

php craft resave-expired/elements/resave-expired

Since expiry dates are only registered on element save, you can run the following console command after installing the plugin, which will resave all elements’ expiry dates.

php craft resave-expired/elements/resave-expiry-dates

Events #

The plugin triggers events before and after resaving elements. If you want to perform your own logic via a plugin or module then you can do so by listening for the EVENT_BEFORE_RESAVE_ELEMENTS or EVENT_AFTER_RESAVE_ELEMENTS events.

You can also prevent the resaving of elements and opt to handle the event yourself.

use putyourlightson\resaveexpired\events\ResaveElementsEvent;
use putyourlightson\resaveexpired\services\ElementsService;
use yii\base\Event;

Event::on(ElementsService::class, ElementsService::EVENT_BEFORE_RESAVE_ELEMENTS,
    function (ResaveElementsEvent $event) {
        // Prevent the resaving of elements.
        $event->isValid = false;
        // Do something with the element IDs.
        $elementIds = $event->elementIds;
    }
);

Have a suggestion to improve the docs? Create an issue with details, and we'll do our best to integrate your ideas.