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

Data objects not publishing #853

Open
jesscostello opened this issue May 23, 2024 · 2 comments
Open

Data objects not publishing #853

jesscostello opened this issue May 23, 2024 · 2 comments

Comments

@jesscostello
Copy link

jesscostello commented May 23, 2024

Module version(s) affected

7.1.1

Description

I have a dataobject which has the versioned extension (versioning only, no staging) and FluentVersionedExtension applied. No matter how I create/save the object it always seems to remain in draft format. I have simplified down my dataobject for the purposes of replication and to rule out anything from the class itself but am still seeing issues. Not sure if this is definitely a bug or if I'm missing something

How to reproduce

Using Silverstripe 5.2

PHP Class

<?php

namespace Name\Website\Models;

use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\ORM\DataObject;

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

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

    private static $has_one = [
        'PhoneLink' => Link::class,
    ];

    private static $many_many = [
        'Images' => Image::class,
    ];

    private static $owns = [
        'Images',
        'PhoneLink',
    ];

    private static $cascade_duplicates = [
        'Images',
        'PhoneLink',
    ];

    private static $cascade_deletes = [
        'Images',
        'PhoneLink',
    ];

    public function getCMSFields()
    {
        $this->beforeUpdateCMSFields(
            function ($fields) {
                $fields->removeByName(['Images']);
                $uploadField = UploadField::create('Images')
                    ->setAllowedExtensions(['png', 'jpg', 'jpeg'])
                    ->setIsMultiUpload(true);

                $fields->addFieldToTab(
                    'Root.Main',
                    $uploadField,
                );
            }
        );
        return parent::getCMSFields();
    }
}

YML Config

File 1

---
Name: app-config
---
TPNT\Website\Models\TestObject:
  extensions:
    - SilverStripe\Versioned\Versioned.versioned

File 2

---
Name: fluent-config
After:
  - '#app-config'
  - '#versionedfiles'
---
TractorCow\Fluent\Model\Locale:
  default_records:
    en:
      Title: English
      Locale: en_NZ
      URLSegment: en
      IsGlobalDefault: 1
    mi:
      Title: Te Reo Māori
      Locale: mi_NZ
      URLSegment: mi

TractorCow\Fluent\Extension\FluentExtension:
  frontend_publish_required: any

SilverStripe\LinkField\Models\Link:
  extensions:
    - TractorCow\Fluent\Extension\FluentVersionedExtension

Name\Website\Models\TestObject:
  extensions:
    - TractorCow\Fluent\Extension\FluentVersionedExtension

When first creating an object there is only a create button, clicking this results in the following
Screenshot 2024-05-24 at 8 57 56 AM

It also does not publish the image as I would expect (Image relationship appears in $owns).

I then have the localisation menu and click 'save and publish (all locales)'. This does publish the image but not the object

Screenshot 2024-05-24 at 8 58 24 AM

Clicking 'publish in this locale' in the localisation table also does not publish and leaves the record in draft state.

Any help would be much appreciated!

@jesscostello
Copy link
Author

@tractorcow just wondering if there's any chance you could offer some assistance with my issue please?

@tractorcow
Copy link
Collaborator

I've not used versioned without stages for a long time, and I haven't actually used ss 5.x in any case. Is there something changed in ss5 with regards to versioning without stages? Sorry I've been out of the Silverstripe game for a bit too long.

I don't know if versioning without stages is a working use case in fluent. FluentVersionedExtension is designed around the standard publishing model, which is draft + live stages. If you see at https://github.com/tractorcow-farm/silverstripe-fluent/blob/7/src/Extension/FluentVersionedExtension.php#L132-L137 you can see that the live / draft stages are assumed as fixed in here.

My suggestion is to keep the Versioned extension, but try removing FluentVersionedExtension (using FluentExtension on its own), due to the lack of stages. It may be sufficient for your admin interface to work.

If you run into issues with this, is removing versioning from your record an option?

If I were to spend the time to fix this in fluent, I would look at FluentVersionedExtension and add some more intelligent logic for checking the list of active stages.

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

No branches or pull requests

2 participants