Skip to content

Commit

Permalink
fix(import): cannot factorize deleteObsoleteItems
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
btry committed Jun 4, 2020
1 parent dd36614 commit b13c01a
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 20 deletions.
12 changes: 12 additions & 0 deletions inc/condition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,16 @@ function ($item) {

return $html;
}

public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
{
$keepCriteria = [
'itemtype' => $container->getType(),
'items_id' => $container->getID(),
];
if (count($exclude) > 0) {
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
}
return $this->deleteByCriteria($keepCriteria);
}
}
20 changes: 0 additions & 20 deletions inc/exportable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,4 @@ public function importChildrenObjects($item, $linker, $subItems, $input) {
}
}
}

public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
{
if ($this instanceof CommonDBRelation) {
$keepCriteria = [
'itemtype' => $container->getType(),
'items_id' => $container->getID(),
];
} else if ($this instanceof CommonDBChild) {
$keepCriteria = [
$container::getForeignKeyField() => $container->getID(),
];
} else {
return true;
}
if (count($exclude) > 0) {
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
}
return $this->deleteByCriteria($keepCriteria);
}
}
11 changes: 11 additions & 0 deletions inc/form_profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,15 @@ public function export($remove_uuid = false) {

return $form_profile;
}

public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
{
$keepCriteria = [
self::$items_id_1 => $container->getID(),
];
if (count($exclude) > 0) {
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
}
return $this->deleteByCriteria($keepCriteria);
}
}
11 changes: 11 additions & 0 deletions inc/form_validator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,15 @@ public function getValidatorsForForm(PluginFormcreatorForm $form, $itemtype) {

return $result;
}

public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
{
$keepCriteria = [
self::$items_id_1 => $container->getID(),
];
if (count($exclude) > 0) {
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
}
return $this->deleteByCriteria($keepCriteria);
}
}
12 changes: 12 additions & 0 deletions inc/item_targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,16 @@ public function prepareInputForAdd($input) {
// }
// return false;
// }

public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
{
$keepCriteria = [
self::$itemtype_2 => $container->getType(),
self::$items_id_2 => $container->getID(),
];
if (count($exclude) > 0) {
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
}
return $this->deleteByCriteria($keepCriteria);
}
}
11 changes: 11 additions & 0 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1226,4 +1226,15 @@ public function post_getFromDB() {
$this->fields += self::getFullData(null, $this->fields['id']);
}
}

public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
{
$keepCriteria = [
self::$items_id => $container->getID(),
];
if (count($exclude) > 0) {
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
}
return $this->deleteByCriteria($keepCriteria);
}
}
11 changes: 11 additions & 0 deletions inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,15 @@ public function post_addItem() {
public function post_updateItem($history = 1) {
$this->updateConditions($this->input);
}

public function deleteObsoleteItems(CommonDBTM $container, array $exclude)
{
$keepCriteria = [
self::$items_id => $container->getID(),
];
if (count($exclude) > 0) {
$keepCriteria[] = ['NOT' => ['id' => $exclude]];
}
return $this->deleteByCriteria($keepCriteria);
}
}

0 comments on commit b13c01a

Please sign in to comment.