protected function execute(InputInterface $input, OutputInterface $output) { $configuration = CodePax_Config::getInstance(CONFIG_PATH . 'config.ini'); $db_versions_model = CodePax_DbVersions::factory($configuration); $latest_structure_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_CHANGE_SCRIPT); $latest_data_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_DATA_CHANGE_SCRIPT); $db_versioning_handler = CodePax_DbVersioning_Environments_Factory::factory($configuration); $change_scripts = $db_versioning_handler->getChangeScripts(); $data_change_scripts = $db_versioning_handler->getDataChangeScripts(); $output->writeln('Environment: ' . strtoupper($configuration->application_environment)); $output->writeln(''); $output->writeln('Database name: ' . $configuration->db_name); $output->writeln('Database structure version: ' . $latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE]); $output->writeln('Database structure last update: ' . $latest_structure_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]); $output->writeln('Database data version: ' . $latest_data_version[CodePax_DbVersions::VERSION_ATTRIBUTE]); $output->writeln('Database data last update: ' . (!empty($latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]) ? $latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE] : 'n/a')); $output->writeln(''); if (strtolower($configuration->application_environment) == 'dev') { $output->writeln('Baseline version: ' . $db_versioning_handler->getLatestBaselineVersion()); } $output->writeln('Change structure scripts to run: '); $output->writeln(!empty($change_scripts) ? implode("\n", array_keys($change_scripts)) : 'n/a'); $output->writeln('Change data scripts to run: '); $output->writeln(!empty($data_change_scripts) ? implode("\n", array_keys($data_change_scripts)) : 'n/a'); }
/** * Create required instances * * @return void * */ public function __construct() { // create the sql handler $this->sql_engine = CodePax_DbVersioning_SqlEngines_Factory::factory(); // factory the Model that handles the versions table $this->db_versions_model = CodePax_DbVersions::factory(); // set the structure version $this->setLatestDbVersion(); // set the data version $this->setLatestDataDbVersion(); }
/** * Return database versioning information * * @return stdClass * @throws CodePax_DbVersioning_Exception */ public function info() { $databaseVersioningInfo = new stdClass(); // get current DB version $db_versions_model = CodePax_DbVersions::factory($this->configuration); if (in_array($this->configuration->application_environment, array('dev', 'prod'))) { $latest_baseline_file = $this->filesManager->getLatestBaselineVersion(); if (!$db_versions_model->checkIsVersionRegistred($latest_baseline_file, CodePax_DbVersions::TYPE_BASELINE)) { $db_versions_model->addVersion($latest_baseline_file, CodePax_DbVersions::TYPE_BASELINE); } } $latest_structure_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_CHANGE_SCRIPT); $latest_data_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_DATA_CHANGE_SCRIPT); $databaseVersioningInfo->database_name = $this->configuration->db_name; $databaseVersioningInfo->database_structure_version = $latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE]; $databaseVersioningInfo->database_structure_last_update = $latest_structure_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]; $databaseVersioningInfo->database_data_version = $latest_data_version[CodePax_DbVersions::VERSION_ATTRIBUTE]; $databaseVersioningInfo->database_data_last_update = !empty($latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]) ? $latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE] : 'n/a'; // get change scripts to run $db_versioning_handler = CodePax_DbVersioning_Environments_Factory::factory($this->configuration); $change_scripts = $db_versioning_handler->getChangeScripts(); $data_change_scripts = $db_versioning_handler->getDataChangeScripts(); $new_baseline_available = false; if (in_array($this->configuration->application_environment, array('dev', 'prod'))) { $new_baseline_available = version_compare($latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE], $db_versioning_handler->getLatestBaselineVersion()) == -1; } // database is up-to-date $databaseVersioningInfo->baseline_script = null; $databaseVersioningInfo->db_versioning_dev_note = false; $databaseVersioningInfo->db_scripts = array(); $databaseVersioningInfo->data_db_scripts = array(); if (empty($change_scripts) && empty($data_change_scripts) && !$new_baseline_available) { $databaseVersioningInfo->db_is_updated = true; } else { //database is not up to date $databaseVersioningInfo->db_is_updated = false; // data change scripts if (!empty($change_scripts)) { $databaseVersioningInfo->db_scripts = array_keys($change_scripts); } // data change scripts if (!empty($data_change_scripts)) { $databaseVersioningInfo->data_db_scripts = array_keys($data_change_scripts); } // when on DEV, show extra info if ($this->configuration->application_environment == 'dev') { $databaseVersioningInfo->baseline_script = $db_versioning_handler->getLatestBaselineVersion(); $databaseVersioningInfo->db_versioning_dev_note = true; } } return $databaseVersioningInfo; }
if (VERSIONING == 'SVN' && !empty($response_string) && is_numeric(strpos(strtolower($response_string), "run 'svn cleanup' to remove locks (type 'svn help cleanup' for details)"))) { $view->working_copy_locked = true; } //--- show HOOKS section if (defined('USE_HOOKS')) { $view->use_hooks = USE_HOOKS; $hooks_hanlder = new CodePax_Hooks_Handler(); $hooks = $hooks_hanlder->getList(); $view->hooks = array_keys($hooks); } //--- show Db versioning section if (defined('USE_DB_VERSIONING') && USE_DB_VERSIONING === true) { $view->use_db_versioning = true; try { // get current DB version $db_versions_model = CodePax_DbVersions::factory(); if (in_array(APPLICATION_ENVIRONMENT, array('dev', 'prod'))) { $latest_baseline_file = CodePax_DbVersioning_Files_Manager::getLatestBaselineVersion(); if (!$db_versions_model->checkIsVersionRegistred($latest_baseline_file, CodePax_DbVersions::TYPE_BASELINE)) { $db_versions_model->addVersion($latest_baseline_file, CodePax_DbVersions::TYPE_BASELINE); } } $latest_structure_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_CHANGE_SCRIPT); $latest_data_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_DATA_CHANGE_SCRIPT); $view->database_name = DB_NAME; $view->database_structure_version = $latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE]; $view->database_structure_last_update = $latest_structure_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]; $view->database_data_version = $latest_data_version[CodePax_DbVersions::VERSION_ATTRIBUTE]; $view->database_data_last_update = !empty($latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]) ? $latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE] : 'n/a'; // get change scripts to run $db_versioning_handler = CodePax_DbVersioning_Environments_Factory::factory(APPLICATION_ENVIRONMENT);
/** * Drop and recreate the database * using the provided DB Engine * * @return void * */ private function dropAndRecreateDb() { $this->sql_engine->dropAndCreateDb(); //for SQL Server get a new DB version model instance //SQL Server closes the connection if we drop the database if (DB_ENGINE == 'sqlsrv') { $this->db_versions_model = CodePax_DbVersions::factory(); } }
/** * Class constructor for the environment object * * @param $configuration * @throws CodePax_DbVersioning_Exception */ public function __construct($configuration) { // set the configuration param $this->configuration = $configuration; // set the files manager instance $this->filesManager = new CodePax_DbVersioning_Files_Manager($this->configuration); // create the sql handler $this->sql_engine = CodePax_DbVersioning_SqlEngines_Factory::factory($this->configuration); // factory the Model that handles the versions table $this->db_versions_model = CodePax_DbVersions::factory($this->configuration); // set the structure version $this->setLatestDbVersion(); // set the data version $this->setLatestDataDbVersion(); }