/** * * @param string $module * @param string $action */ public static function update($module, $action = 'create') { $targetDbName = 'centreon'; ini_set('memory_limit', '-1'); $di = Di::getDefault(); $config = $di->get('config'); $targetDb = 'db_centreon'; $db = $di->get($targetDb); // Configuration for Propel $configParams = array('propel.project' => 'centreon', 'propel.database' => 'mysql', 'propel.database.url' => $config->get($targetDb, 'dsn'), 'propel.database.user' => $config->get($targetDb, 'username'), 'propel.database.password' => $config->get($targetDb, 'password')); // Set the Current Platform and DB Connection $platform = new CentreonMysqlPlatform($db); // Initilize Schema Parser $propelDb = new \MysqlSchemaParser($db); $propelDb->setGeneratorConfig(new \GeneratorConfig($configParams)); $propelDb->setPlatform($platform); // get Current Db State $currentDbAppData = new \AppData($platform); $currentDbAppData->setGeneratorConfig(new \GeneratorConfig($configParams)); $currentDb = $currentDbAppData->addDatabase(array('name' => $targetDbName)); $propelDb->parse($currentDb); // Retreive target DB State $updatedAppData = new \AppData($platform); self::getDbFromXml($updatedAppData, 'centreon'); // Get diff between current db state and target db state $diff = \PropelDatabaseComparator::computeDiff($currentDb, $updatedAppData->getDatabase('centreon'), false); if ($diff !== false) { $strDiff = $platform->getModifyDatabaseDDL($diff); $sqlToBeExecuted = \PropelSQLParser::parseString($strDiff); $finalSql = "\nSET FOREIGN_KEY_CHECKS = 0;\n\n"; if ($action == 'create') { $finalSql .= implode(";\n\n", static::keepCreateStatement($sqlToBeExecuted, $module)); } elseif ($action == 'delete') { $finalSql .= implode(";\n\n", static::keepDeleteStatement($sqlToBeExecuted, $module)); } $finalSql .= ";\n\nSET FOREIGN_KEY_CHECKS = 1;\n\n"; \PropelSQLParser::executeString($finalSql, $db); } // Empty Target DB self::deleteTargetDbSchema($targetDbName); }
protected static function initializeCurrentSchema($platform) { $configParams = array('propel.project' => 'centreon', 'propel.database' => 'mysql', 'propel.database.driver' => 'mysql', 'propel.database.createUrl' => 'mysql://root@localhost/', 'propel.database.url' => 'mysql:dbname=centreon;host=localhost', 'propel.database.user' => 'root', 'propel.database.password' => '', 'propel.database.encoding' => 'utf-8'); // Initilize Schema Parser $db = Di::getDefault()->get('db_centreon'); $propelDb = new \MysqlSchemaParser($db); $propelDb->setGeneratorConfig(new \GeneratorConfig($configParams)); $propelDb->setPlatform($platform); // get Current Db State $currentDbAppData = new \AppData($platform); $currentDbAppData->setGeneratorConfig(new \GeneratorConfig($configParams)); $currentDb = $currentDbAppData->addDatabase(array('name' => 'centreon')); $propelDb->parse($currentDb); return $currentDb; }