Skip to content

Commit d78c0bb

Browse files
stonebuzzRom1-B
andauthored
Fix warning during CLI installation (#314)
* Fix(Core): prevent warning during CLI installation * apply review * Apply suggestions from code review --------- Co-authored-by: Romain B. <[email protected]>
1 parent 727c29c commit d78c0bb

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [UNRELEASED]
99

10+
### Fixed
11+
12+
- Fix warning during CLI installation
1013

1114
## [1.9.1] - 2025-10-27
1215

hook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function plugin_mreporting_install()
246246
$config->createFirstConfig();
247247

248248
PluginMreportingProfile::addRightToAllProfiles();
249-
PluginMreportingProfile::addRightToProfile($_SESSION['glpiactiveprofile']['id']);
249+
PluginMreportingProfile::addRightToProfile();
250250

251251
return true;
252252
}

inc/profile.class.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,31 @@ public static function getRight()
204204
* Function to add right on report to a profile
205205
* @param $idProfile
206206
*/
207-
public static function addRightToProfile($idProfile)
207+
public static function addRightToProfile(?int $idProfile = null): void
208208
{
209209
/** @var DBmysql $DB */
210210
global $DB;
211211

212-
//get all reports
212+
$profiles_ids = [];
213+
$profiles_ids = is_null($idProfile) ? Profile::getSuperAdminProfilesId() : [$idProfile];
214+
213215
$config = new PluginMreportingConfig();
214-
foreach ($config->find() as $report) {
215-
// add right for any reports for profile
216-
// Add manual request because Add function get error : right is set to NULL
217-
if (!$DB->updateOrInsert('glpi_plugin_mreporting_profiles', [
218-
'profiles_id' => $idProfile,
219-
'reports' => $report['id'],
220-
'right' => READ,
221-
], [
222-
'profiles_id' => $idProfile,
223-
'reports' => $report['id'],
224-
])) {
225-
return;
216+
$reports = $config->find();
217+
218+
foreach ($profiles_ids as $profileId) {
219+
foreach ($reports as $report) {
220+
$DB->updateOrInsert(
221+
'glpi_plugin_mreporting_profiles',
222+
[
223+
'profiles_id' => $profileId,
224+
'reports' => $report['id'],
225+
'right' => READ,
226+
],
227+
[
228+
'profiles_id' => $profileId,
229+
'reports' => $report['id'],
230+
],
231+
);
226232
}
227233
}
228234
}

0 commit comments

Comments
 (0)