public function install() { $messageSchema = $this->messagesSchemaProvider->getSchemaFor($this->messagesTableName); $endpointSchema = $this->endpointSchemaProvider->getSchemaFor($this->endpointsTableName); // is there a better way to atomically create in order to not compete with other endpoints? try { $this->databaseSynchronizer->createSchema($messageSchema); } catch (TableExistsException $e) { } try { $this->databaseSynchronizer->createSchema($endpointSchema); } catch (TableExistsException $e) { } }
/** * update * * @param string $mod module dirname * * @return mixed boolean false if failed, XoopsModule if success */ public function update($mod = '') { $xoops = Xoops::getInstance(); $module_handler = $xoops->getHandlerModule(); $module = $module_handler->getByDirname($mod); $xoops->templateClearModuleCache($module->getVar('mid')); // Save current version for use in the update function $prev_version = $module->getVar('version'); // we dont want to change the module name set by admin $temp_name = $module->getVar('name'); $module->loadInfoAsVar($module->getVar('dirname')); $module->setVar('name', $temp_name); $module->setVar('last_update', time()); if (!$module_handler->insertModule($module)) { $this->error[] = sprintf(XoopsLocale::EF_NOT_UPDATED, "<strong>" . $module->getVar('name') . "</strong>"); return false; } else { // execute module specific preupdate script if any $update_script = $module->getInfo('onUpdate'); if (false != $update_script && trim($update_script) != '') { XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($update_script))); $func = 'xoops_module_preupdate_' . $mod; if (function_exists($func)) { $result = $func($module, $prev_version); if (!$result) { $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func); $this->trace = array_merge($this->error, $module->getErrors()); } else { $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>"); $this->trace = array_merge($this->trace, $module->getMessages()); } } } // update schema $schema_file = $module->getInfo('schema'); if (!empty($schema_file)) { $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file; if (!XoopsLoad::fileExists($schema_file_path)) { $this->error[] = sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>"); return false; } $importer = new ImportSchema(); $importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path)); $synchronizer = new SingleDatabaseSynchronizer($xoops->db()); $synchronizer->updateSchema($importSchema, true); } // delete templates $this->deleteTemplates($module); // install templates $this->installTemplates($module); // install blocks $this->installBlocks($module); // reset compile_id $xoops->tpl()->setCompileId(); // first delete all config entries $this->deleteConfigs($module); // Install Configs $this->installConfigs($module, 'update'); // execute module specific update script if any $update_script = $module->getInfo('onUpdate'); if (false != $update_script && trim($update_script) != '') { XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($update_script))); $func = 'xoops_module_update_' . $mod; if (function_exists($func)) { $result = $func($module, $prev_version); if (!$result) { $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func); $this->trace = array_merge($this->error, $module->getErrors()); } else { $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>"); $this->trace = array_merge($this->trace, $module->getMessages()); } } } $this->trace[] = sprintf(XoopsLocale::SF_UPDATED, '<strong>' . $module->getVar('name', 's') . '</strong>'); return $module; } }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); // make sure schemas exists $sm = $this->sc->getSchemaManager(); $this->validateSchema($this->getConfig('source')); echo "Creating target schema\n"; // create schema if it doesn't exist if (($db = $this->getOptionalConfig('target.dbname')) !== null && $this->validateSchema($this->getConfig('target'), false) == false) { // get schema-less connection $_config = $this->getConfig('target'); unset($_config['dbname']); $conn = \Doctrine\DBAL\DriverManager::getConnection($_config); $tm = $conn->getSchemaManager(); echo "Creating database\n"; $tm->createDatabase($db); } try { $schema = $sm->createSchema(); echo "Creating tables\n"; // sync configured tables only if ($tables = $this->getOptionalConfig('tables')) { // extract target table names $tables = array_column($tables, 'name'); foreach ($schema->getTables() as $table) { if (!in_array($table->getName(), $tables)) { $schema->dropTable($table->getName()); } } } // make sure schema is free of conflicts for target platform if (in_array($platform = $this->tc->getDatabasePlatform()->getName(), array('sqlite'))) { $this->updateSchemaForTargetPlatform($schema, $platform); } $synchronizer = new SingleDatabaseSynchronizer($this->tc); $synchronizer->createSchema($schema); } catch (\Exception $e) { $sql = $schema->toSql($this->tc->getDatabasePlatform()); echo join($sql, "\n"); throw $e; } }
/** * Execute teardown tasks. */ public function onTeardown() { $connection = $this->getConnection(); $synchronizer = new SingleDatabaseSynchronizer($connection); $synchronizer->dropSchema($this->getSchema()); }