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

slug is overwritten when updating partial data without slug field (via PHP or API) #3

Closed
raffaelj opened this issue Sep 8, 2019 · 0 comments

Comments

@raffaelj
Copy link
Owner

commented Sep 8, 2019

When using the UI, all fields will be sent when updating an entry and everything works like expected. But when I update only a partial data set, the addon thinks, that the slug was deleted and creates a new one with the default fallback.

Steps to reproduce:

PHP

$change = [
    '_id' => '5cebf12a333862178c0001f8', // existing _id
    'test' => 'change only this one',
    
    // UniqueSlugs addon wants to check against these fields:
    // 'slug' => 'about',
    // 'title' => 'About',
];

// save changes
$this->module('collections')->save('pages', [$change], ['revision' => true]);

REST API
/api/collections/save/pages?token=xxtokenxx
{"data":{"_id":"5cebf12a333862178c0001f8","test":"change only this one"}}

Response:

{
    "_id": "5cebf12a333862178c0001f8",
    "test": "change only this one",
    "_by": "user_id...",
    "_modified": 1567949823,
    "slug": "entry",
    "slug_fr": "entry-1"
}

It is totally possible, to update entries with partial data, but the addon doesn't know about it and tries to check against non sent values.

https://github.com/raffaelj/cockpit_UniqueSlugs/blob/master/bootstrap.php#L48
https://github.com/raffaelj/cockpit_UniqueSlugs/blob/master/bootstrap.php#L137

Problems to solve that issue:

I could load the original entry to find the missing fields before comparing, but that would cause another avoidable database request and multiple new possible edge cases.

Checking against an empty slug field is a feature to reset the slug or to create it for older entries, that were created without or with misconfigured addon.

I'm not sure about an elegant solution. If anyone has ideas, please share them.

@raffaelj raffaelj closed this in d79c827 Sep 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.