public function testCompareVersion() { // 0 = equals // -1 : v1 < v2 // 1 : v1 > v2 $this->assertEqual(0, jVersionComparator::compareVersion('1.0', '1.0')); $this->assertEqual(1, jVersionComparator::compareVersion('1.1', '1.0')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.0', '1.1')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.1', '1.1.1')); $this->assertEqual(1, jVersionComparator::compareVersion('1.1.2', '1.1')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2', '1.2b')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2', '1.2a')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2', '1.2RC')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2', '1.2bETA')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2', '1.2alpha')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2', '1.2pre')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2b', '1.2')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2a', '1.2')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2RC', '1.2')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2bEta', '1.2')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2alpha', '1.2')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2b1', '1.2b2')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2B1', '1.2b2')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2b2', '1.2b1')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2b2', '1.2b2-dev')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2b2-dev', '1.2b2')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2b2-dev.2324', '1.2b2')); $this->assertEqual(0, jVersionComparator::compareVersion('1.2b2pre', '1.2b2-dev')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2b2pre.4', '1.2b2-dev')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2b2pre.4', '1.2b2-dev.9')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2b2pre', '1.2b2-dev.9')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2RC1', '1.2RC2')); $this->assertEqual(0, jVersionComparator::compareVersion('1.2.3a1pre', '1.2.3a1-dev')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2RC-dev', '1.2RC')); $this->assertEqual(1, jVersionComparator::compareVersion('1.2RC', '1.2RC-dev')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2pre', '1.2a')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2pre', '1.2b')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2pre', '1.2RC')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2PRE', '1.2RC')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2a', '1.2b')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2b', '1.2rc')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.2rc', '1.2')); $this->assertEqual(0, jVersionComparator::compareVersion('1.*', '1')); $this->assertEqual(0, jVersionComparator::compareVersion('1.1.*', '1.1.1')); $this->assertEqual(0, jVersionComparator::compareVersion('1.1.2', '1.1.*')); $this->assertEqual(0, jVersionComparator::compareVersion('1.1.*', '1.1')); $this->assertEqual(0, jVersionComparator::compareVersion('1.1', '1.1.*')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.1.*', '1.2')); $this->assertEqual(-1, jVersionComparator::compareVersion('1.1', '1.2.*')); $this->assertEqual(0, jVersionComparator::compareVersion('1.1', '*')); $this->assertEqual(0, jVersionComparator::compareVersion('*', '1.1')); }
public function isUpgraded($epId) { return $this->isInstalled($epId) && \jVersionComparator::compareVersion($this->moduleInfos->version, $this->moduleStatuses[$epId]->version) == 0; }
public function checkVersion($min, $max) { return jVersionComparator::compareVersion($min, $this->sourceVersion) <= 0 && jVersionComparator::compareVersion($this->sourceVersion, $max) <= 0; }
/** * return the list of objects which are responsible to upgrade the component * from the current installed version of the component. * * this method should be called after verifying and resolving * dependencies. Needed components (modules or plugins) should be * installed/upgraded before calling this method * * @param jInstallerEntryPoint $ep the entry point * @throw jInstallerException if an error occurs during the install. * @return array array of jIInstallerComponent */ function getUpgraders($ep) { $epId = $ep->getEpId(); if ($this->moduleUpgraders === null) { $this->moduleUpgraders = array(); $p = $this->path . 'install/'; if (!file_exists($p) || $this->moduleInfos[$epId]->skipInstaller) { return array(); } // we get the list of files for the upgrade $fileList = array(); if ($handle = opendir($p)) { while (false !== ($f = readdir($handle))) { if (!is_dir($p . $f)) { if (preg_match('/^upgrade_to_([^_]+)_([^\\.]+)\\.php$/', $f, $m)) { $fileList[] = array($f, $m[1], $m[2]); } else { if (preg_match('/^upgrade_([^\\.]+)\\.php$/', $f, $m)) { $fileList[] = array($f, '', $m[1]); } } } } closedir($handle); } if (!count($fileList)) { return array(); } // now we order the list of file foreach ($fileList as $fileInfo) { require_once $p . $fileInfo[0]; $cname = $this->name . 'ModuleUpgrader_' . $fileInfo[2]; if (!class_exists($cname)) { throw new jInstallerException("module.upgrader.class.not.found", array($cname, $this->name)); } $upgrader = new $cname($this->name, $fileInfo[2], $this->path, $fileInfo[1], false); if ($fileInfo[1] && count($upgrader->targetVersions) == 0) { $upgrader->targetVersions = array($fileInfo[1]); } $this->moduleUpgraders[] = $upgrader; } } $list = array(); foreach ($this->moduleUpgraders as $upgrader) { $foundVersion = ''; // check the version foreach ($upgrader->targetVersions as $version) { if (jVersionComparator::compareVersion($this->moduleInfos[$epId]->version, $version) >= 0) { // we don't execute upgraders having a version lower than the installed version (they are old upgrader) continue; } if (jVersionComparator::compareVersion($this->sourceVersion, $version) < 0) { // we don't execute upgraders having a version higher than the version indicated in the module.xml continue; } $foundVersion = $version; // when multiple version are specified, we take the first one which is ok break; } if (!$foundVersion) { continue; } $upgrader->version = $foundVersion; // we have to check now the date of versions // we should not execute the updater in some case. // for example, we have an updater for the 1.2 and 2.3 version // we have the 1.4 installed, and want to upgrade to the 2.5 version // we should not execute the update for 2.3 since modifications have already been // made into the 1.4. The only way to now that, is to compare date of versions if ($upgrader->date != '' && $this->mainInstaller) { $upgraderDate = $this->_formatDate($upgrader->date); // the date of the first version installed into the application $firstVersionDate = $this->_formatDate($this->mainInstaller->installerIni->getValue($this->name . '.firstversion.date', $epId)); if ($firstVersionDate !== null) { if ($firstVersionDate >= $upgraderDate) { continue; } } // the date of the current installed version $currentVersionDate = $this->_formatDate($this->mainInstaller->installerIni->getValue($this->name . '.version.date', $epId)); if ($currentVersionDate !== null) { if ($currentVersionDate >= $upgraderDate) { continue; } } } $upgrader->setParameters($this->moduleInfos[$epId]->parameters); $class = get_class($upgrader); if (!isset($this->upgradersContexts[$class])) { $this->upgradersContexts[$class] = array(); } $upgrader->setEntryPoint($ep, $ep->configIni, $this->moduleInfos[$epId]->dbProfile, $this->upgradersContexts[$class]); $list[] = $upgrader; } // now let's sort upgrader, to execute them in the right order (oldest before newest) usort($list, function ($upgA, $upgB) { return jVersionComparator::compareVersion($upgA->version, $upgB->version); }); return $list; }
/** * update informations about jelix version in a module.xml or project.xml file */ protected function updateJelixDependency($doc) { $info = $this->firstElementChild($doc->documentElement); $dep = $this->nextElementSibling($info, 'dependencies'); $jelix = $this->firstElementChild($dep, 'jelix'); if (!$jelix->hasAttribute('minversion')) { $jelix->setAttribute('minversion', JELIX_VERSION); } if (!$jelix->hasAttribute('maxversion') || jVersionComparator::compareVersion($jelix->getAttribute('maxversion'), JELIX_VERSION) == -1) { $jelix->setAttribute('maxversion', jVersionComparator::getBranchVersion(JELIX_VERSION) . '.*'); } }
/** * internal use. callback function for the sort of the list of upgraders files * @param array $fileA informations about the first file * @param array $fileB informations about the second file * @return integer 0 if equal, -1 if $versionA < $versionB, 1 if $versionA > $versionB */ function sortFileList($fileA, $fileB) { return jVersionComparator::compareVersion($fileA[1], $fileB[1]); }
function sortUpgraderList($upgA, $upgB) { return jVersionComparator::compareVersion($upgA->version, $upgB->version); }
function compare($value) { $result = jVersionComparator::compareVersion($value, $this->operand); switch ($this->op) { case self::OP_EQ: return $result === 0; case self::OP_LT: return $result === -1; case self::OP_GT: return $result === 1; case self::OP_LTE: return $result < 1; break; case self::OP_GTE: return $result > -1; break; case self::OP_DIFF: return $result != 0; } return false; }