Fix algorithm for candidate determination

Created on 1 December 2022, almost 2 years ago
Updated 28 April 2023, over 1 year ago

Problem/Motivation

I have been running the 1.0.1 version of this module on a site for a few months and it has been working great. I updated to the 1.1.1 version to take advantage of the new algorithm to prune even more revisions. After running the 1.1.1 version on a dev site I noticed a few issues.

  1. Originally this module kept all published revisions, the new 1.1.1 version now deletes published revisions. This is a problem for Government of Canada applications as they are required to keep the full history of published content.
  2. After running against some nodes I noticed instances where all revisions of a node would be deleted.

I have updated the logic to keep all published revisions, with an option to allow pruning of published revisions as implemented in the related ticket. There is now a textbox that allows us to enter all workflow states that should be considered published, which allows us to consider a state like archived as published. I have also added a Devel form that allows us to test the candidate revision selection on a given node, which takes into account all config options on the settings form.

Changes to settings form:

New devel form:

🐛 Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

🇨🇦Canada smulvih2 Canada 🍁

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇦Canada joel_osc

    Re-rolling this patch because it does provide some nice functionality, but removing the changes to cm_revision_delete_get_latest_default_revision as from my testing the previous code was working properly and the new code was definitely broken.

  • 🇨🇦Canada joel_osc

    Attempt #2, fixing missing DevelForm.php in previous patch.

  • 🇨🇦Canada joel_osc

    I have tested the above patch and it seems to work. I would like at least one more set of eyes on it before bringing it in so i will leave this as needs review for now. Thanks everyone for all of your work.

  • Status changed to RTBC over 1 year ago
  • 🇨🇦Canada smulvih2 Canada 🍁

    @mrshowerman yes I see what you mean about getLatestTranslationAffectedRevisionId() not always returning the default revision. Looks like the patch in #16 addresses this (reverts my changes to cm_revision_delete_get_latest_default_revision()). Tested #16 and works great! Will put this to RTBC but will wait for our QA team to review this in more detail before moving forward with the merge.

  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada smulvih2 Canada 🍁

    We are getting reports that nodes without a published revision get all drafts besides the latest are being deleted. In the case where no published revisions exist, all drafts should be left untouched. I have updated the cm_revision_delete_get_node_candidate() function to account for this (only return nodes that have at least one published revision). I have also updated the devel form to identify if the node in question is a candidate or not, and if it is it will display the revisions that will be deleted.

  • 🇨🇦Canada smulvih2 Canada 🍁

    Issue with the way I created the last patch. New patch attached.

  • Status changed to RTBC over 1 year ago
  • 🇨🇦Canada joel_osc

    Patch is confirmed working on multiple sites... rbtc.

    • smulvih2 committed 01fb490e on 1.1.x
      Issue #3324883 by smulvih2, joel_osc: Fix algorithm for candidate...
  • Status changed to Fixed over 1 year ago
  • 🇨🇦Canada smulvih2 Canada 🍁

    Thanks for all the work on this guys! This has been included in 1.1.3.

  • Hello all,

    After upgrading to 1.1.3 and visiting the admin link (/admin/config/content/cm_revision_delete) I get the error message below.

    The problem disappears when I downgraded to 1.1.2. I am using Drupal 9.5.8 on PHP 8.1.16 and 10.6.11-MariaDB-0ubuntu0.22.04.1. Not sure if I should include this bug in this issue or elsewhere?

    Thanks for all your work.

    The website encountered an unexpected error. Please try again later.

    Symfony\Component\Routing\Exception\RouteNotFoundException: Route "cm_revision_delete.devel" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 206 of core/lib/Drupal/Core/Routing/RouteProvider.php).
    Drupal\Core\Menu\LocalTaskDefault->getRouteParameters() (Line: 310)
    Drupal\Core\Menu\LocalTaskManager->getTasksBuild() (Line: 358)
    Drupal\Core\Menu\LocalTaskManager->getLocalTasks() (Line: 95)
    Drupal\Core\Menu\Plugin\Block\LocalTasksBlock->build() (Line: 171)
    Drupal\block\BlockViewBuilder::preRender()
    call_user_func_array() (Line: 101)
    Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 788)
    Drupal\Core\Render\Renderer->doCallback() (Line: 374)
    Drupal\Core\Render\Renderer->doRender() (Line: 446)
    Drupal\Core\Render\Renderer->doRender() (Line: 204)
    Drupal\Core\Render\Renderer->render() (Line: 479)
    Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 43)
    __TwigTemplate_adf422af4faba65a60c110b1816dd7b8->doDisplay() (Line: 405)
    Twig\Template->displayWithErrorHandling() (Line: 378)
    Twig\Template->display() (Line: 390)
    Twig\Template->render() (Line: 55)
    twig_render_template() (Line: 384)
    Drupal\Core\Theme\ThemeManager->render() (Line: 433)
    Drupal\Core\Render\Renderer->doRender() (Line: 204)
    Drupal\Core\Render\Renderer->render() (Line: 479)
    Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 86)
    __TwigTemplate_cdf27144588ac30aff3b7f000179defe->doDisplay() (Line: 405)
    Twig\Template->displayWithErrorHandling() (Line: 378)
    Twig\Template->display() (Line: 390)
    Twig\Template->render() (Line: 55)
    twig_render_template() (Line: 384)
    Drupal\Core\Theme\ThemeManager->render() (Line: 433)
    Drupal\Core\Render\Renderer->doRender() (Line: 204)
    Drupal\Core\Render\Renderer->render() (Line: 162)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 163)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
    call_user_func() (Line: 142)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 174)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 46)
    Drupal\redirect_after_login\RedirectMiddleware->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 49)
    Asm89\Stack\Cors->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
    Stack\StackedHttpKernel->handle() (Line: 718)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

  • 🇨🇦Canada smulvih2 Canada 🍁

    @elneto thanks for reporting this. I have 1.1.3 installed on drupal/core 9.5.8 as well and it is working for me. If you look at the routing file in the root of the module you will see that route is defined. Can you please try deleting the module folder and running composer install again? Also make sure no other patches are being applied to this module.

  • @smulvih2, worked like a charm. Thank you very much!

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

Production build 0.71.5 2024