本文整理汇总了PHP中TableExists函数的典型用法代码示例。如果您正苦于以下问题:PHP TableExists函数的具体用法?PHP TableExists怎么用?PHP TableExists使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TableExists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update0853to0855
/**
* Update from 0.85.3 to 0.85.5
*
* @return bool for success (will die for most error)
**/
function update0853to0855()
{
global $DB, $migration;
$updateresult = true;
$ADDTODISPLAYPREF = array();
//TRANS: %s is the number of new version
$migration->displayTitle(sprintf(__('Update to %s'), '0.85.5'));
$migration->setVersion('0.85.5');
$backup_tables = false;
$newtables = array();
foreach ($newtables as $new_table) {
// rename new tables if exists ?
if (TableExists($new_table)) {
$migration->dropTable("backup_{$new_table}");
$migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
$backup_tables = true;
$query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
}
}
if ($backup_tables) {
$migration->displayWarning("You can delete backup tables if you have no need of them.", true);
}
$migration->addField("glpi_entities", 'inquest_duration', "integer", array('value' => 0));
$migration->addKey('glpi_users', 'begin_date', 'begin_date');
$migration->addKey('glpi_users', 'end_date', 'end_date');
$migration->addKey('glpi_knowbaseitems', 'begin_date', 'begin_date');
$migration->addKey('glpi_knowbaseitems', 'end_date', 'end_date');
// must always be at the end
$migration->executeMigration();
return $updateresult;
}
示例2: plugin_vip_install
function plugin_vip_install()
{
global $DB;
$migration = new Migration(100);
// Création de la table uniquement lors de la première installation
if (!TableExists("glpi_plugin_vip_profiles")) {
// Table des droits du profil
$query = "CREATE TABLE `glpi_plugin_vip_profiles` (\n\t `id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',\n\t `show_vip_tab` tinyint(1) collate utf8_unicode_ci default NULL,\n\t PRIMARY KEY (`id`)\n\t ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die("Error creating Vip Profiles table" . $DB->error());
$migration->executeMigration();
//creation du premier accès nécessaire lors de l'installation du plugin
include_once GLPI_ROOT . "/plugins/vip/inc/profile.class.php";
PluginVipProfile::createAdminAccess($_SESSION['glpiactiveprofile']['id']);
}
if (!TableExists("glpi_plugin_vip_groups")) {
//
$query = "CREATE TABLE `glpi_plugin_vip_groups` (\n `id` int(11) NOT NULL default 0 COMMENT 'RELATION to glpi_groups(id)',\n `isvip` tinyint(1) default '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die("Erreur lors de la création de la table des groupes vip " . $DB->error());
$query = "INSERT INTO `glpi_plugin_vip_groups`\n (`id`, `isvip`)\n VALUES ('0', '0')";
$DB->query($query) or die("Erreur lors de l'insertion des valeurs par défaut dans la table des groupes vip " . $DB->error());
}
if (!TableExists("glpi_plugin_vip_tickets")) {
$query = "CREATE TABLE glpi_plugin_vip_tickets (\n\t\t\t\t id int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_tickets (id)',\n\t\t\t\t isvip tinyint(1) default '0',\n\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die("Error creating Vip Tickets table");
}
$query = "INSERT INTO glpi_plugin_vip_tickets\n\t\t\t\t SELECT id, '0'\n\t\t\t\t\t FROM glpi_tickets\n\t\t ON DUPLICATE KEY\n\t\t\t\t UPDATE isvip = '0'";
$DB->query($query) or die("Error inserting ticket in Vip Tickets table");
$migration->executeMigration();
return true;
}
示例3: install
public static function install(Migration $migration)
{
$table = getTableForItemType(__CLASS__);
if (!TableExists($table)) {
$query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) NOT NULL DEFAULT '',\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error());
}
// Migration from previous version
if (TableExists('glpi_plugin_formcreator_cats')) {
$query = "INSERT IGNORE INTO `{$table}` (`id`, `name`)\n SELECT `id`,`name` FROM glpi_plugin_formcreator_cats";
$GLOBALS['DB']->query($query);
$GLOBALS['DB']->query("DROP TABLE glpi_plugin_formcreator_cats");
}
/**
* Migration of special chars from previous versions
*
* @since 0.85-1.2.3
*/
$query = "SELECT `id`, `name`, `comment`\n FROM `{$table}`";
$result = $GLOBALS['DB']->query($query);
while ($line = $GLOBALS['DB']->fetch_array($result)) {
$query_update = "UPDATE `{$table}` SET\n `name` = '" . plugin_formcreator_encode($line['name']) . "',\n `comment` = '" . plugin_formcreator_encode($line['comment']) . "'\n WHERE `id` = " . (int) $line['id'];
$GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error());
}
return true;
}
示例4: install
public static function install(Migration $migration)
{
global $DB;
$table = getTableForItemType(__CLASS__);
if (!TableExists($table) && !TableExists("glpi_dropdown_plugin_order_taxes")) {
$migration->displayMessage("Installing {$table}");
//Install
$query = "CREATE TABLE `glpi_plugin_order_ordertaxes` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query) or die($DB->error());
$taxes = new self();
foreach (array('20', '5.5', '19.6') as $tax) {
$taxes->add(array('name' => $tax));
}
} else {
//Update
$migration->displayMessage("Migrating {$table}");
//1.2.0
$migration->renameTable("glpi_dropdown_plugin_order_taxes", $table);
$migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment");
$migration->changeField($table, "name", "name", "varchar(255) collate utf8_unicode_ci default NULL");
$migration->changeField($table, "comments", "comment", "text collate utf8_unicode_ci");
$migration->migrationOneTable($table);
//Remplace , by . in taxes
foreach ($DB->request("SELECT `name` FROM `{$table}`") as $data) {
if (strpos($data["name"], ',')) {
$name = str_replace(',', '.', $data["name"]);
$query = "UPDATE `{$table}`\n SET `name` = '" . $name . "'\n WHERE `name`= '" . $data["name"] . "'";
$DB->query($query) or die($DB->error());
}
}
}
}
示例5: plugin_fields_checkFiles
function plugin_fields_checkFiles()
{
$plugin = new Plugin();
if (isset($_SESSION['glpiactiveentities']) && $plugin->isInstalled('fields') && $plugin->isActivated('fields')) {
Plugin::registerClass('PluginFieldsContainer');
Plugin::registerClass('PluginFieldsDropdown');
Plugin::registerClass('PluginFieldsField');
if (TableExists("glpi_plugin_fields_containers")) {
$container_obj = new PluginFieldsContainer();
$containers = $container_obj->find();
foreach ($containers as $container) {
$classname = "PluginFields" . ucfirst($container['itemtype'] . preg_replace('/s$/', '', $container['name']));
if (!class_exists($classname)) {
PluginFieldsContainer::generateTemplate($container);
}
}
}
if (TableExists("glpi_plugin_fields_fields")) {
$fields_obj = new PluginFieldsField();
$fields = $fields_obj->find("`type` = 'dropdown'");
foreach ($fields as $field) {
PluginFieldsDropdown::create($field);
}
}
}
}
示例6: plugin_immobilizationsheets_install
function plugin_immobilizationsheets_install()
{
global $DB;
include_once GLPI_ROOT . "/plugins/immobilizationsheets/inc/profile.class.php";
$update = false;
if (!TableExists("glpi_plugin_immo_profiles") && !TableExists("glpi_plugin_immobilizationsheets_profiles")) {
$DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/empty-1.3.0.sql");
} else {
if (TableExists("glpi_plugin_immo_profiles") && FieldExists("glpi_plugin_immo_profiles", "interface")) {
$update = true;
$DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.2.0.sql");
$DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.3.0.sql");
} else {
if (!TableExists("glpi_plugin_immobilizationsheets_profiles")) {
$update = true;
$DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.3.0.sql");
}
}
}
if ($update) {
//Do One time on 0.78
$query_ = "SELECT *\n FROM `glpi_plugin_immobilizationsheets_profiles` ";
$result_ = $DB->query($query_);
if ($DB->numrows($result_) > 0) {
while ($data = $DB->fetch_array($result_)) {
$query = "UPDATE `glpi_plugin_immobilizationsheets_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';";
$result = $DB->query($query);
}
}
$query = "ALTER TABLE `glpi_plugin_immobilizationsheets_profiles`\n DROP `name` ;";
$result = $DB->query($query);
}
PluginImmobilizationsheetsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
return true;
}
示例7: plugin_manufacturersimports_install
function plugin_manufacturersimports_install()
{
global $DB;
include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/profile.class.php";
include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/config.class.php";
$migration = new Migration("1.7.0");
$update = false;
//Root of SQL files for DB installation or upgrade
$sql_root = GLPI_ROOT . "/plugins/manufacturersimports/sql/";
if (!TableExists("glpi_plugin_manufacturersimports_configs")) {
$DB->runFile($sql_root . "/empty-1.7.0.sql");
} else {
if (TableExists("glpi_plugin_suppliertag_config") && !FieldExists("glpi_plugin_suppliertag_config", "FK_entities")) {
$update = true;
$DB->runFile($sql_root . "/update-1.1.sql");
$DB->runFile($sql_root . "/update-1.2.0.sql");
$DB->runFile($sql_root . "/update-1.3.0.sql");
$DB->runFile($sql_root . "/update-1.4.1.sql");
$DB->runFile($sql_root . "/update-1.5.0.sql");
$DB->runFile($sql_root . "/update-1.7.0.sql");
} else {
if (TableExists("glpi_plugin_suppliertag_profiles") && FieldExists("glpi_plugin_suppliertag_profiles", "interface")) {
$update = true;
$DB->runFile($sql_root . "/update-1.2.0.sql");
$DB->runFile($sql_root . "/update-1.3.0.sql");
$DB->runFile($sql_root . "/update-1.4.1.sql");
$DB->runFile($sql_root . "/update-1.5.0.sql");
$DB->runFile($sql_root . "/update-1.7.0.sql");
} else {
if (!TableExists("glpi_plugin_manufacturersimports_profiles") && !FieldExists("glpi_plugin_manufacturersimports_configs", "supplier_key")) {
$update = true;
$DB->runFile($sql_root . "/update-1.3.0.sql");
$DB->runFile($sql_root . "/update-1.4.1.sql");
$DB->runFile($sql_root . "/update-1.5.0.sql");
$DB->runFile($sql_root . "/update-1.7.0.sql");
} else {
if (!FieldExists("glpi_plugin_manufacturersimports_configs", "supplier_key")) {
$DB->runFile($sql_root . "/update-1.7.0.sql");
}
}
}
}
}
$query = "UPDATE `glpi_plugin_manufacturersimports_configs` \n SET `Supplier_url` = 'http://www.dell.com/support/troubleshooting/us/en/04/Index?c=us&l=en&s=bsd&cs=04&t=system&ServiceTag=' \n WHERE `name` ='" . PluginManufacturersimportsConfig::DELL . "'";
$DB->query($query);
if ($update) {
foreach ($DB->request('glpi_plugin_manufacturersimports_profiles') as $data) {
$query = "UPDATE `glpi_plugin_manufacturersimports_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';";
$DB->query($query);
}
$migration->dropField('glpi_plugin_manufacturersimports_profiles', 'name');
Plugin::migrateItemType(array(2150 => 'PluginManufacturersimportsModel', 2151 => 'PluginManufacturersimportsConfig'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_manufacturersimports_models", "glpi_plugin_manufacturersimports_logs"));
}
//Migrate profiles to the system introduced in 0.85
PluginManufacturersimportsProfile::initProfile();
PluginManufacturersimportsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
//Drop old profile table : not used anymore
$migration->dropTable('glpi_plugin_manufacturersimports_profiles');
return true;
}
示例8: install
static function install(Migration $migration)
{
global $DB, $GENINVENTORYNUMBER_TYPES;
$table = getTableForItemType(__CLASS__);
if (TableExists("glpi_plugin_geninventorynumber_fields")) {
//Only migrate itemtypes when it's only necessary, otherwise it breaks upgrade procedure !
$migration->renameTable("glpi_plugin_geninventorynumber_fields", $table);
}
if (!TableExists($table)) {
$query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL auto_increment,\n `plugin_geninventorynumber_configs_id` int(11) NOT NULL default '0',\n `itemtype` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',\n `template` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',\n `is_active` tinyint(1) NOT NULL default '0',\n `use_index` tinyint(1) NOT NULL default '0',\n `index` bigint(20) NOT NULL default '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query);
} else {
$migration->changeField($table, 'ID', 'id', 'autoincrement');
$migration->changeField($table, 'config_id', 'plugin_geninventorynumber_configs_id', 'integer');
if ($migration->changeField($table, 'device_type', 'itemtype', 'string')) {
$migration->migrationOneTable($table);
Plugin::migrateItemType(array(), array("glpi_displaypreferences"), array($table));
}
$migration->changeField($table, 'enabled', 'is_active', 'boolean');
$migration->changeField($table, 'use_index', 'use_index', 'boolean');
$migration->migrationOneTable($table);
}
$field = new self();
foreach ($GENINVENTORYNUMBER_TYPES as $type) {
if (!countElementsInTable($table, "`itemtype`='{$type}'")) {
$input["plugin_geninventorynumber_configs_id"] = 1;
$input["itemtype"] = $type;
$input["template"] = "<#######>";
$input["is_active"] = 0;
$input["index"] = 0;
$field->add($input);
}
}
}
示例9: plugin_moreticket_install
function plugin_moreticket_install()
{
global $DB;
include_once GLPI_ROOT . "/plugins/moreticket/inc/profile.class.php";
if (!TableExists("glpi_plugin_moreticket_configs")) {
// table sql creation
$DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/empty-1.2.0.sql");
}
PluginMoreticketProfile::initProfile();
PluginMoreticketProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
$migration = new Migration("1.1.0");
$migration->dropTable('glpi_plugin_moreticket_profiles');
if (!FieldExists("glpi_plugin_moreticket_configs", "solution_status")) {
$DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.1.sql");
}
if (FieldExists("glpi_plugin_moreticket_waitingtypes", "is_helpdeskvisible")) {
$DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.2.sql");
}
if (!FieldExists("glpi_plugin_moreticket_closetickets", "documents_id")) {
$DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.3.sql");
}
if (!FieldExists("glpi_plugin_moreticket_configs", "date_report_mandatory")) {
$DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.2.0.sql");
}
return true;
}
示例10: update0901to0905
/**
* Update from 0.90.1 to 0.90.5
*
* @return bool for success (will die for most error)
**/
function update0901to0905()
{
global $DB, $migration;
$updateresult = true;
$ADDTODISPLAYPREF = array();
//TRANS: %s is the number of new version
$migration->displayTitle(sprintf(__('Update to %s'), '0.90.5'));
$migration->setVersion('0.90.5');
$backup_tables = false;
$newtables = array();
foreach ($newtables as $new_table) {
// rename new tables if exists ?
if (TableExists($new_table)) {
$migration->dropTable("backup_{$new_table}");
$migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
$backup_tables = true;
$query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
}
}
if ($backup_tables) {
$migration->displayWarning("You can delete backup tables if you have no need of them.", true);
}
// fix https://github.com/glpi-project/glpi/issues/820
// remove empty suppliers in tickets
$query = "DELETE FROM glpi_suppliers_tickets\n WHERE suppliers_id = 0\n AND alternative_email = ''";
$DB->query($query);
// ************ Keep it at the end **************
$migration->executeMigration();
return $updateresult;
}
示例11: plugin_racks_install
function plugin_racks_install()
{
global $DB;
include_once GLPI_ROOT . "/plugins/racks/inc/profile.class.php";
$migration = new Migration("1.5.0");
$update = false;
if (!TableExists("glpi_plugin_rack_profiles") && !TableExists("glpi_plugin_racks_profiles")) {
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/empty-1.4.2.sql");
} elseif (TableExists("glpi_plugin_rack_content") && !FieldExists("glpi_plugin_rack_content", "first_powersupply")) {
$update = true;
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.0.2.sql");
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.1.0.sql");
} elseif (!TableExists("glpi_plugin_racks_profiles")) {
$update = true;
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.1.0.sql");
}
//from 1.1 version
if (TableExists("glpi_plugin_racks_racks") && !FieldExists("glpi_plugin_racks_racks", "otherserial")) {
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.2.1.sql");
}
if (TableExists("glpi_plugin_racks_racks") && !FieldExists("glpi_plugin_racks_racks", "users_id_tech")) {
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.3.0.sql");
}
if (!TableExists("glpi_plugin_racks_racktypes")) {
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.3.2.sql");
}
if (TableExists("glpi_plugin_racks_racktypes") && !FieldExists("glpi_plugin_racks_racktypes", "is_recursive")) {
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.4.1.sql");
}
if (TableExists("glpi_plugin_racks_profiles") && !FieldExists("glpi_plugin_racks_profiles", "open_ticket")) {
$DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.4.2.sql");
}
if ($update) {
foreach ($DB->request('glpi_plugin_racks_profiles') as $data) {
$query = "UPDATE `glpi_plugin_racks_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';";
$result = $DB->query($query);
}
$migration->dropField('glpi_plugin_racks_profiles', 'name');
Plugin::migrateItemType(array(4450 => 'PluginRacksRack', 4451 => 'PluginRacksOther'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_racks_racks_items", "glpi_plugin_racks_itemspecifications"));
}
$notepad_tables = array('glpi_plugin_racks_racks');
foreach ($notepad_tables as $t) {
// Migrate data
if (FieldExists($t, 'notepad')) {
$query = "SELECT id, notepad\n FROM `{$t}`\n WHERE notepad IS NOT NULL\n AND notepad <>'';";
foreach ($DB->request($query) as $data) {
$iq = "INSERT INTO `glpi_notepads`\n (`itemtype`, `items_id`, `content`, `date`, `date_mod`)\n VALUES ('" . getItemTypeForTable($t) . "', '" . $data['id'] . "',\n '" . addslashes($data['notepad']) . "', NOW(), NOW())";
$DB->queryOrDie($iq, "0.85 migrate notepad data");
}
$query = "ALTER TABLE `glpi_plugin_racks_racks` DROP COLUMN `notepad`;";
$DB->query($query);
}
}
//Migrate profiles to the system introduced in 0.85
PluginRacksProfile::initProfile();
PluginRacksProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
//Drop old profile table : not used anymore
$migration->dropTable('glpi_plugin_racks_profiles');
return true;
}
示例12: plugin_environment_install
function plugin_environment_install()
{
global $DB;
include_once GLPI_ROOT . "/plugins/environment/inc/profile.class.php";
$update = false;
if (TableExists("glpi_plugin_environment_profiles") && FieldExists("glpi_plugin_environment_profiles", "interface")) {
$update = true;
$DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.3.0.sql");
$DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.4.0.sql");
} else {
if (TableExists("glpi_plugin_environment_profiles") && FieldExists("glpi_plugin_environment_profiles", "connections")) {
$update = true;
$DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.4.0.sql");
}
}
if ($update) {
//Do One time on 0.78
$query_ = "SELECT *\n FROM `glpi_plugin_environment_profiles` ";
$result_ = $DB->query($query_);
if ($DB->numrows($result_) > 0) {
while ($data = $DB->fetch_array($result_)) {
$query = "UPDATE `glpi_plugin_environment_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';";
$result = $DB->query($query);
}
}
$query = "ALTER TABLE `glpi_plugin_environment_profiles`\n DROP `name` ;";
$result = $DB->query($query);
}
PluginEnvironmentProfile::initProfile();
PluginEnvironmentProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
$migration = new Migration("1.8.0");
$migration->dropTable('glpi_plugin_environment_profiles');
$_SESSION["glpi_plugin_environment_installed"] = 1;
return true;
}
示例13: install
public static function install(Migration $migration)
{
global $DB;
$table = getTableForItemType(__CLASS__);
if (!TableExists($table)) {
$query = "CREATE TABLE IF NOT EXISTS `{$table}` (\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 '1',\n `name` varchar(255) NOT NULL DEFAULT '',\n `comment` text collate utf8_unicode_ci,\n `color` varchar(50) NOT NULL DEFAULT '' COLLATE 'utf8_unicode_ci',\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error());
}
if (!FieldExists($table, 'type_menu')) {
$migration->addField($table, 'type_menu', "varchar(50) NOT NULL DEFAULT ''");
$migration->addKey($table, 'type_menu');
$migration->migrationOneTable($table);
}
// Version 0.90-1.1
$result = $DB->query("SHOW FIELDS FROM `{$table}` where Field ='type_menu'");
if ($result && $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
if (stristr($data["Type"], 'varchar') !== FALSE) {
$DB->query("ALTER TABLE `{$table}` DROP INDEX `type_menu`;");
$DB->query("ALTER TABLE `{$table}` MODIFY `type_menu` text COLLATE utf8_unicode_ci;");
$datas = getAllDatasFromTable($table, "`type_menu` IS NOT NULL");
if (!empty($datas)) {
foreach ($datas as $data) {
$itemtypes = PluginTagTagItem::getItemtypes($data['type_menu']);
$DB->query("UPDATE `{$table}` SET `type_menu` = '" . json_encode($itemtypes) . "' WHERE `id` = '" . $data['id'] . "'");
}
}
break;
}
}
}
return true;
}
示例14: updateXXtoXY
/**
* DO NOT FORGET TO REPLACE XX AND XY OCCURENCES WITH CORRECT VALUES
* Update from XX to XY
*
* @return bool for success (will die for most error)
**/
function updateXXtoXY()
{
global $DB, $migration, $CFG_GLPI;
$current_config = Config::getConfigurationValues('core');
$updateresult = true;
$ADDTODISPLAYPREF = array();
//TRANS: %s is the number of new version
$migration->displayTitle(sprintf(__('Update to %s'), 'XY'));
$migration->setVersion('XY');
$backup_tables = false;
// table already exist but deleted during the migration
// not table created during the migration
$newtables = array();
foreach ($newtables as $new_table) {
// rename new tables if exists ?
if (TableExists($new_table)) {
$migration->dropTable("backup_{$new_table}");
$migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
$backup_tables = true;
$query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
}
}
if ($backup_tables) {
$migration->displayWarning("You can delete backup tables if you have no need of them.", true);
}
//put you migration script here
// ************ Keep it at the end **************
$migration->executeMigration();
return $updateresult;
}
示例15: plugin_groupead_install
/**
* Fonction d'installation du plugin
* @return boolean
*/
function plugin_groupead_install()
{
global $DB;
$miseAjour = false;
//parcour du tableau des tables à créer
foreach (plugin_groupead_getListeTable() as $id => $table) {
if (!TableExists($id)) {
$requeteInsert = "";
foreach ($table as $key => $value) {
if ($requeteInsert != "") {
$requeteInsert .= ",`" . $key . "` " . $value;
} else {
$requeteInsert .= "`" . $key . "` " . $value;
}
//si premier enregistrement pas de virgule
}
$query = "CREATE TABLE `" . $id . "` (" . $requeteInsert . ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die($DB->error());
} else {
$miseAjour = true;
}
}
//enregistrement spéciaux
//creation du premier accès nécessaire lors de l'installation du plugin
if ($miseAjour) {
plugin_groupead_miseAjour();
} else {
foreach (plugin_groupead_getFirstInsert() as $query) {
$DB->query($query) or die($DB->error());
}
}
return true;
}