Skip to content
Permalink
Browse files

fixed slug overwrite on partial data update, fixes #3

  • Loading branch information...
raffaelj committed Sep 8, 2019
1 parent 2ea8cd1 commit d79c827e2e1d670960ec09139b81c669381835bc
Showing with 26 additions and 6 deletions.
  1. +4 −0 CHANGELOG.md
  2. +22 −6 bootstrap.php
@@ -1,5 +1,9 @@
# Changelog

## 0.5.2

* fixed overwriting of slug when saving only partial data (via custom php script or via api)

## 0.5.1

* fixed: GUI didn't save on first run, because of a wrong variable type (empty object/array)
@@ -5,7 +5,7 @@
* @see https://github.com/raffaelj/cockpit_UniqueSlugs/
* @see https://github.com/agentejo/cockpit/
*
* @version 0.5.1
* @version 0.5.2
* @author Raffael Jesche
* @license MIT
*/
@@ -44,8 +44,12 @@
// get field name
if (isset($config['collections'][$name])) {
// generate slug on create only or when an existing one is empty
if (!$isUpdate || ($isUpdate && empty($entry[$slugName]))) {
// generate slug on create only or when an existing one is an empty string
if (!$isUpdate
|| ($isUpdate
&& isset($entry[$slugName])
&& $entry[$slugName] == ''))
{
$fld = $config['collections'][$name];
$fld = is_array($fld) ? $fld : [$fld];
@@ -61,7 +65,11 @@
}
elseif (!empty($config['check_on_update']) && $isUpdate && !empty($entry[$slugName])) {
elseif (!empty($config['check_on_update'])
&& $isUpdate
&& isset($entry[$slugName])
&& $entry[$slugName] == '')
{
// never trust user input ;-)
$slug = $this->app->helper('utils')->sluggify($entry[$slugName]);
@@ -88,7 +96,11 @@
if ($locale == 'default') continue;
if (!$isUpdate || ($isUpdate && empty($entry[$slugName.'_'.$locale]))) {
if (!$isUpdate
|| ($isUpdate
&& isset($entry[$slugName.'_'.$locale])
&& $entry[$slugName.'_'.$locale] == ''))
{
$fld = $config['localize'][$name];
$fld = is_array($fld) ? $fld : [$fld];
@@ -104,7 +116,11 @@
}
elseif (!empty($config['check_on_update']) && $isUpdate && !empty($entry[$slugName.'_'.$locale])) {
elseif (!empty($config['check_on_update'])
&& $isUpdate
&& isset($entry[$slugName.'_'.$locale])
&& $entry[$slugName.'_'.$locale] == '')
{
// never trust user input ;-)
$slug = $this->app->helper('utils')->sluggify($entry[$slugName.'_'.$locale]);

0 comments on commit d79c827

Please sign in to comment.
You can’t perform that action at this time.