本文整理汇总了PHP中Migration::createRule方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::createRule方法的具体用法?PHP Migration::createRule怎么用?PHP Migration::createRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Migration
的用法示例。
在下文中一共展示了Migration::createRule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: plugin_ocsinventoryng_install
/**
* @return bool
*/
function plugin_ocsinventoryng_install()
{
global $DB;
include_once GLPI_ROOT . "/plugins/ocsinventoryng/inc/profile.class.php";
$migration = new Migration(132);
if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers_profiles") && !TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !TableExists("ocs_glpi_ocsservers")) {
$install = true;
$DB->runFile(GLPI_ROOT . "/plugins/ocsinventoryng/install/mysql/1.3.2-empty.sql");
$migration->createRule(array('sub_type' => 'RuleImportComputer', 'entities_id' => 0, 'is_recursive' => 0, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootComputerOcs'), array(array('criteria' => 'serial', 'condition' => Rule::PATTERN_FIND, 'pattern' => '1')), array(array('field' => '_fusion', 'action_type' => 'assign', 'value' => 0)));
$migration->createRule(array('sub_type' => 'RuleImportEntity', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootEntityOcs'), array(array('criteria' => 'TAG', 'condition' => Rule::PATTERN_IS, 'pattern' => '*'), array('criteria' => 'OCS_SERVER', 'condition' => Rule::PATTERN_IS, 'pattern' => 1)), array(array('field' => 'entities_id', 'action_type' => 'assign', 'value' => 0)));
} else {
if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !TableExists("ocs_glpi_ocsservers")) {
CronTask::Register('PluginOcsinventoryngOcsServer', 'ocsng', MINUTE_TIMESTAMP * 5);
$migration->createRule(array('sub_type' => 'RuleImportComputer', 'entities_id' => 0, 'is_recursive' => 0, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootComputerOcs'), array(array('criteria' => 'serial', 'condition' => Rule::PATTERN_FIND, 'pattern' => '1')), array(array('field' => '_fusion', 'action_type' => 'assign', 'value' => 0)));
$migration->createRule(array('sub_type' => 'RuleImportEntity', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootEntityOcs'), array(array('criteria' => 'TAG', 'condition' => Rule::PATTERN_IS, 'pattern' => '*'), array('criteria' => 'OCS_SERVER', 'condition' => Rule::PATTERN_IS, 'pattern' => 1)), array(array('field' => 'entities_id', 'action_type' => 'assign', 'value' => 0)));
} else {
if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers") && TableExists("ocs_glpi_ocsservers")) {
$update = true;
$DB->runFile(GLPI_ROOT . "/plugins/ocsinventoryng/install/mysql/1.0.0-update.sql");
// recuperation des droits du core
// creation de la table glpi_plugin_ocsinventoryng_profiles vide
if (TableExists("ocs_glpi_profiles") && (TableExists('ocs_glpi_ocsservers') && countElementsInTable('ocs_glpi_ocsservers') > 0)) {
$query = "INSERT INTO `glpi_plugin_ocsinventoryng_profiles`\r\n (`profiles_id`, `ocsng`, `sync_ocsng`, `view_ocsng`, `clean_ocsng`,\r\n `rule_ocs`)\r\n SELECT `id`, `ocsng`, `sync_ocsng`, `view_ocsng`, `clean_ocsng`,\r\n `rule_ocs`\r\n FROM `ocs_glpi_profiles`";
$DB->queryOrDie($query, "1.0.0 insert profiles for OCS in plugin");
}
// recuperation des paramètres du core
if (TableExists("ocs_glpi_crontasks")) {
$query = "INSERT INTO `glpi_crontasks`\r\n SELECT *\r\n FROM `ocs_glpi_crontasks`\r\n WHERE `itemtype` = 'OcsServer'";
$DB->queryOrDie($query, "1.0.0 insert crontasks for plugin ocsinventoryng");
$query = "UPDATE `glpi_crontasks`\r\n SET `itemtype` = 'PluginOcsinventoryngOcsServer'\r\n WHERE `itemtype` = 'OcsServer'";
$DB->queryOrDie($query, "1.0.0 update ocsinventoryng crontask");
}
if (TableExists("ocs_glpi_displaypreferences")) {
$query = "INSERT INTO `glpi_displaypreferences`\r\n SELECT *\r\n FROM `ocs_glpi_displaypreferences`\r\n WHERE `itemtype` = 'OcsServer'";
$DB->queryOrDie($query, "1.0.0 insert displaypreferences for plugin ocsinventoryng");
$query = "UPDATE `glpi_displaypreferences`\r\n SET `itemtype` = 'PluginOcsinventoryngOcsServer'\r\n WHERE `itemtype` = 'OcsServer'";
$DB->queryOrDie($query, "1.0.0 update ocsinventoryng displaypreferences");
}
plugin_ocsinventoryng_migrateComputerLocks($migration);
}
}
}
//Update 1.0.3
if (TableExists("glpi_plugin_ocsinventoryng_networkports") && !FieldExists('glpi_plugin_ocsinventoryng_networkports', 'speed')) {
$query = "ALTER TABLE `glpi_plugin_ocsinventoryng_networkports` \r\n ADD `speed` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT '10mb/s';";
$DB->queryOrDie($query, "1.0.3 update table glpi_plugin_ocsinventoryng_networkports");
}
// Update 1.0.4
if (TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'conn_type')) {
$query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n ADD `conn_type` TINYINT(1) NOT NULL DEFAULT '0';";
$DB->queryOrDie($query, "1.0.4 update table glpi_plugin_ocsinventoryng_ocsservers");
}
//Update 1.1.0
if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers_profiles")) {
$query = "CREATE TABLE `glpi_plugin_ocsinventoryng_ocsservers_profiles` (\r\n `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n `plugin_ocsinventoryng_ocsservers_id` INT(11) NOT NULL DEFAULT '0',\r\n `profiles_id` INT(11) NOT NULL DEFAULT '0',\r\n PRIMARY KEY (`id`),\r\n KEY `plugin_ocsinventoryng_ocsservers_id` (`plugin_ocsinventoryng_ocsservers_id`),\r\n KEY `profiles_id` (`profiles_id`)\r\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, 'Creating glpi_plugin_ocsinventoryng_ocsservers_profiles' . "<br>" . $DB->error());
}
if (TableExists("glpi_plugin_ocsinventoryng_ocslinks") && !FieldExists('glpi_plugin_ocsinventoryng_ocslinks', 'last_ocs_conn')) {
$query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocslinks` \r\n ADD `last_ocs_conn` DATETIME DEFAULT NULL;";
$DB->queryOrDie($query, "1.1.0 update table glpi_plugin_ocsinventoryng_ocslinks");
}
if (TableExists("glpi_plugin_ocsinventoryng_ocslinks") && !FieldExists('glpi_plugin_ocsinventoryng_ocslinks', 'ip_src')) {
$query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocslinks` \r\n ADD `ip_src` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL;";
$DB->queryOrDie($query, "1.1.0 update table glpi_plugin_ocsinventoryng_ocslinks");
}
if (TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'import_device_bios')) {
$query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n ADD `import_device_bios` TINYINT(1) NOT NULL DEFAULT '1';";
$DB->queryOrDie($query, "1.1.0 update table glpi_plugin_ocsinventoryng_ocsservers");
}
if (!TableExists("glpi_plugin_ocsinventoryng_devicebiosdatas")) {
$query = "CREATE TABLE `glpi_plugin_ocsinventoryng_devicebiosdatas` (\r\n `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n `designation` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n `comment` TEXT COLLATE utf8_unicode_ci,\r\n `date` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n `assettag` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n `manufacturers_id` INT(11) NOT NULL DEFAULT '0',\r\n `entities_id` INT(11) NOT NULL DEFAULT '0',\r\n `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',\r\n PRIMARY KEY (`id`),\r\n KEY `manufacturers_id` (`manufacturers_id`),\r\n KEY `entities_id` (`entities_id`),\r\n KEY `is_recursive` (`is_recursive`)\r\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "1.1.0 add table glpi_plugin_ocsinventoryng_devicebiosdatas");
}
if (!TableExists("glpi_plugin_ocsinventoryng_items_devicebiosdatas")) {
$query = "CREATE TABLE `glpi_plugin_ocsinventoryng_items_devicebiosdatas` (\r\n `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n `items_id` INT(11) NOT NULL DEFAULT '0',\r\n `itemtype` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n `plugin_ocsinventoryng_devicebiosdatas_id` INT(11) NOT NULL DEFAULT '0',\r\n `is_deleted` TINYINT(1) NOT NULL DEFAULT '0',\r\n `is_dynamic` TINYINT(1) NOT NULL DEFAULT '0',\r\n `entities_id` INT(11) NOT NULL DEFAULT '0',\r\n `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',\r\n PRIMARY KEY (`id`),\r\n KEY `computers_id` (`items_id`),\r\n KEY `plugin_ocsinventoryng_devicebiosdatas_id` (`plugin_ocsinventoryng_devicebiosdatas_id`),\r\n KEY `is_deleted` (`is_deleted`),\r\n KEY `is_dynamic` (`is_dynamic`),\r\n KEY `entities_id` (`entities_id`),\r\n KEY `is_recursive` (`is_recursive`),\r\n KEY `item` (`itemtype`,`items_id`)\r\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "1.1.0 add table glpi_plugin_ocsinventoryng_items_devicebiosdatas");
}
PluginOcsinventoryngProfile::initProfile();
PluginOcsinventoryngProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
if (TableExists("glpi_plugin_ocsinventoryng_ocsservers") && TableExists("glpi_plugin_ocsinventoryng_profiles") && countElementsInTable("glpi_plugin_ocsinventoryng_ocsservers", "`is_active` = 1") == 1) {
foreach ($DB->request("glpi_plugin_ocsinventoryng_ocsservers") as $server) {
foreach ($DB->request("glpi_plugin_ocsinventoryng_profiles", "`ocsng` IS NOT NULL") as $rights) {
$query = "INSERT INTO `glpi_plugin_ocsinventoryng_ocsservers_profiles`\r\n SET `profiles_id` = '" . $rights['profiles_id'] . "',\r\n `plugin_ocsinventoryng_ocsservers_id` = '" . $server['id'] . "'";
$DB->queryOrDie($query, "insert glpi_plugin_ocsinventoryng_ocsservers_profiles");
}
}
}
$migration->dropTable('glpi_plugin_ocsinventoryng_profiles');
//Update 1.2.2
if (TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'import_device_motherboard')) {
$query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n ADD `import_device_motherboard` TINYINT(1) NOT NULL DEFAULT '0';";
$DB->queryOrDie($query, "1.2.2 update table glpi_plugin_ocsinventoryng_ocsservers");
}
//Update 1.2.3
if (!TableExists("glpi_plugin_ocsinventoryng_ipdiscoverocslinks")) {
$query = "CREATE TABLE `glpi_plugin_ocsinventoryng_ipdiscoverocslinks` (\r\n `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n `items_id` INT(11) NOT NULL,\r\n `itemtype` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n `macaddress` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL UNIQUE,\r\n `last_update` DATETIME COLLATE utf8_unicode_ci DEFAULT NULL,\r\n `subnet` VARCHAR(40) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n `plugin_ocsinventoryng_ocsservers_id` INT(11) NOT NULL DEFAULT '0',\r\n PRIMARY KEY (`id`)\r\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "1.2.3 add table glpi_plugin_ocsinventoryng_ipdiscoverocslinks");
//.........这里部分代码省略.........