Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rule::initRules() signature #18031

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading