function glpiautoload($classname) { global $DEBUG_AUTOLOAD, $CFG_GLPI; static $notfound = array(); // empty classname or non concerted plugin if (empty($classname) || is_numeric($classname)) { return FALSE; } $dir = GLPI_ROOT . "/inc/"; //$classname="PluginExampleProfile"; if ($plug = isPluginItemType($classname)) { $plugname = strtolower($plug['plugin']); $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/"; $item = strtolower($plug['class']); // Is the plugin activate ? // Command line usage of GLPI : need to do a real check plugin activation if (isCommandLine()) { $plugin = new Plugin(); if (count($plugin->find("directory='{$plugname}' AND state=" . Plugin::ACTIVATED)) == 0) { // Plugin does not exists or not activated return FALSE; } } else { // Standard use of GLPI if (!in_array($plugname, $_SESSION['glpi_plugins'])) { // Plugin not activated return FALSE; } } } else { // Is ezComponent class ? $matches = array(); if (preg_match('/^ezc([A-Z][a-z]+)/', $classname, $matches)) { include_once GLPI_EZC_BASE; ezcBase::autoload($classname); return TRUE; } else { $item = strtolower($classname); } } // No errors for missing classes due to implementation if (!isset($CFG_GLPI['missingclasses']) or !in_array($item, $CFG_GLPI['missingclasses'])) { if (file_exists("{$dir}{$item}.class.php")) { include_once "{$dir}{$item}.class.php"; if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { $DEBUG_AUTOLOAD[] = $classname; } } else { if (!isset($notfound["{$classname}"])) { // trigger an error to get a backtrace, but only once (use prefix 'x' to handle empty case) //Toolbox::logInFile('debug', "file $dir$item.class.php not founded trying to load class $classname\n"); trigger_error("GLPI autoload : file {$dir}{$item}.class.php not founded trying to load class '{$classname}'"); $notfound["{$classname}"] = TRUE; } } } }
function plugin_mreporting_install() { global $DB; //get version $plugin = new Plugin(); $found = $plugin->find("name = 'mreporting'"); $plugin_mreporting = array_shift($found); //init migration $migration = new Migration($plugin_mreporting['version']); //create profiles table $queries = array(); $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_profiles` (\n `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\n `profiles_id` VARCHAR(45) NOT NULL,\n `reports` CHAR(1),\n `config` CHAR(1),\n PRIMARY KEY (`id`)\n )\n ENGINE = MyISAM;"; //create configuration table $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_configs` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `classname` varchar(255) collate utf8_unicode_ci default NULL,\n `is_active` tinyint(1) NOT NULL default '0',\n `is_notified` tinyint(1) NOT NULL default '1',\n `show_graph` tinyint(1) NOT NULL default '0',\n `show_area` tinyint(1) NOT NULL default '0',\n `spline` tinyint(1) NOT NULL default '0',\n `show_label` VARCHAR(10) default NULL,\n `flip_data` tinyint(1) NOT NULL default '0',\n `unit` VARCHAR(10) default NULL,\n `default_delay` VARCHAR(10) default NULL,\n `condition` VARCHAR(255) default NULL,\n `graphtype` VARCHAR(255) default 'GLPI',\n PRIMARY KEY (`id`),\n KEY `is_active` (`is_active`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_preferences` (\n `id` int(11) NOT NULL auto_increment,\n `users_id` int(11) NOT NULL default 0,\n `template` varchar(255) collate utf8_unicode_ci default NULL,\n PRIMARY KEY (`id`),\n KEY `users_id` (`users_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; // add display preferences $query_display_pref = "SELECT id \n FROM glpi_displaypreferences\n WHERE itemtype = 'PluginMreportingConfig'"; $res_display_pref = $DB->query($query_display_pref); if ($DB->numrows($res_display_pref) == 0) { $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','2','2','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','3','3','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','4','4','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','5','5','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','6','6','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','8','8','0');"; } $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_notifications` (\n `id` int(11) NOT NULL auto_increment,\n `entities_id` int(11) NOT NULL default '0',\n `is_recursive` tinyint(1) NOT NULL default '0',\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `notepad` longtext collate utf8_unicode_ci,\n `date_envoie` DATE DEFAULT NULL,\n `notice`INT(11) NOT NULL DEFAULT 0,\n `alert` INT(11) NOT NULL DEFAULT 0,\n `comment` text collate utf8_unicode_ci,\n `date_mod` datetime default NULL,\n `is_deleted` tinyint(1) NOT NULL default '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; foreach ($queries as $query) { $DB->query($query); } // == Update to 2.1 == if (!FieldExists('glpi_plugin_mreporting_configs', 'is_notified')) { $migration->addField('glpi_plugin_mreporting_configs', 'is_notified', 'tinyint(1) NOT NULL default "1"', array('after' => 'is_active')); $migration->migrationOneTable('glpi_plugin_mreporting_configs'); } require_once "inc/profile.class.php"; PluginMreportingProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); $rep_files_mreporting = GLPI_PLUGIN_DOC_DIR . "/mreporting"; if (!is_dir($rep_files_mreporting)) { mkdir($rep_files_mreporting); } $notifications_folder = GLPI_PLUGIN_DOC_DIR . "/mreporting/notifications"; if (!is_dir($notifications_folder)) { mkdir($notifications_folder); } require_once "inc/notification.class.php"; PluginMreportingNotification::install(); CronTask::Register('PluginMreportingNotification', 'SendNotifications', MONTH_TIMESTAMP); require_once "inc/baseclass.class.php"; require_once "inc/common.class.php"; require_once "inc/config.class.php"; $config = new PluginMreportingConfig(); $config->createFirstConfig(); return true; }
/** * Get module id or fusioninventory plugin id * * @param $p_name Module name * @return Plugin id or FALSE if module is not active or not a fusioninventory module **/ static function getModuleId($p_name) { $index = FALSE; if (!isset($_SESSION['glpi_plugins'])) { return $index; } if ($p_name == 'fusioninventory') { $index = array_search($p_name, $_SESSION['glpi_plugins']); if (!$index) { $plugin = new Plugin(); $data = $plugin->find("directory='" . $p_name . "'"); if (count($data)) { $fields = current($data); $index = $fields['id']; } } } return $index; }
/** * @param $width **/ function showSystemInformations($width) { // No need to translate, this part always display in english (for copy/paste to forum) echo "\n<tr class='tab_bg_2'><th>Plugins list</th></tr>"; echo "<tr class='tab_bg_1'><td><pre>\n \n"; $plug = new Plugin(); $pluglist = $plug->find("", "name, directory"); foreach ($pluglist as $plugin) { $msg = substr(str_pad($plugin['directory'], 30), 0, 20) . " Name: " . Toolbox::substr(str_pad($plugin['name'], 40), 0, 30) . " Version: " . str_pad($plugin['version'], 10) . " State: "; switch ($plugin['state']) { case self::ANEW: $msg .= 'New'; break; case self::ACTIVATED: $msg .= 'Enabled'; break; case self::NOTINSTALLED: $msg .= 'Not installed'; break; case self::TOBECONFIGURED: $msg .= 'To be configured'; break; case self::NOTACTIVATED: $msg .= 'Not activated'; break; case self::TOBECLEANED: default: $msg .= 'To be cleaned'; break; } echo wordwrap("\t" . $msg . "\n", $width, "\n\t\t"); } echo "\n</pre></td></tr>"; }
/** * To load classes * * @param $classname : class to load **/ function glpi_autoload($classname) { global $DEBUG_AUTOLOAD, $CFG_GLPI; static $notfound = array('xStates' => true, 'xAllAssets' => true); // empty classname or non concerted plugin or classname containing dot (leaving GLPI main treee) if (empty($classname) || is_numeric($classname) || strpos($classname, '.') !== false) { die("Security die. trying to load an forbidden class name"); } $dir = GLPI_ROOT . "/inc/"; if ($plug = isPluginItemType($classname)) { $plugname = strtolower($plug['plugin']); $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/"; $item = strtolower($plug['class']); // Is the plugin activate ? // Command line usage of GLPI : need to do a real check plugin activation if (isCommandLine()) { $plugin = new Plugin(); if (count($plugin->find("directory='{$plugname}' AND state=" . Plugin::ACTIVATED)) == 0) { // Plugin does not exists or not activated return false; } } else { // Standard use of GLPI if (!isset($_SESSION['glpi_plugins']) || !in_array($plugname, $_SESSION['glpi_plugins'])) { // Plugin not activated return false; } } } else { //TODO: clean, seems uneeded, as composer autoloader is used first // Do not try to load phpcas using GLPI autoload //if (preg_match('/^CAS_.*/', $classname)) { // return false; //} // Do not try to load Zend using GLPI autoload //if (preg_match('/^Zend.*/', $classname)) { // return false; //} // Do not try to load Simplepie using GLPI autoload //if (preg_match('/^SimplePie.*/', $classname)) { // return false; //} $item = strtolower($classname); } if (file_exists("{$dir}{$item}.class.php")) { include_once "{$dir}{$item}.class.php"; if (isset($_SESSION['glpi_use_mode']) && $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { $DEBUG_AUTOLOAD[] = $classname; } } else { if (!isset($notfound["x{$classname}"])) { // trigger an error to get a backtrace, but only once (use prefix 'x' to handle empty case) // trigger_error("GLPI autoload : file $dir$item.class.php not founded trying to load class '$classname'"); $notfound["x{$classname}"] = true; } } }
/** * プラグインのステータスを更新する * * @return boolean * @access protected */ function _updatePluginStatus() { $db =& $this->_connectDb($this->_readDbSettingFromSession()); $version = $this->getBaserVersion(); App::import('Model', 'Plugin'); $Plugin = new Plugin(); $datas = $Plugin->find('all'); if ($datas) { $result = true; foreach ($datas as $data) { $data['Plugin']['version'] = $version; $data['Plugin']['status'] = true; if (!$Plugin->save($data)) { $result = false; } } return $result; } else { return false; } }
/** * To load classes * * @param $classname : class to load **/ function glpi_autoload($classname) { global $DEBUG_AUTOLOAD, $CFG_GLPI; static $notfound = array('xStates' => true, 'xAllAssets' => true); // empty classname or non concerted plugin or classname containing dot (leaving GLPI main treee) if (empty($classname) || is_numeric($classname) || strpos($classname, '.') !== false) { return false; } $dir = GLPI_ROOT . "/inc/"; if ($plug = isPluginItemType($classname)) { $plugname = strtolower($plug['plugin']); $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/"; $item = strtolower($plug['class']); // Is the plugin activate ? // Command line usage of GLPI : need to do a real check plugin activation if (isCommandLine()) { $plugin = new Plugin(); if (count($plugin->find("directory='{$plugname}' AND state=" . Plugin::ACTIVATED)) == 0) { // Plugin does not exists or not activated return false; } } else { // Standard use of GLPI if (!in_array($plugname, $_SESSION['glpi_plugins'])) { // Plugin not activated return false; } } } else { // Is ezComponent class ? if (preg_match('/^ezc([A-Z][a-z]+)/', $classname, $matches)) { include_once GLPI_EZC_BASE; ezcBase::autoload($classname); return true; } // Is Zend class ? // if (preg_match('/^Zend/',$classname,$matches)) { // if (GLPI_ZEND_PATH) { // set_include_path(GLPI_ZEND_PATH . PATH_SEPARATOR . get_include_path()); // } // require_once("Zend/Loader.php"); // // Zend_Loader::loadClass($classname); // return true; // } // Do not try to load phpcas using GLPI autoload if (preg_match('/^CAS_.*/', $classname)) { return false; } $item = strtolower($classname); } // No errors for missing classes due to implementation if (file_exists("{$dir}{$item}.class.php")) { include_once "{$dir}{$item}.class.php"; if (isset($_SESSION['glpi_use_mode']) && $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { $DEBUG_AUTOLOAD[] = $classname; } } else { if (!isset($notfound["x{$classname}"])) { // trigger an error to get a backtrace, but only once (use prefix 'x' to handle empty case) // trigger_error("GLPI autoload : file $dir$item.class.php not founded trying to load class '$classname'"); $notfound["x{$classname}"] = true; } } }
/** * Remove the specified resource from storage. * DELETE /plugin/{id} * * @param int $id * @return Response */ public function destroy($id) { $plugin = Plugin::find($id); $plugin->versions()->delete(); $plugin->delete(); return Redirect::back()->withSuccess('Plugin removed.'); }
public function checkInstall($pluginname = '', $when = '') { global $DB; if ($pluginname == '') { return; } $comparaisonSQLFile = "plugin_" . $pluginname . "-empty.sql"; // See http://joefreeman.co.uk/blog/2009/07/php-script-to-compare-mysql-database-schemas/ $file_content = file_get_contents(GLPI_ROOT . "/plugins/" . $pluginname . "/install/mysql/" . $comparaisonSQLFile); $a_lines = explode("\n", $file_content); $a_tables_ref = array(); $current_table = ''; foreach ($a_lines as $line) { if (strstr($line, "CREATE TABLE ") or strstr($line, "CREATE VIEW")) { $matches = array(); preg_match("/`(.*)`/", $line, $matches); $current_table = $matches[1]; } else { if (preg_match("/^`/", trim($line))) { $s_line = explode("`", $line); $s_type = explode("COMMENT", $s_line[2]); $s_type[0] = trim($s_type[0]); $s_type[0] = str_replace(" COLLATE utf8_unicode_ci", "", $s_type[0]); $s_type[0] = str_replace(" CHARACTER SET utf8", "", $s_type[0]); $a_tables_ref[$current_table][$s_line[1]] = str_replace(",", "", $s_type[0]); } } } // * Get tables from MySQL $a_tables_db = array(); $a_tables = array(); // SHOW TABLES; $query = "SHOW TABLES"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { if ((strstr($data[0], "tracker") or strstr($data[0], 'fusioninventory') or strstr($data[0], 'fusinvinventory') or strstr($data[0], 'fusinvsnmp') or strstr($data[0], 'fusinvdeploy')) and !strstr($data[0], "glpi_plugin_fusioninventory_pcidevices") and !strstr($data[0], "glpi_plugin_fusioninventory_pcivendors") and !strstr($data[0], "glpi_plugin_fusioninventory_ouis") and !strstr($data[0], "glpi_plugin_fusioninventory_usbdevices") and !strstr($data[0], "glpi_plugin_fusioninventory_usbvendors")) { $data[0] = str_replace(" COLLATE utf8_unicode_ci", "", $data[0]); $data[0] = str_replace("( ", "(", $data[0]); $data[0] = str_replace(" )", ")", $data[0]); $a_tables[] = $data[0]; } } foreach ($a_tables as $table) { $query = "SHOW CREATE TABLE " . $table; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $a_lines = explode("\n", $data['Create Table']); foreach ($a_lines as $line) { if (strstr($line, "CREATE TABLE ") or strstr($line, "CREATE VIEW")) { $matches = array(); preg_match("/`(.*)`/", $line, $matches); $current_table = $matches[1]; } else { if (preg_match("/^`/", trim($line))) { $s_line = explode("`", $line); $s_type = explode("COMMENT", $s_line[2]); $s_type[0] = trim($s_type[0]); $s_type[0] = str_replace(" COLLATE utf8_unicode_ci", "", $s_type[0]); $s_type[0] = str_replace(" CHARACTER SET utf8", "", $s_type[0]); $s_type[0] = str_replace(",", "", $s_type[0]); if (trim($s_type[0]) == 'text' || trim($s_type[0]) == 'longtext') { $s_type[0] .= ' DEFAULT NULL'; } $a_tables_db[$current_table][$s_line[1]] = $s_type[0]; } } } } } $a_tables_ref_tableonly = array(); foreach ($a_tables_ref as $table => $data) { $a_tables_ref_tableonly[] = $table; } $a_tables_db_tableonly = array(); foreach ($a_tables_db as $table => $data) { $a_tables_db_tableonly[] = $table; } // Compare $tables_toremove = array_diff($a_tables_db_tableonly, $a_tables_ref_tableonly); $tables_toadd = array_diff($a_tables_ref_tableonly, $a_tables_db_tableonly); // See tables missing or to delete $this->assertEquals(count($tables_toadd), 0, 'Tables missing ' . $when . ' ' . print_r($tables_toadd, TRUE)); $this->assertEquals(count($tables_toremove), 0, 'Tables to delete ' . $when . ' ' . print_r($tables_toremove, TRUE)); // See if fields are same foreach ($a_tables_db as $table => $data) { if (isset($a_tables_ref[$table])) { $fields_toremove = array_diff_assoc($data, $a_tables_ref[$table]); $fields_toadd = array_diff_assoc($a_tables_ref[$table], $data); $diff = "======= DB ============== Ref =======> " . $table . "\n"; $diff .= print_r($data, TRUE); $diff .= print_r($a_tables_ref[$table], TRUE); // See tables missing or to delete $this->assertEquals(count($fields_toadd), 0, 'Fields missing/not good in ' . $when . ' ' . $table . ' ' . print_r($fields_toadd, TRUE) . " into " . $diff); $this->assertEquals(count($fields_toremove), 0, 'Fields to delete in ' . $when . ' ' . $table . ' ' . print_r($fields_toremove, TRUE) . " into " . $diff); } } /* * Check if all modules registered */ $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='WAKEONLAN'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, 'WAKEONLAN module not registered'); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='INVENTORY'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, 'INVENTORY module not registered'); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='InventoryComputerESX'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, 'ESX module not registered'); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='NETWORKINVENTORY'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, 'NETWORKINVENTORY module not registered'); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='NETWORKDISCOVERY'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, 'NETWORKDISCOVERY module not registered'); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n WHERE `modulename`='ESX'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 0, 'ESX module may be renommed in InventoryComputerESX'); // $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules` // WHERE `modulename`='DEPLOY'"; // $result = $DB->query($query); // $this->assertEquals($DB->numrows($result), 1, 'DEPLOY module not registered'); /* * Verify in taskjob definition PluginFusinvsnmpIPRange not exist */ $query = "SELECT * FROM `glpi_plugin_fusioninventory_taskjobs`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $snmprangeip = 0; if (strstr($data['targets'], "PluginFusinvsnmpIPRange")) { $snmprangeip = 1; } $this->assertEquals($snmprangeip, 0, 'Have some "PluginFusinvsnmpIPRange" items in taskjob definition'); } /* * Verify cron created */ $crontask = new CronTask(); $this->assertTrue($crontask->getFromDBbyName('PluginFusioninventoryTask', 'taskscheduler'), 'Cron taskscheduler not created'); $this->assertTrue($crontask->getFromDBbyName('PluginFusioninventoryTaskjobstate', 'cleantaskjob'), 'Cron cleantaskjob not created'); $this->assertTrue($crontask->getFromDBbyName('PluginFusioninventoryNetworkPortLog', 'cleannetworkportlogs'), 'Cron cleannetworkportlogs not created'); $this->assertTrue($crontask->getFromDBbyName('PluginFusioninventoryAgentWakeup', 'wakeupAgents'), 'Cron wakeupAgents not created'); /* * Verify config fields added */ $plugin = new Plugin(); $data = $plugin->find("directory='fusioninventory'"); $plugins_id = 0; if (count($data)) { $fields = current($data); $plugins_id = $fields['id']; } $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='ssl_only'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, "type 'ssl_only' not added in config for plugins " . $plugins_id); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='delete_task'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, "type 'delete_task' not added in config"); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='inventory_frequence'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, "type 'inventory_frequence' not added in config"); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='agent_port'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, "type 'agent_port' not added in config"); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='extradebug'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, "type 'extradebug' not added in config"); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='users_id'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, "type 'users_id' not added in config"); $query = "SELECT * FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='version'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, "type 'version' not added in config"); $data = $DB->fetch_assoc($result); $this->assertEquals($data['value'], '0.90+1.0', "Field 'version' not with right version"); $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_configs`\n WHERE `type`='otherserial'"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 1, "type 'otherserial' not added in config"); // TODO : test glpi_displaypreferences, rules, bookmark... /* * Verify table glpi_plugin_fusioninventory_inventorycomputercriterias * have right 10 lines */ $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 11, "Number of criteria not right in table" . " glpi_plugin_fusioninventory_inventorycomputercriterias " . $when); /* * Verify table `glpi_plugin_fusioninventory_inventorycomputerstats` filed with data */ $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_inventorycomputerstats`"; $result = $DB->query($query); $this->assertEquals($DB->numrows($result), 8760, "Must have table `glpi_plugin_fusioninventory_inventorycomputerstats` not empty"); }
$db =& ConnectionManager::getDataSource('plugin'); $db->cacheQueries = false; $listSources = $db->listSources(); $prefix = $db->config['prefix']; $pluginTables = array('blog' => $prefix . 'blog_contents', 'mail' => $prefix . 'mail_contents', 'feed' => $prefix . 'feed_configs', 'uploader' => $prefix . 'uploader_files', 'twitter' => $prefix . 'twitter_configs'); $tableExistsPlugins = array(); foreach ($pluginTables as $key => $table) { if (in_array($table, $listSources)) { $tableExistsPlugins[] = $key; } } App::import('Model', 'Plugin'); $Plugin = new Plugin(); $result = true; foreach ($tableExistsPlugins as $plugin) { $data = $Plugin->find('first', array('conditions' => array('name' => $plugin))); $appPath = APP . 'plugins' . DS . $plugin . DS . 'config' . DS . 'config.php'; $baserPath = BASER_PLUGINS . $plugin . DS . 'config' . DS . 'config.php'; $path = ''; if (file_exists($appPath)) { $path = $appPath; } elseif (file_exists($baserPath)) { $path = $baserPath; } $data['Plugin']['name'] = $plugin; $data['Plugin']['status'] = false; if ($path) { include $path; if (isset($title)) { $data['Plugin']['title'] = $title; }
/** * Links a version to an application * GET /application/{appid}/link/{pluginid} * * @param int $appid * @param int $pluginid * @return Response */ public function linkVersion($appid, $pluginid) { if (Application::find($appid) && Plugin::find($pluginid)) { return View::make('admin.applications.linkversion')->with(['app' => Application::find($appid), 'plugin' => Plugin::find($pluginid), 'versionslist' => Plugin::find($pluginid)->versions()->lists('name', 'id')]); } else { return Redirect::action('application.index')->withErrors(['Application or plugin does not exist.']); } }
function plugin_escalade_install() { global $DB; //get version $plugin = new Plugin(); $found = $plugin->find("name = 'escalade'"); $plugin_escalade = array_shift($found); //init migration $migration = new Migration($plugin_escalade['version']); // == Tables creation (initial installation) == if (!TableExists('glpi_plugin_escalade_histories')) { $query = "CREATE TABLE `glpi_plugin_escalade_histories` (\n `id` INT(11) NOT NULL AUTO_INCREMENT,\n `tickets_id` INT(11) NOT NULL,\n `groups_id` INT(11) NOT NULL,\n `date_mod` DATETIME NOT NULL,\n PRIMARY KEY (`id`),\n KEY `tickets_id` (`tickets_id`),\n KEY `groups_id` (`groups_id`)\n ) ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query); } if (!TableExists('glpi_plugin_escalade_configs')) { $query = "CREATE TABLE `glpi_plugin_escalade_configs` (\n `id` INT(11) NOT NULL AUTO_INCREMENT,\n `remove_group` INT(11) NOT NULL,\n `remove_delete_group_btn` INT(11) NOT NULL,\n `remove_delete_user_btn` INT(11) NOT NULL,\n `show_history` INT(11) NOT NULL,\n `task_history` INT(11) NOT NULL,\n `remove_tech` INT(11) NOT NULL,\n `solve_return_group` INT(11) NOT NULL,\n `reassign_group_from_cat` INT(11) NOT NULL,\n `reassign_tech_from_cat` INT(11) NOT NULL,\n `cloneandlink_ticket` INT(11) NOT NULL,\n `close_linkedtickets` INT(11) NOT NULL,\n `use_assign_user_group` INT(11) NOT NULL,\n `use_assign_user_group_creation` INT(11) NOT NULL,\n `use_assign_user_group_modification` INT(11) NOT NULL,\n `assign_me_ticket` INT(11) NOT NULL,\n `use_filter_assign_group` INT(11) NOT NULL,\n `ticket_last_status` INT(11) NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query); $query = "INSERT INTO glpi_plugin_escalade_configs \n VALUES (NULL, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, '" . Ticket::WAITING . "')"; $DB->query($query); } // == Update to 1.2 == if (!FieldExists('glpi_plugin_escalade_configs', 'cloneandlink_ticket')) { $migration->addField('glpi_plugin_escalade_configs', 'cloneandlink_ticket', 'INT(11) NOT NULL', array('after' => 'reassign_tech_from_cat')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!FieldExists('glpi_plugin_escalade_configs', 'close_linkedtickets')) { $migration->addField('glpi_plugin_escalade_configs', 'close_linkedtickets', 'INT(11) NOT NULL', array('after' => 'cloneandlink_ticket')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!FieldExists('glpi_plugin_escalade_configs', 'use_assign_user_group')) { $migration->addField('glpi_plugin_escalade_configs', 'use_assign_user_group', 'INT(11) NOT NULL', array('after' => 'close_linkedtickets')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!FieldExists('glpi_plugin_escalade_configs', 'use_assign_user_group_creation')) { $migration->addField('glpi_plugin_escalade_configs', 'use_assign_user_group_creation', 'INT(11) NOT NULL', array('after' => 'use_assign_user_group')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!FieldExists('glpi_plugin_escalade_configs', 'use_assign_user_group_modification')) { $migration->addField('glpi_plugin_escalade_configs', 'use_assign_user_group_modification', 'INT(11) NOT NULL', array('after' => 'use_assign_user_group_creation')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!FieldExists('glpi_plugin_escalade_configs', 'remove_delete_group_btn')) { $migration->addField('glpi_plugin_escalade_configs', 'remove_delete_group_btn', 'INT(11) NOT NULL', array('after' => 'remove_group')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!FieldExists('glpi_plugin_escalade_configs', 'assign_me_ticket')) { $migration->addField('glpi_plugin_escalade_configs', 'assign_me_ticket', 'INT(11) NOT NULL', array('after' => 'use_assign_user_group_modification')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!isIndex("glpi_plugin_escalade_histories", 'tickets_id') || !isIndex("glpi_plugin_escalade_histories", 'groups_id')) { $migration->addKey("glpi_plugin_escalade_histories", 'tickets_id', 'tickets_id'); $migration->addKey("glpi_plugin_escalade_histories", 'groups_id', 'groups_id'); $migration->migrationOneTable('glpi_plugin_escalade_histories'); } // == Update to 1.3 == if (!FieldExists('glpi_plugin_escalade_configs', 'remove_delete_user_btn')) { $migration->addField('glpi_plugin_escalade_configs', 'remove_delete_user_btn', 'INT(11) NOT NULL DEFAULT 1', array('after' => 'remove_delete_group_btn')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!FieldExists('glpi_plugin_escalade_configs', 'use_filter_assign_group')) { $migration->addField('glpi_plugin_escalade_configs', 'use_filter_assign_group', 'INT(11) NOT NULL', array('after' => 'use_assign_user_group_modification')); $migration->migrationOneTable('glpi_plugin_escalade_configs'); } if (!TableExists('glpi_plugin_escalade_groups_groups')) { $query = "CREATE TABLE `glpi_plugin_escalade_groups_groups` (\n `id` INT(11) NOT NULL AUTO_INCREMENT,\n `groups_id_source` int(11) NOT NULL DEFAULT '0',\n `groups_id_destination` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`)\n ) ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query); } // Update for 0.84 status if (TableExists('glpi_plugin_escalade_configs')) { foreach ($DB->request("glpi_plugin_escalade_configs") as $data) { switch ($data['ticket_last_status']) { case 'solved': $status = Ticket::SOLVED; break; case 'waiting': $status = Ticket::WAITING; break; case 'closed': $status = Ticket::CLOSED; break; case 'assign': $status = Ticket::ASSIGNED; break; case 'new': $status = Ticket::INCOMING; break; case 'plan': $status = Ticket::PLANNED; break; default: $status = -1; break; } $query = "UPDATE `glpi_plugin_escalade_configs`\n SET `ticket_last_status` = '" . $status . "'\n WHERE `id` = '" . $data['id'] . "'"; $DB->query($query); } $query = "ALTER TABLE `glpi_plugin_escalade_configs` MODIFY `ticket_last_status` INT(11);"; $DB->query($query); } return true; }
/** * Show the form for editing the specified resource. * GET /version/{id}/edit * * @param int $id * @return Response */ public function edit($pluginid, $versionid) { return View::make('admin.version.edit')->with(['version' => Version::find($versionid), 'plugin' => Plugin::find($pluginid)]); }