static function addDefaultProfileInfos($profiles_id, $rights) { $profileRight = new ProfileRight(); foreach ($rights as $right => $value) { if (!countElementsInTable('glpi_profilerights', "`profiles_id`='{$profiles_id}' AND `name`='{$right}'")) { $myright['profiles_id'] = $profiles_id; $myright['name'] = $right; $myright['rights'] = $value; $profileRight->add($myright); //Add right to the current session $_SESSION['glpiactiveprofile'][$right] = $value; } } }
/** * @param $profile **/ static function addDefaultProfileInfos($profiles_id, $rights, $drop_existing = false) { $profileRight = new ProfileRight(); foreach ($rights as $right => $value) { if (countElementsInTable('glpi_profilerights', "`profiles_id`='{$profiles_id}' AND `name`='{$right}'") && $drop_existing) { $profileRight->deleteByCriteria(array('profiles_id' => $profiles_id, 'name' => $right)); } if (!countElementsInTable('glpi_profilerights', "`profiles_id`='{$profiles_id}' AND `name`='{$right}'")) { $myright['profiles_id'] = $profiles_id; $myright['name'] = $right; $myright['rights'] = $value; $profileRight->add($myright); //Add right to the current session $_SESSION['glpiactiveprofile'][$right] = $value; } } }
static function install(Migration $migration) { global $DB; $profileRight = new ProfileRight(); $profile = new Profile(); //Update needed if (TableExists('glpi_plugin_genericobject_profiles')) { foreach (getAllDatasFromTable('glpi_plugin_genericobject_profiles') as $right) { if (preg_match("/PluginGenericobject(.*)/", $right['itemtype'], $results)) { $newrightname = 'plugin_genericobject_' . strtolower($results[1]) . 's'; if (!countElementsInTable('glpi_profilerights', "`profiles_id`='" . $right['profiles_id'] . "' \n AND `name`='{$newrightname}'")) { switch ($right['right']) { case NULL: case '': $rightvalue = 0; break; case 'r': $rightvalue = READ; break; case 'w': $rightvalue = ALLSTANDARDRIGHT; break; } $profileRight->add(array('profiles_id' => $right['profiles_id'], 'name' => $newrightname, 'rights' => $rightvalue)); if (!countElementsInTable('glpi_profilerights', "`profiles_id`='" . $right['profiles_id'] . "' \n AND `name`='plugin_genericobject_types'")) { $profileRight->add(array('profiles_id' => $right['profiles_id'], 'name' => 'plugin_genericobject_types', 'rights' => 23)); } } if ($right['open_ticket']) { $profile->getFromDB($right['profiles_id']); $helpdesk_item_types = json_decode($profile->fields['helpdesk_item_type'], true); if (is_array($helpdesk_item_types)) { if (!in_array($right['itemtype'], $helpdesk_item_types)) { $helpdesk_item_types[] = $right['itemtype']; } } else { $helpdesk_item_types = array($right['itemtype']); } $tmp['id'] = $profile->getID(); $tmp['helpdesk_item_type'] = json_encode($helpdesk_item_types); $profile->update($tmp); } } } //$migration->dropTable('glpi_plugin_genericobject_profiles'); } if (!countElementsInTable('glpi_profilerights', "`name` LIKE '%genericobject%'")) { self::createFirstAccess(); } }
static function install() { global $DB; if (TableExists('glpi_plugin_reports_profiles')) { if (FieldExists('glpi_plugin_reports_profiles', 'ID')) { // version installee < 1.4.0 $query = "ALTER TABLE `glpi_plugin_reports_profiles`\n CHANGE `ID` `id` int(11) NOT NULL auto_increment"; $DB->queryOrDie($query, "CHANGE ID: " . $DB->error()); } if (!FieldExists('glpi_plugin_reports_profiles', 'profiles_id')) { // version < 1.5.0 $query = "RENAME TABLE `glpi_plugin_reports_profiles`\n TO `glpi_plugin_reports_oldprofiles`"; $DB->query($query) or die("SAVE TABLE profiles: " . $DB->error()); $DB->query($create) or die("CREATE TABLE profiles: " . $DB->error()); $fields = $DB->list_fields('glpi_plugin_reports_oldprofiles'); unset($fields['id']); unset($fields['profile']); foreach ($fields as $field => $descr) { $query = "INSERT INTO `glpi_plugin_reports_profiles`\n (`profiles_id`, `report`, `access`)\n SELECT `id`, '{$field}', `{$field}`\n FROM `glpi_plugin_reports_oldprofiles`\n WHERE `{$field}` IS NOT NULL"; $DB->query($query) or die("LOAD TABLE profiles: " . $DB->error()); } $query = "DROP TABLE `glpi_plugin_reports_oldprofiles`"; $DB->query($query) or die("DROP TABLE oldprofiles: " . $DB->error()); } // -- SINCE 0.85 -- //Add new rights in glpi_profilerights table $profileRight = new ProfileRight(); $query = "SELECT *\n FROM `glpi_plugin_reports_profiles`"; foreach ($DB->request($query) as $data) { $right['profiles_id'] = $data['profiles_id']; $right['name'] = "plugin_reports_" . $data['report']; $droit = $data['access']; if ($droit == 'r') { $right['rights'] = 1; $profileRight->add($right); } } $DB->query("DROP TABLE `glpi_plugin_reports_profiles`"); } else { // new install } return true; }
/** * * * @since 1.3 **/ static function upgrade(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); switch (plugin_simcard_currentVersion()) { case '1.3': case '1.3.1': $query = "SELECT * FROM `glpi_plugin_simcard_profiles`"; $result = $DB->query($query); while ($data = $DB->fetch_assoc($result)) { // Write the access rights into the new ACLs system of GLPI 0.85 $translatedRight = self::translateARight($data['simcard']) + self::translateARight($data['open_ticket']); if ($translatedRight & READ) { $translatedRight = $translatedRight | READNOTE; } if ($translatedRight & UPDATE) { $translatedRight = $translatedRight | READNOTE | UPDATENOTE; } $profileRight = new ProfileRight(); $profileRightFields['profiles_id'] = $data['profiles_id']; $profileRightFields['name'] = self::RIGHT_SIMCARD_SIMCARD; $profileRightFields['rights'] = $translatedRight; if ($profileRight->add($profileRightFields) === false) { die('Fatal error migrating profile rights'); } // The plugin is not yet active, the hook will not trigger automatically plugin_simcard_profileRightUpdate($profileRight); } $query = "DROP TABLE `glpi_plugin_simcard_profiles`"; $DB->query($query) or die($DB->error()); break; case '1.4': case '1.4.1': } }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (isset($_SESSION['glpiactiveprofile'])) { PluginGeninventorynumberProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); } if (TableExists("glpi_plugin_geninventorynumber_profiles")) { foreach (getAllDatasFromTable($table) as $data) { $profile = new self(); foreach ($profile->getAllRights() as $right => $rights) { if (!countElementsInTable('glpi_profilerights', "`profiles_id`='" . $data['profiles_id'] . "' \n AND `name`='" . $rights['field'] . "'")) { $profileRight = new ProfileRight(); $myright = array(); $myright['name'] = $rights['field']; $myright['profiles_id'] = $data['profiles_id']; if (!strcmp($data['plugin_geninventorynumber_generate'], 'w')) { $myright['rights'] = CREATE; } if (!strcmp($data['plugin_geninventorynumber_overwrite'], 'w')) { $myright['rights'] += UPDATE; } $profileRight->add($myright); } } } $migration->dropTable($table); } }