Skip to content

Commit

Permalink
Update Rule::initRules() signature
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Oct 8, 2024
1 parent 39c0d77 commit a7ff590
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ The present file will list all changes made to the project; according to the
- `Group::getDataItems()` signature changed. The two first parameters `$types` and `$field` were replaced
by a unique boolean `$tech` parameter that is used to compute the `$types` and `$field` values automatically.
- `CartridgeItem::addCompatibleType()` method is now static.
- `Rule::initRule()` has been made final and non static and its signature changed.
- `Transfer` class is now final.
- `Transfer::addNotToBeTransfer()` method is now private.
- `Transfer::addToAlreadyTransfer()` method is now private.
Expand Down
2 changes: 1 addition & 1 deletion src/Glpi/Asset/Capacity/IsInventoriableCapacity.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function onClassBootstrap(string $classname): void

//create rules
$rules = new \RuleImportAsset();
$rules->initRules(true, false, false, $classname);
$rules->initRules(true, $classname);
}

public function onCapacityDisabled(string $classname): void
Expand Down
2 changes: 1 addition & 1 deletion src/Glpi/Rules/RulesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function initializeRules(): void
}

if (countElementsInTable(Rule::getTable(), ['sub_type' => $ruleclass->getType()]) === 0) {
$ruleclass->initRules(false, false, false);
$ruleclass->initRules(false);
}

// Mark collection as already initialized, to not reinitialize it on next update
Expand Down
17 changes: 5 additions & 12 deletions src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3386,17 +3386,12 @@ public static function getConditionsWithComplexValues(): array
/**
* Create rules (initialisation).
*
* @param boolean $reset Whether to reset before adding new rules, defaults to true
* @param boolean $with_plugins Use plugins rules or not
* @param boolean $check Check if rule exists before creating
* @param ?string $itemtype Itemtype to work on
* @param bool $reset Whether to reset before adding new rules, defaults to true
* @param ?string $itemtype Itemtype to work on
*
* @return boolean
*
* @FIXME Make it final in GLPI 11.0.
* @FIXME Remove $reset, $with_plugins and $check parameters in GLPI 11.0, they are actually not used or have no effect where they are used.
* @return bool
*/
public function initRules(bool $reset = true, $with_plugins = true, $check = true, string $itemtype = null): bool
final public function initRules(bool $reset = true, ?string $itemtype = null): bool
{
/** @var DBmysql $DB */
global $DB;
Expand Down Expand Up @@ -3428,8 +3423,6 @@ public function initRules(bool $reset = true, $with_plugins = true, $check = tru
if (!$DB->delete(self::getTable(), $where, $joins)) {
return false; // Do not continue if reset failed
}

$check = false; // Nothing to check
}

$xml = $this->getDefaultRules();
Expand Down Expand Up @@ -3483,7 +3476,7 @@ public function initRules(bool $reset = true, $with_plugins = true, $check = tru

$rule = new static();

if ($check === true && $rule->getFromDBByCrit(['uuid' => (string)$rulexml->uuid])) {
if ($reset !== false && $rule->getFromDBByCrit(['uuid' => (string)$rulexml->uuid])) {
// Rule already exists, ignore it.
continue;
}
Expand Down

0 comments on commit a7ff590

Please sign in to comment.