Skip to content

Commit b13c01a

Browse files
committed
fix(import): cannot factorize deleteObsoleteItems
If the parent object is in itemtype_2 and items_id_2, it is not obvious to use this pair as FK Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent dd36614 commit b13c01a

7 files changed

+68
-20
lines changed

inc/condition.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,16 @@ function ($item) {
392392

393393
return $html;
394394
}
395+
396+
public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
397+
{
398+
$keepCriteria = [
399+
'itemtype' => $container->getType(),
400+
'items_id' => $container->getID(),
401+
];
402+
if (count($exclude) > 0) {
403+
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
404+
}
405+
return $this->deleteByCriteria($keepCriteria);
406+
}
395407
}

inc/exportable.class.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,4 @@ public function importChildrenObjects($item, $linker, $subItems, $input) {
128128
}
129129
}
130130
}
131-
132-
public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
133-
{
134-
if ($this instanceof CommonDBRelation) {
135-
$keepCriteria = [
136-
'itemtype' => $container->getType(),
137-
'items_id' => $container->getID(),
138-
];
139-
} else if ($this instanceof CommonDBChild) {
140-
$keepCriteria = [
141-
$container::getForeignKeyField() => $container->getID(),
142-
];
143-
} else {
144-
return true;
145-
}
146-
if (count($exclude) > 0) {
147-
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
148-
}
149-
return $this->deleteByCriteria($keepCriteria);
150-
}
151131
}

inc/form_profile.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,15 @@ public function export($remove_uuid = false) {
247247

248248
return $form_profile;
249249
}
250+
251+
public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
252+
{
253+
$keepCriteria = [
254+
self::$items_id_1 => $container->getID(),
255+
];
256+
if (count($exclude) > 0) {
257+
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
258+
}
259+
return $this->deleteByCriteria($keepCriteria);
260+
}
250261
}

inc/form_validator.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,15 @@ public function getValidatorsForForm(PluginFormcreatorForm $form, $itemtype) {
203203

204204
return $result;
205205
}
206+
207+
public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
208+
{
209+
$keepCriteria = [
210+
self::$items_id_1 => $container->getID(),
211+
];
212+
if (count($exclude) > 0) {
213+
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
214+
}
215+
return $this->deleteByCriteria($keepCriteria);
216+
}
206217
}

inc/item_targetticket.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,16 @@ public function prepareInputForAdd($input) {
171171
// }
172172
// return false;
173173
// }
174+
175+
public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
176+
{
177+
$keepCriteria = [
178+
self::$itemtype_2 => $container->getType(),
179+
self::$items_id_2 => $container->getID(),
180+
];
181+
if (count($exclude) > 0) {
182+
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
183+
}
184+
return $this->deleteByCriteria($keepCriteria);
185+
}
174186
}

inc/question.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,4 +1226,15 @@ public function post_getFromDB() {
12261226
$this->fields += self::getFullData(null, $this->fields['id']);
12271227
}
12281228
}
1229+
1230+
public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
1231+
{
1232+
$keepCriteria = [
1233+
self::$items_id => $container->getID(),
1234+
];
1235+
if (count($exclude) > 0) {
1236+
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
1237+
}
1238+
return $this->deleteByCriteria($keepCriteria);
1239+
}
12291240
}

inc/section.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,15 @@ public function post_addItem() {
430430
public function post_updateItem($history = 1) {
431431
$this->updateConditions($this->input);
432432
}
433+
434+
public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
435+
{
436+
$keepCriteria = [
437+
self::$items_id => $container->getID(),
438+
];
439+
if (count($exclude) > 0) {
440+
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
441+
}
442+
return $this->deleteByCriteria($keepCriteria);
443+
}
433444
}

0 commit comments

Comments
 (0)