sulu / SuluArticleBundle

Bundle for managing localized content-rich entities like blog-posts in the Sulu content management system
MIT License
52 stars 77 forks source link

Add copy article functionality #538

Closed alexandersch closed 1 year ago

alexandersch commented 3 years ago

I would like to request a copy article feature. Would be a nice addition to the article bundle.

rogamoore commented 2 years ago

Hello everybody!

We would also be interested to have this feature and are happy to help making it happen.

We noticed that there is already some logic in the current version for copying articles so it looks like this feature was already there in an older version of the bundle: see https://github.com/sulu/SuluArticleBundle/blob/2.x/Controller/ArticleController.php#L565

PoC

With some hacks it's pretty easy to get it working:

Next steps?

So what do you think?

rogamoore commented 1 year ago

Hi, I was wondering if someone could give me a quick feedback. If there is interest I could start working on a PR.

mario-fehr commented 1 year ago

Hi, I was wondering if someone could give me a quick feedback. If there is interest I could start working on a PR.

@rogamoore It would be nice if you could contribute this feature to the bundle.

Jelmer7 commented 1 year ago

👋 Any update on this?

rogamoore commented 1 year ago

@mario-fehr @Jelmer7 Please see the "Next steps?" section on my post. I need feedback from someone (Sulu Team) on the two subscribers that are failing. They are not part of the SuluArticleBundle, but of Sulu Core and I have not enough knowledge at the moment to fix this part.

rogamoore commented 1 year ago

@alexander-schranz Sorry to ping you, but as we have some time available to contribute to this feature, I would like to ask for a quick opinion/feedback of the Sulu team regarding the above questions. If it's a bad moment, just let me know, otherwise I think it could be a great addition to the next release.

alexander-schranz commented 1 year ago

@rogamoore I think the copy function should be very similar to the snippet copy function which was lately implemented here by @wachterjohannes: https://github.com/sulu/sulu/pull/6859/files. Let me know if you can get it based on https://github.com/sulu/sulu/pull/6859/files get it work also for articles.

The deleteUnavailableLocales sounds like something which can be skipped in copy where no locale exist.

The RoutableSubscriber sounds required. It is strange that it fails here and the documentInspector can not get all locales? Or what is the current stack trace here?

rogamoore commented 1 year ago

@alexander-schranz Thanks for your feedback! I've checked the PR you've linked (https://github.com/sulu/sulu/pull/6859/files) and my changes are pretty much the same (which I think is a good sign) with the difference that after copying the article it's not published immediately, but opened in draft mode.

The linked PR also fixes one of my problems mentioned above, where it fails in the WebspaceSubscriber.

So right now there is only one issue left (all other details can be discussed in the upcoming PR).

So now this raises a few questions:

rogamoore commented 1 year ago

So, I found that the reason why generator is null is because in my config there is no mapping defined:

# missing
sulu_route:
    mappings:
        Sulu\Bundle\ArticleBundle\Document\ArticleDocument:
            generator: schema
            options:
                route_schema: '/articles/{implode("-", object)}'

The reason is that I have configured the route schema per template as described here: https://github.com/sulu/SuluArticleBundle/blob/2.x/Resources/doc/routing.md#overwrite-route-schema-in-template

<property name="routePath" type="route" mandatory="true">
    <meta>
        <title>sulu_admin.url</title>
    </meta>
    <params>
        <param name="route_schema" value="/{translator.trans('article.routes.events')}/{implode('-', object)}"/>
        <param name="mode" value="leaf"/>
    </params>
    <tag name="sulu_article.article_route"/>
</property>

So this raises a new question: If the route schema is defined in the template, how to make sure it's also used when copying an article?

Meanwhile I will test the yaml config to see, if I can get past the error with this.

rogamoore commented 1 year ago

I can get past the error, when using this mapping (not the default from the docs):

sulu_route:
    mappings:
        Sulu\Bundle\ArticleBundle\Document\ArticleDocument:
            generator: schema
            options:
                route_schema: '/articles/{is_array(object) ? implode("-", object) : object.getTitle()}'

Without the default from the docs I'm getting

implode(): Argument #2 ($array) must be of type ?array, Sulu\\Bundle\\ArticleBundle\\Document\\ArticleDocument given

My next step will be preparing a PR, but I will need some help with this route generating stuff, because IMHO it should work with the default YAML config and also when using the route schema per template config.

rogamoore commented 1 year ago

I think this issue can be closed now that #610 has been merged - the feature will be available in the next release (2.5.0 I guess)