Problem/Motivation

When a site has been built, and then edited it remains in a 'built' state. Ideally the state should change to stale to indicate that it needs a rebuild and deploy.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

mortim07 created an issue. See original summary.

mortim07’s picture

StatusFileSize
new1.72 KB
mortim07’s picture

@larowlan Happy to add a test in if you think this is valid?

larowlan’s picture

+++ b/src/Entity/PreviewSiteBuild.php
@@ -284,9 +284,31 @@ class PreviewSiteBuild extends ContentEntityBase implements PreviewSiteBuildInte
+    if (!empty($this->original) &&
+      $this->getStatus() === self::STATUS_BUILT &&
+      FALSE === $this->get('contents')->equals($this->original->contents)) {
+      return TRUE;
+    }
+    return FALSE;

any reason not to just return instead of using an if?


return !empty($this->original) && ...

+1 for a test

mortim07’s picture

@larowlan Nope, just me not seeing the obvious. 😂

mortim07’s picture

StatusFileSize
new1.73 KB
mortim07’s picture

StatusFileSize
new2.58 KB

Adding test.

mortim07’s picture

Status: Active » Needs review
larowlan’s picture

+++ b/src/Entity/PreviewSiteBuild.php
@@ -284,9 +284,28 @@ class PreviewSiteBuild extends ContentEntityBase implements PreviewSiteBuildInte
+      FALSE === $this->get('contents')->equals($this->original->contents));

should we also be comparing the updated time of the content items where they're instances of EntityChangedInterface?

mortim07’s picture

@larowlan Good point. I think that could be useful, albeit if they're saving the build then it's more likely they've added or removed something so that would take precedent anyway. I'm happy to add it in though.

mortim07’s picture

Title: Make use of stale state. » Make use of stale state
StatusFileSize
new10.41 KB

@larowlan Take a look and let me know what you think. In essence in addition to changing a build, when a content entity is updated it checks to see if there is a preview site build connected to it and sets the status to stale. I've introduced a setting that allows you to turn this behaviour off if it has performance implications. I've also added tests. Happy to discuss further. :)

Status: Needs review » Needs work

The last submitted patch, 11: 3349512-4.patch, failed testing. View results

mortim07’s picture

StatusFileSize
new10.59 KB

Let's try this again.

mortim07’s picture

StatusFileSize
new10.41 KB
mortim07’s picture

Status: Needs work » Needs review
larowlan’s picture

Status: Needs review » Needs work
Issue tags: +DrupalSouth

This looks great, just one comment about the update hook and a minor performance optimisation

  1. +++ b/preview_site.install
    @@ -31,3 +31,10 @@ function preview_site_update_9001(): TranslatableMarkup {
    +  \Drupal::configFactory()->getEditable('preview_site.settings')->set('proactive_stale_check', 0)->save();
    

    I think we need 'trust data' TRUE for the save call here because this is happening in an update hook

  2. +++ b/preview_site.module
    @@ -102,3 +103,32 @@ function preview_site_cron() {
    +    foreach ($preview_site_builds as $preview_site_build) {
    +      $preview_site_build = $preview_site_build_storage->load($preview_site_build);
    

    Can we use loadMultiple outside the loop here, for better performance

  3. +++ b/preview_site.module
    @@ -102,3 +103,32 @@ function preview_site_cron() {
    +        $preview_site_build->set('status', PreviewSiteBuildInterface::STATUS_STALE)->save();
    

    yeah this is much cleaner

mortim07’s picture

StatusFileSize
new10.37 KB

@larowlan Addressed your feedback.

larowlan’s picture

+++ b/preview_site.module
@@ -102,3 +103,31 @@ function preview_site_cron() {
+      if (!empty($preview_site_build)) {

we don't need this anymore, loadMultiple filters out nulls

Feel free to remove that and commit

mortim07’s picture

StatusFileSize
new10.32 KB

@larowlan All done.

larowlan’s picture

Status: Needs work » Reviewed & tested by the community

Thanks

  • mortim07 committed f1b6d72a on 1.x
    Issue #3349512 by mortim07: Make use of stale state
    
mortim07’s picture

Status: Reviewed & tested by the community » Fixed
larowlan’s picture

Status: Fixed » Closed (fixed)

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