Repository navigation
Conversation
stonebuzz
left a comment
There was a problem hiding this comment.
plugin_mreporting_install() calls addRightToAllProfiles() (inserts right = NULL for every profile, super-admin included) before addRightToProfile() (READ for super-admins). Previously the second call overwrote NULL with READ; now it sees the row already exists and skips it. Result: on a fresh install, and for every new report created by createFirstConfig() during an update, super-admin profiles end up with no access. Swapping the two calls restores the intended defaults without touching existing rights.
PluginMreportingProfile::addRightToProfile();
PluginMreportingProfile::addRightToAllProfiles();| // Only create the missing profile/report combinations, never overwrite an existing right | ||
| foreach ($profiles_ids as $profile_id) { | ||
| foreach ($reports_ids as $report_id) { | ||
| $already_exists = $DB->request([ |
There was a problem hiding this comment.
One COUNT query per profile × report pair (N+1), in both methods. With e.g. 40 profiles and 70 reports that is 2800 queries on each install/update, and addRightToProfile() also runs on every profile creation. Fetch existing pairs once and check in memory.
$existing = [];
foreach ($DB->request(['SELECT' => ['profiles_id', 'reports'], 'FROM' => self::getTable()]) as $row) {
$existing[$row['profiles_id'] . '-' . $row['reports']] = true;
}
// then: if (!isset($existing[$profile_id . '-' . $report_id])) { $DB->insert(...); }| $reports = $config->find(); | ||
|
|
||
| // Only create the missing profile/report combinations, never overwrite an existing right | ||
| foreach ($profiles_ids as $profileId) { |
There was a problem hiding this comment.
The insert-if-missing loop is duplicated verbatim in both methods, only the profile list and the default right differ. A private helper (array $profiles_ids, ?int $right) would remove the duplication.
Checklist before requesting a review
Please delete options that are not relevant.
Description
Screenshots (if appropriate):