You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if ( !str_starts_with($body['links'][$j]['href'], $this->context->core['baseUrl'] . RestoRouter::ROUTE_TO_CATALOGS ) ) {
514
+
continue;
515
+
}
516
+
if ($catalogs[$i]['id'] === substr($body['links'][$j]['href'], strlen($this->context->core['baseUrl'] . RestoRouter::ROUTE_TO_CATALOGS) + 1)) {
517
+
$levelUp[$catalogs[$i]['id']] = true;
518
+
break;
519
+
}
520
+
}
521
+
}
522
+
$removed = 0;
523
+
foreach (array_keys($levelUp) as$key) {
524
+
if ( $levelUp[$key] === false ) {
525
+
$removed++;
526
+
}
527
+
}
528
+
529
+
if ($removed > 0) {
530
+
return RestoLogUtil::httpError(400, 'The catalog update would remove ' . $removed . ' existing child(s). Set **_force** query parameter to true to force update anyway');
return RestoLogUtil::httpError(400, 'The catalog contains ' . ($count - 1) . ' child(s) and cannot be deleted. Set **_force** query parameter to true to force deletion anyway');
@@ -292,16 +295,38 @@ public function updateCatalog($catalog, $userid, $context)
292
295
$this->dbDriver->query('BEGIN');
293
296
294
297
/*
295
-
* Delete all catalog childs BUT NOT HIMSELF
298
+
* Delete catalog childs BUT NOT HIMSELF and the one in childIds
296
299
*/
297
-
$this->dbDriver->fetch($this->dbDriver->pQuery('DELETE FROM ' . $this->dbDriver->targetSchema . '.catalog WHERE lower(id) LIKE lower($1) RETURNING id', array(
$this->dbDriver->fetch($this->dbDriver->pQuery('DELETE FROM ' . $this->dbDriver->targetSchema . '.catalog_feature WHERE path ~ $1 AND path <> $2' , array(
301
-
RestoUtil::path2ltree($catalog['id']) . '.*',
302
-
RestoUtil::path2ltree($catalog['id'])
303
-
), 500, 'Cannot delete catalog_feature association for catalog ' . $catalog['id']));
304
-
300
+
if ( array_key_exists('links', $cleanLinks) ) {
301
+
302
+
// No childIds => easy !
303
+
if ( empty($cleanLinks['childIds']) ) {
304
+
$this->dbDriver->fetch($this->dbDriver->pQuery('DELETE FROM ' . $this->dbDriver->targetSchema . '.catalog WHERE lower(id) LIKE lower($1) RETURNING id', array(
$this->dbDriver->fetch($this->dbDriver->pQuery('DELETE FROM ' . $this->dbDriver->targetSchema . '.catalog WHERE lower(id) LIKE lower($1) AND lower(id) NOT IN (' . join(',', $lowerIds) . ') RETURNING id', array(
$this->dbDriver->fetch($this->dbDriver->pQuery('DELETE FROM ' . $this->dbDriver->targetSchema . '.catalog_feature WHERE path ~ $1 AND path NOT IN (' . join(',', $paths) . ')' , array(
323
+
RestoUtil::path2ltree($catalog['id']) . '.*'
324
+
), 500, 'Cannot update catalog_feature association for catalog ' . $catalog['id']));
325
+
326
+
}
327
+
328
+
}
329
+
305
330
/*
306
331
* Then update catalog
307
332
*/
@@ -310,9 +335,11 @@ public function updateCatalog($catalog, $userid, $context)
310
335
/*
311
336
* Add an entry in catalog_feature for each interalItems but first remove all items !
0 commit comments