/** * Retrieve the modules needing upgrades. * * The return value will be in following format: * array( * ModuleName => array( * 'from' => string: The current version in the db. * 'to' => string: The current code version of the module. * 'migration' => Phprojekt_Migration_Abstract: The module's * migration object. * ) * ) * * @return array See description */ public function getModulesNeedingUpgrade() { if (!is_null($this->_modulesNeedingUpgrade)) { return $this->_modulesNeedingUpgrade; } $db = Phprojekt::getInstance()->getDb(); $moduleVersions = $db->fetchAssoc('SELECT LOWER(name), version FROM module'); $return = array(); foreach ($this->_migrations as $module => $migration) { $module = strtolower($module); $codeVersion = $migration->getCurrentModuleVersion(); if (array_key_exists($module, $moduleVersions)) { // The module is already installed and we are upgrading. $moduleVersion = $moduleVersions[$module]['version']; $compare = Phprojekt::compareVersion($moduleVersion, $codeVersion); if ($compare > 0) { // The current db version is higher than the code version. // TODO: Handle this. } else { if ($compare < 0) { $return[$module] = array('from' => $moduleVersion, 'to' => $codeVersion, 'migration' => $migration); } } } else { // The module is new. Add it to the list $return[$module] = array('from' => null, 'to' => $codeVersion, 'migration' => $migration); } } $this->_modulesNeedingUpgrade = $return; return $return; }
public function testCompareVersion() { $this->assertGreaterThan(0, Phprojekt::compareVersion("6.0.10", Phprojekt::getVersion())); $this->assertGreaterThan(0, Phprojekt::compareVersion("6.0.1", "6.0.0")); $this->assertLessThan(0, Phprojekt::compareVersion("6.0.1", "6.1.0")); $this->assertGreaterThan(0, Phprojekt::compareVersion("6.0.1-RC2", "6.0.1-RC1")); $this->assertLessThan(0, Phprojekt::compareVersion("6.0.0-RC1", "6.0.0")); $this->assertEquals(0, Phprojekt::compareVersion("6.0.0-RC1", "6.0.0-RC1")); $this->assertEquals(0, Phprojekt::compareVersion("6.0.1", "6.0.1")); }
/** * Upgrade to the latest version. * * @param String $currentVersion Phprojekt version string indicating our * current version * @param Zend_Db_Adapter_Abstract $db The database to use * * @return void * @throws Exception On Errors */ public function upgrade($currentVersion, Zend_Db_Adapter_Abstract $db) { $this->_db = $db; if (Phprojekt::compareVersion($currentVersion, '6.1.5') < 0) { $this->_renameFilemanagersWithSameTitle(); $this->parseDbFile('Filemanager'); Phprojekt::getInstance()->getCache()->clean(Zend_Cache::CLEANING_MODE_ALL); $this->_renameFilesWithSameName(); } }
/** * Upgrade to the latest version. * * @param String $currentVersion Phprojekt version string indicating our * current version * @param Zend_Db_Adapter_Abstract $db The database to use * * @return void * @throws Exception On Errors */ public function upgrade($currentVersion, Zend_Db_Adapter_Abstract $db) { date_default_timezone_set('utc'); $this->_db = $db; if (is_null($currentVersion) || Phprojekt::compareVersion($currentVersion, '6.1.0-beta1') < 0) { $this->parseDbFile('Calendar2'); Phprojekt::getInstance()->getCache()->clean(Zend_Cache::CLEANING_MODE_ALL); $this->_migrateFromOldCalendar(); $this->_removeOldCalendar(); } }
/** * Upgrade to the latest version. * * @param String $currentVersion Phprojekt version string indicating our * current version * @param Zend_Db_Adapter_Abstract $db The database to use * * @return void * @throws Exception On Errors */ public function upgrade($currentVersion, Zend_Db_Adapter_Abstract $db) { date_default_timezone_set('utc'); $this->_db = $db; $this->parseDbFile('Timecard'); if (Phprojekt::compareVersion($currentVersion, '6.1.4') < 0) { $request = new Zend_Controller_Request_Http(); $uidSuffix = "@phprojekt6-" . $request->getHttpHost(); Phprojekt::getInstance()->getDB()->query("UPDATE timecard SET uri = id, uid = CONCAT(UUID(), \"{$uidSuffix}\");"); // This is mysql-only. Not sure if this is the ultimate way to go here. Phprojekt::getInstance()->getDB()->query('ALTER TABLE timecard ADD UNIQUE (uri)'); } }
private function patchOldModuleGrids() { $applicationPath = Phprojekt::getInstance()->getConfig()->applicationPath; $moduleDirs = scandir($applicationPath); foreach ($moduleDirs as $moduleName) { if ($moduleName != "." && $moduleName != "..") { $select = $this->_db->select()->from("module", array("version", "id"))->where("name = ?", $moduleName)->limit(1); $row = $this->_db->fetchRow($select); if ($row !== false && Phprojekt::compareVersion($row["version"], "6.2.1") < 0) { $this->patchOldModuleGrid($moduleName); $this->_db->update("module", array("version" => "6.2.1"), $this->_db->quoteInto("id = ?", $row["id"])); } } } }
/** * Delete all the version higher than the current one * and the version lower than the current module version. * * @param string $module Current module of the data. * @param array $data Array with all the version and data for parse. * * @return array Array with only the correct versions. */ private function _getVersionsForProcess($module, $data) { $current = Phprojekt::getVersion(); $moduleVersion = $this->_getModuleVersion($module); foreach (array_keys($data) as $version) { if (Phprojekt::compareVersion($moduleVersion, $version) > 0 || Phprojekt::compareVersion($current, $version) < 0) { unset($data[$version]); } } return $data; }