silverstripe-cms icon indicating copy to clipboard operation
silverstripe-cms copied to clipboard

SiteTree won't write new versions if only a field named 'Status' is changed

Open lozcalver opened this issue 6 years ago • 1 comments

Please don’t ask how much time I wasted because of this bug 😭😂

<?php

class MyPage extends Page
{
    private static $db = [
        'Status' => 'Varchar(255)'
    ];

    public function getCMSFields()
    {
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
            $fields->addFieldToTab('Root.Main', TextField::create('Status'));
        });

        return parent::getCMSFields();
    }

    public function onAfterPublish()
    {
        die('you will never get this, a-la-la-la-la');
    }
}

Make changes to the value of status, onAfterPublish() won’t be called. The only time it’ll be called is if you also make a change to another field’s value as well. There are other issues this bug causes, but this is the easiest to reproduce.

The cause is this line: https://github.com/silverstripe/silverstripe-cms/blob/8a44071ec63c33abcec0d2901081114b30ae1907/code/Model/SiteTree.php#L1588.

I’m not sure if we should just remove that whole code block, but at the very least we should remove Status from the array as it’s no longer a field on SiteTree (it hasn’t been since 2.4). We should also remove ToDo, VersionID and SaveCount.

lozcalver avatar Jul 10 '19 15:07 lozcalver

How much time did you waste?

michalkleiner avatar Jul 10 '19 21:07 michalkleiner