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

$owns broken when using versioning without stages #346

Open
kinglozzer opened this issue Nov 25, 2021 · 1 comment
Open

$owns broken when using versioning without stages #346

kinglozzer opened this issue Nov 25, 2021 · 1 comment

Comments

@kinglozzer
Copy link
Member

Versions

4.8.1 - 4.x-dev (possibly earlier than 4.8.1, that’s all I tested)

Problem

When using versioning without stages (Versioned::class.'.versioned'), owned objects won’t be published.

Reproduction steps

Add the following code, dev/build then create an object and add an image. The image won’t be published when you save the object.

<?php

namespace App\Model;

use SilverStripe\Assets\Image;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;

class TestObject extends DataObject
{
    private static $table_name = 'TestObject';

    private static $db = [
        'Title' => 'Varchar(255)'
    ];

    private static $has_one = [
        'Image' => Image::class
    ];

    private static $owns = [
        'Image'
    ];

    private static $extensions = [
        Versioned::class . '.versioned'
    ];
}
<?php

namespace App\Admin;

use App\Model\TestObject;
use SilverStripe\Admin\ModelAdmin;

class TestObjectAdmin extends ModelAdmin
{
    private static $managed_models = [
        TestObject::class
    ];

    private static $menu_title = 'Test object';

    private static $url_segment = 'test-object';
}
@kinglozzer
Copy link
Member Author

Adding an && $record->hasStages() check to this line appears to solve it:

$ownerIsVersioned = $record && $record->hasExtension(Versioned::class);

I think that’s okay as a fix? It changes the logic from “prevent publish if the record is versioned” to “prevent publish if the record is versioned with stages”. If the record is versioned without stages, there’s no reason to prevent a publish as the save action updates “live” content immediately anyway.

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

No branches or pull requests

2 participants