Skip to content

Commit

Permalink
Fix raw SQL
Browse files Browse the repository at this point in the history
Fix locales
  • Loading branch information
tsmr committed Nov 25, 2024
1 parent c45e16b commit 97477df
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 39 deletions.
26 changes: 14 additions & 12 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function plugin_accounts_uninstall()
"glpi_plugin_accounts_notificationstates"];

foreach ($tables as $table) {
$DB->query("DROP TABLE IF EXISTS `$table`;");
$DB->dropTable($table);
}

//old versions
Expand All @@ -347,7 +347,7 @@ function plugin_accounts_uninstall()
"glpi_plugin_accounts_profiles"];

foreach ($tables as $table) {
$DB->query("DROP TABLE IF EXISTS `$table`;");
$DB->dropTable($table);
}

$notif = new Notification();
Expand Down Expand Up @@ -401,18 +401,20 @@ function plugin_accounts_uninstall()
"glpi_impactitems"];

foreach ($tables_glpi as $table_glpi) {
$DB->query("DELETE FROM `$table_glpi`
WHERE `itemtype` = 'PluginAccountsAccount'
OR `itemtype` = 'PluginAccountsHelpdesk'
OR `itemtype` = 'PluginAccountsGroup'
OR `itemtype` = 'PluginAccountsAccountState'
OR `itemtype` = 'PluginAccountsAccountType' ;");
$DB->delete($table_glpi, ['itemtype' => ['LIKE' => 'PluginAccounts%']]);
}

$DB->query("DELETE
FROM `glpi_impactrelations`
WHERE `itemtype_source` IN ('PluginAccountsAccount')
OR `itemtype_impacted` IN ('PluginAccountsAccount')");

$DB->delete('glpi_impactrelations', [
'OR' => [
[
'itemtype_source' => ['PluginAccountsAccount'],
],
[
'itemtype_impacted' => ['PluginAccountsAccount'],
],
]
]);

if (class_exists('PluginDatainjectionModel')) {
PluginDatainjectionModel::clean(['itemtype' => 'PluginAccountsAccount']);
Expand Down
8 changes: 4 additions & 4 deletions inc/account.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function rawSearchOptions()
'table' => 'glpi_users',
'field' => 'name',
'linkfield' => 'users_id_tech',
'name' => __('Technician in charge of the hardware'),
'name' => __('Technician in charge'),
'datatype' => 'dropdown',
'right' => 'interface'
];
Expand All @@ -297,7 +297,7 @@ public function rawSearchOptions()
'table' => 'glpi_groups',
'field' => 'completename',
'linkfield' => 'groups_id_tech',
'name' => __('Group in charge of the hardware'),
'name' => __('Group in charge'),
'condition' => ['`is_assign`' => 1],
'datatype' => 'dropdown'
];
Expand Down Expand Up @@ -675,7 +675,7 @@ public function showForm($ID, $options = [])
Html::showDateField("date_creation", ['value' => $this->fields["date_creation"]]);
echo "</td>";

echo "<td>" . __('Technician in charge of the hardware') . "</td>";
echo "<td>" . __('Technician in charge') . "</td>";
echo "<td>";
User::dropdown(['name' => "users_id_tech",
'value' => $this->fields["users_id_tech"],
Expand All @@ -694,7 +694,7 @@ public function showForm($ID, $options = [])
Html::showDateField("date_expiration", ['value' => $this->fields["date_expiration"]]);
echo "</td>";

echo "<td>" . __('Group in charge of the hardware') . "</td><td>";
echo "<td>" . __('Group in charge') . "</td><td>";
Group::dropdown(['name' => 'groups_id_tech',
'value' => $this->fields['groups_id_tech'],
'condition' => ['is_assign' => 1]]);
Expand Down
1 change: 0 additions & 1 deletion inc/notificationstate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public function showNotificationForm($target) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
Html::closeForm();
echo "</div>";
}
}
Expand Down
16 changes: 8 additions & 8 deletions inc/notificationtargetaccount.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function getEvents() {
public function addAdditionalTargets($event = '') {
$this->addTarget(self::ACCOUNT_USER, __('Affected User', 'accounts'));
$this->addTarget(self::ACCOUNT_GROUP, __('Affected Group', 'accounts'));
$this->addTarget(self::ACCOUNT_TECHUSER, __('Technician in charge of the hardware'));
$this->addTarget(self::ACCOUNT_TECHGROUP, __('Group in charge of the hardware'));
$this->addTarget(self::ACCOUNT_TECHUSER, __('Technician in charge'));
$this->addTarget(self::ACCOUNT_TECHGROUP, __('Group in charge'));
}

/**
Expand Down Expand Up @@ -181,10 +181,10 @@ public function addDataForTemplate($event, $options = []) {
$this->data['##account.groups##'] = Dropdown::getDropdownName('glpi_groups',
$this->obj->getField('groups_id'));

$this->data['##lang.account.userstech##'] = __('Technician in charge of the hardware');
$this->data['##lang.account.userstech##'] = __('Technician in charge');
$this->data['##account.userstech##'] = $dbu->getUserName($this->obj->getField("users_id_tech"));

$this->data['##lang.account.groupstech##'] = __('Group in charge of the hardware');
$this->data['##lang.account.groupstech##'] = __('Group in charge');
$this->data['##account.groupstech##'] = Dropdown::getDropdownName('glpi_groups',
$this->obj->getField('groups_id_tech'));

Expand Down Expand Up @@ -225,8 +225,8 @@ public function addDataForTemplate($event, $options = []) {
$this->data['##lang.account.login##'] = __('Login');
$this->data['##lang.account.users##'] = __('Affected User', 'accounts');
$this->data['##lang.account.groups##'] = __('Affected Group', 'accounts');
$this->data['##lang.account.userstech##'] = __('Technician in charge of the hardware');
$this->data['##lang.account.groupstech##'] = __('Group in charge of the hardware');
$this->data['##lang.account.userstech##'] = __('Technician in charge');
$this->data['##lang.account.groupstech##'] = __('Group in charge');
$this->data['##lang.account.location##'] = __('Location');
$this->data['##lang.account.others##'] = __('Others');
$this->data['##lang.account.datecreation##'] = __('Creation date');
Expand Down Expand Up @@ -275,8 +275,8 @@ function getTags() {
'account.login' => __('Login'),
'account.users' => __('Affected User', 'accounts'),
'account.groups' => __('Affected Group', 'accounts'),
'account.userstech' => __('Technician in charge of the hardware'),
'account.groupstech' => __('Group in charge of the hardware'),
'account.userstech' => __('Technician in charge'),
'account.groupstech' => __('Group in charge'),
'account.location' => __('Location'),
'account.others' => __('Others'),
'account.datecreation' => __('Creation date'),
Expand Down
35 changes: 22 additions & 13 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,22 @@ public static function migrateOneProfile($profiles_id)
return true;
}

foreach ($DB->request(
'glpi_plugin_accounts_profiles',
"`profiles_id`='$profiles_id'"
) as $profile_data) {
$it = $DB->request([
'FROM' => 'glpi_plugin_accounts_profiles',
'WHERE' => ['profiles_id' => $profiles_id]
]);
foreach ($it as $profile_data) {
$matching = ['accounts' => 'plugin_accounts',
'all_users' => 'plugin_accounts_see_all_users',
'my_groups' => 'plugin_accounts_my_groups',
'open_ticket' => 'plugin_accounts_open_ticket'];
$current_rights = ProfileRight::getProfileRights($profiles_id, array_values($matching));
foreach ($matching as $old => $new) {
if (!isset($current_rights[$old])) {
$query = "UPDATE `glpi_profilerights`
SET `rights`='" . self::translateARight($profile_data[$old]) . "'
WHERE `name`='$new' AND `profiles_id`='$profiles_id'";
$DB->query($query);
$DB->update('glpi_profilerights', ['rights' => self::translateARight($profile_data[$old])], [
'name' => $new,
'profiles_id' => $profiles_id
]);
}
}
}
Expand All @@ -317,13 +318,21 @@ public static function initProfile()
}

//Migration old rights in new ones
foreach ($DB->request("SELECT `id` FROM `glpi_profiles`") as $prof) {
$it = $DB->request([
'SELECT' => ['id'],
'FROM' => 'glpi_profiles'
]);
foreach ($it as $prof) {
self::migrateOneProfile($prof['id']);
}
foreach ($DB->request("SELECT *
FROM `glpi_profilerights`
WHERE `profiles_id`='" . $_SESSION['glpiactiveprofile']['id'] . "'
AND `name` LIKE '%plugin_accounts%'") as $prof) {
$it = $DB->request([
'FROM' => 'glpi_profilerights',
'WHERE' => [
'profiles_id' => $_SESSION['glpiactiveprofile']['id'],
'name' => ['LIKE', '%plugin_accounts%']
]
]);
foreach ($it as $prof) {
if (isset($_SESSION['glpiactiveprofile'])) {
$_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights'];
}
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function plugin_version_accounts()
'version' => PLUGIN_ACCOUNTS_VERSION,
'oldname' => 'compte',
'license' => 'GPLv2+',
'author' => "<a href='http://infotel.com/services/expertise-technique/glpi/'>Infotel</a>, Franck Waechter",
'author' => "<a href='https://blogglpi.infotel.com'>Infotel</a>, Franck Waechter",
'homepage' => 'https://github.com/InfotelGLPI/accounts',
'requirements' => [
'glpi' => [
Expand Down

0 comments on commit 97477df

Please sign in to comment.