/** * Initialize the schema (tables) */ static function __initSchema() { if (empty(self::$__cacheSchemaChanges['vtiger_links'])) { if (!Vtiger_Utils::CheckTable('vtiger_links')) { Vtiger_Utils::CreateTable('vtiger_links', '(linkid INT NOT NULL PRIMARY KEY, tabid INT, linktype VARCHAR(20), linklabel VARCHAR(30), linkurl VARCHAR(255), linkicon VARCHAR(100), sequence INT, status INT(1) NOT NULL DEFAULT 1)', true); Vtiger_Utils::ExecuteQuery('CREATE INDEX link_tabidtype_idx on vtiger_links(tabid,linktype)'); } self::$__cacheSchemaChanges['vtiger_links'] = true; } }
/** * Import Tables of the module * @access private */ function import_Tables($modulenode) { if (empty($modulenode->tables) || empty($modulenode->tables->table)) { return; } $adb = PearDatabase::getInstance(); $adb->query('SET FOREIGN_KEY_CHECKS = 0;'); /** * Record the changes in schema file */ if (file_exists("modules/{$modulenode->name}")) { $fileToOpen = "modules/{$modulenode->name}/schema.xml"; } else { if (file_exists("modules/Settings/{$modulenode->name}")) { $fileToOpen = "modules/Settings/{$modulenode->name}/schema.xml"; } } $schemafile = fopen($fileToOpen, 'w'); if ($schemafile) { fwrite($schemafile, "<?xml version='1.0'?>\n"); fwrite($schemafile, "<schema>\n"); fwrite($schemafile, "\t<tables>\n"); } // Import the table via queries foreach ($modulenode->tables->table as $tablenode) { $tablename = $tablenode->name; $tablesql = "{$tablenode->sql}"; // Convert to string format // Save the information in the schema file. fwrite($schemafile, "\t\t<table>\n"); fwrite($schemafile, "\t\t\t<name>{$tablename}</name>\n"); fwrite($schemafile, "\t\t\t<sql><![CDATA[{$tablesql}]]></sql>\n"); fwrite($schemafile, "\t\t</table>\n"); // Avoid executing SQL that will DELETE or DROP table data if (Vtiger_Utils::IsCreateSql($tablesql)) { if (!Vtiger_Utils::checkTable($tablename)) { self::log("SQL: {$tablesql} ... ", false); Vtiger_Utils::ExecuteQuery($tablesql); self::log("DONE"); } } else { if (Vtiger_Utils::IsDestructiveSql($tablesql)) { self::log("SQL: {$tablesql} ... SKIPPED"); } else { self::log("SQL: {$tablesql} ... ", false); Vtiger_Utils::ExecuteQuery($tablesql); self::log("DONE"); } } } if ($schemafile) { fwrite($schemafile, "\t</tables>\n"); fwrite($schemafile, "</schema>\n"); fclose($schemafile); } $adb->query('SET FOREIGN_KEY_CHECKS = 1;'); }
/** * Import Tables of the module * @access private */ function import_Tables($modulenode) { if (empty($modulenode->tables) || empty($modulenode->tables->table)) { return; } /** * Record the changes in schema file */ $schemafile = @fopen("modules/{$modulenode->name}/schema.xml", 'w'); if ($schemafile) { fwrite($schemafile, "<?xml version='1.0'?>\n"); fwrite($schemafile, "<schema>\n"); fwrite($schemafile, "\t<tables>\n"); } // Import the table via queries foreach ($modulenode->tables->table as $tablenode) { $tablename = $tablenode->name; $tablesql = "{$tablenode->sql}"; // Convert to string format // Save the information in the schema file. if ($schemafile) { fwrite($schemafile, "\t\t<table>\n"); fwrite($schemafile, "\t\t\t<name>{$tablename}</name>\n"); fwrite($schemafile, "\t\t\t<sql><![CDATA[{$tablesql}]]></sql>\n"); fwrite($schemafile, "\t\t</table>\n"); } // Avoid executing SQL that will DELETE or DROP table data if (Vtiger_Utils::IsCreateSql($tablesql)) { if (!Vtiger_Utils::checkTable($tablename)) { self::log("SQL: {$tablesql} ... ", false); Vtiger_Utils::ExecuteQuery($tablesql); self::log("DONE"); } } else { if (Vtiger_Utils::IsDestructiveSql($tablesql)) { self::log("SQL: {$tablesql} ... SKIPPED"); } else { self::log("SQL: {$tablesql} ... ", false); Vtiger_Utils::ExecuteQuery($tablesql); self::log("DONE"); } } } if ($schemafile) { fwrite($schemafile, "\t</tables>\n"); fwrite($schemafile, "</schema>\n"); fclose($schemafile); } }
/** * Handle migration of the module * @access private */ function handle_Migration($modulenode, $moduleInstance) { // TODO Handle module migration SQL $this->parse_Migration($modulenode); $cur_version = $moduleInstance->version; foreach ($this->_migrations as $migversion => $migrationnode) { // Perform migration only for higher version than current if (version_compare($cur_version, $migversion, '<')) { self::log("Migrating to {$migversion} ... STARTED"); if (!empty($migrationnode->tables) && !empty($migrationnode->tables->table)) { foreach ($migrationnode->tables->table as $tablenode) { $tablename = $tablenode->name; $tablesql = "{$tablenode->sql}"; // Convert to string // Skip SQL which are destructive if (Vtiger_Utils::IsDestructiveSql($tablesql)) { self::log("SQL: {$tablesql} ... SKIPPED"); } else { // Supress any SQL query failures self::log("SQL: {$tablesql} ... ", false); Vtiger_Utils::ExecuteQuery($tablesql, true); self::log("DONE"); } } } self::log("Migrating to {$migversion} ... DONE"); } } }