Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

None versioned DataObject does not trigger objectsToUpdate #197

Open
2 tasks done
Oliver996 opened this issue Jul 16, 2024 · 1 comment
Open
2 tasks done

None versioned DataObject does not trigger objectsToUpdate #197

Oliver996 opened this issue Jul 16, 2024 · 1 comment
Labels

Comments

@Oliver996
Copy link

Module version(s) affected

^6.2

Description

I did add everything like documented https://github.com/silverstripe/silverstripe-staticpublishqueue/blob/6/docs/en/basic_configuration.md#engines to the dataobject to trigger republish of the cache. When the dataobject is versioned the objectsToUpdate is triggered when I unpublish or/and archive the dataobject. But in a dataobject that is not versioned it only triggers on save, but not on delete. I could not get objectsToUpdate to trigger on delete. Is this a bug, not meant to work with not versioned dataobject or is there some documentation missing for not versioned dataobject? I did test it on my silverstripe 5.2 and also on a clean silverstripe 5.2 with only the staticpublishqueue both had the same problem.
It also would be nice to add that you need the canPublish function for versioned dataobject in the documentation.

How to reproduce

Clean 5.2 Silverstripe with staticpublishqueue then added dataobject like https://github.com/silverstripe/silverstripe-staticpublishqueue/blob/6/docs/en/basic_configuration.md#engines

Test.php with objectsToUpdate and objectsToDelete (both simply for testing)

<?php

use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
use SilverStripe\StaticPublishQueue\Contract\StaticPublishingTrigger;

class Test extends DataObject implements StaticPublishingTrigger {

    private static $db = [
        'Name' => 'Text'
    ];

    private static $table_name = 'Test';

    function getCMSFields() {
        $fields = FieldList::create(TabSet::create('Root'));

        $fields->addFieldToTab('Root.Main',
            TextField::create('Name', _t('Downloads.NAME', 'Name'))
        );

        $this->extend('updateCMSFields', $fields);

        return $fields;
    }

    public function objectsToUpdate($context) {
        $page = Page::get()->First();
        $array[] = $page;

        return $array; 
    }

    public function objectsToDelete($context) {
        $page = Page::get()->First();
        $array[] = $page;

        return $array;
    }

}

yml

Test:
  extensions:
    - SilverStripe\StaticPublishQueue\Extension\Engine\SiteTreePublishingEngine

After saving, it creates both jobs, but after delete it creates no jobs for update/delete cache.

When adding versioned to the dataobject (add to Test class)

private static $extensions = [
    Versioned::class,
];

public function canPublish($member = null){
    return true;
}

Then it works with saving, publishing, unpublishing and archiving. It always creates both jobs

Possible Solution

No response

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)
@andrewandante
Copy link
Contributor

Hi - it looks like the only hooks in the SiteTreePublishingEngine are related to publishing, so yes, I think this module currently doesn't work with non-versioned objects.

For your case, you should be able to work around it by replicating the onBefore/onAfter changes, and applying them to write rather than publish (and delete rather than unpublish).

I think there's a potential PR where the onBefore/onAfter methods are called with an "if this thing is not versioned" check? Potentially worth experimenting with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants