You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
Tried to implement the auto-unpublish with CacheMaster enabled, but unfortunately it does not work as expected :(
Here is my bug report and my local corrections.
When $modx->cacheManager->refresh(...) is called on OnBeforeDocFormSave event, MODX takes the values of pub_date and unpub_date from the database, not from event's $resource object.
Since we are in OnBeforeDocFormSave handler, the new values (pub or unpub) are not yet saved to the database.
Therefore, $modx->cacheManager->refresh will update the auto_publish.cache.php not for current resource, but for other resources with non-zero pub_date and unpub_date values.
If the submitted (but not saved yet) resource is the only with the unpub_date, the auto_publish.cache.php will not be updated.
With the current approach, the auto_publish.cache.php not updating when the user unset either pub_date or unpub_date, which was previously set. Inside OnBeforeDocFormSave unset values are empty and the condition is not satisfied.
My solution:
bind CacheMaster to OnDocFormSave event.
relocate $modx->cacheManager->refresh(...) without surrounding condition from OnBeforeFormSave to the first switch($event):
/* Bail out if we're not doing this object */
switch($event) {
case 'OnDocFormSave':
if (!$doResources) {
return;
}
$ctx = $resource->get('context_key');
// If pub_date or unpub_date are set, update the auto_publish cache
// if ($resource->get('pub_date') || $resource->get('unpub_date')) {
$providers = array(
'auto_publish' => array('contexts' => $ctx),
);
$providers_result = array();
$modx->cacheManager->refresh($providers, $providers_result); // Cache refreshes from database
if ($doDebug) {
my_debug($providers_result);
}
//}
return;
break;
case 'OnDocFormPrerender':
case 'OnBeforeDocFormSave':
if (!$doResources) {
return;
}
break;
The text was updated successfully, but these errors were encountered:
Hello,
Sorry for answering with delay.
Actually, only one line of this modification was authored by me. It is "case 'OnDocFormSave':". All other lines were copy-pasted from your original code.
I think it is possible to assume that multiple calls to getOption are safe for execution inside OnDocFormSave handler.
Yes, I tested my modification with following scenarios (only with unpub_date).
set the unpub_date (one resource)
clear the unpub_date (one resource)
set the unpub_date (multiple resources with unpub_date set)
clear the unpub_date (multiple resources with unpub_date set)
My modification is already working on production website. I use CacheMaster in doResource+uncheckEmptyCache mode only.
The only improvement I could imagine is to actually detect the change of pub_date and unpub_date values on OnBeforeDocFormSave (before) and somehow pass the change to OnDocFormSave (after).
In this case the auto_publish.cache.php will be regenerated only then absolutely needed.
Hello,
Tried to implement the auto-unpublish with CacheMaster enabled, but unfortunately it does not work as expected :(
Here is my bug report and my local corrections.
Related commits for reference:
9c45274
0ea93d8
When $modx->cacheManager->refresh(...) is called on OnBeforeDocFormSave event, MODX takes the values of pub_date and unpub_date from the database, not from event's $resource object.
Since we are in OnBeforeDocFormSave handler, the new values (pub or unpub) are not yet saved to the database.
Therefore, $modx->cacheManager->refresh will update the auto_publish.cache.php not for current resource, but for other resources with non-zero pub_date and unpub_date values.
If the submitted (but not saved yet) resource is the only with the unpub_date, the auto_publish.cache.php will not be updated.
With the current approach, the auto_publish.cache.php not updating when the user unset either pub_date or unpub_date, which was previously set. Inside OnBeforeDocFormSave unset values are empty and the condition is not satisfied.
My solution:
The text was updated successfully, but these errors were encountered: