|
|
|
@ -3,16 +3,13 @@
|
|
|
|
|
namespace Spip\Cli\Command; |
|
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
|
|
|
|
|
class CoreListerVersions extends Command { |
|
|
|
|
private $chemin_svn_racine = 'svn://trac.rezo.net/spip'; |
|
|
|
|
private $versions = array(); |
|
|
|
|
private $last = ''; |
|
|
|
|
|
|
|
|
|
public const _SPIP_GIT_REPO = 'https://git.spip.net/spip/spip.git'; |
|
|
|
|
|
|
|
|
|
protected function configure() { |
|
|
|
|
$this |
|
|
|
|
->setName('core:listerversions') |
|
|
|
@ -22,140 +19,153 @@ class CoreListerVersions extends Command {
|
|
|
|
|
't', |
|
|
|
|
InputOption::VALUE_OPTIONAL, |
|
|
|
|
'branches ou tags ?', |
|
|
|
|
'' // Par défaut, tout |
|
|
|
|
'branches' // Par défaut, les tags |
|
|
|
|
) |
|
|
|
|
->setAliases(array( |
|
|
|
|
'versions' |
|
|
|
|
)) |
|
|
|
|
->setAliases(['versions']) |
|
|
|
|
; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* execute |
|
|
|
|
* |
|
|
|
|
* @param mixed $input |
|
|
|
|
* @param mixed $output |
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
|
|
|
// On travaille dans le dossier courant |
|
|
|
|
$dossier = getcwd(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$type = $input->getOption('type'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('passthru')) { |
|
|
|
|
$output->writeln("<error>Votre installation de PHP doit pouvoir exécuter des commandes externes avec la fonction passthru().</error>"); |
|
|
|
|
$output->writeln('<error>Votre installation de PHP doit pouvoir exécuter des commandes externes avec la fonction passthru().</error>'); |
|
|
|
|
return Command::FAILURE; |
|
|
|
|
} |
|
|
|
|
// Si c'est bon on continue |
|
|
|
|
else{ |
|
|
|
|
$versions = $this->get_versions(); |
|
|
|
|
|
|
|
|
|
// Seulement ce type |
|
|
|
|
if (array_key_exists($type, $versions)) { |
|
|
|
|
$versions = array_intersect_key($versions, array($type=>'yes')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($versions as $type => $numeros) { |
|
|
|
|
$output->writeln("<question>$type</question>"); |
|
|
|
|
|
|
|
|
|
foreach ($numeros as $numero => $url) { |
|
|
|
|
$output->writeln("$numero"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$versions = $this->listerVersions($type); |
|
|
|
|
foreach ($versions as $key => $value) { |
|
|
|
|
$output->writeln($value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Command::SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get_last_release($xy='') { |
|
|
|
|
$versions = $this->get_versions(); |
|
|
|
|
$tags = array_flip($versions['tags']); |
|
|
|
|
|
|
|
|
|
if ($xy) { |
|
|
|
|
$masque = "/^$xy\.\d+$/"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* listerVersions |
|
|
|
|
* |
|
|
|
|
* @param mixed $type |
|
|
|
|
* @return array $liste |
|
|
|
|
*/ |
|
|
|
|
public static function listerVersions(string $type = 'branches') { |
|
|
|
|
$liste = []; |
|
|
|
|
|
|
|
|
|
if ($type == 'tags') { |
|
|
|
|
ob_start(); |
|
|
|
|
passthru('git ls-remote --tags ' . self::_SPIP_GIT_REPO); |
|
|
|
|
$tags = ob_get_contents(); |
|
|
|
|
ob_end_clean(); |
|
|
|
|
|
|
|
|
|
$tags_pattern = '/v\d+.\d+.\d+[a-z0-9+-]*$/sm'; |
|
|
|
|
preg_match_all($tags_pattern, $tags, $liste); |
|
|
|
|
|
|
|
|
|
$liste = preg_replace('/v/', '', $liste[0]); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$masque = '/^\d+\.\d+\.\d+$/'; |
|
|
|
|
|
|
|
|
|
if ($type == 'branches') { |
|
|
|
|
ob_start(); |
|
|
|
|
passthru('git ls-remote --heads ' . self::_SPIP_GIT_REPO); |
|
|
|
|
$branches = ob_get_contents(); |
|
|
|
|
ob_end_clean(); |
|
|
|
|
|
|
|
|
|
$branches_pattern = '/refs\/heads\/[a-z0-9_.\/-]*/s'; |
|
|
|
|
preg_match_all($branches_pattern, $branches, $liste); |
|
|
|
|
|
|
|
|
|
$liste = preg_replace('/refs\/heads\//', '', $liste[0]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// On ne garde que les trucs stables |
|
|
|
|
$stables = array_filter( |
|
|
|
|
$tags, |
|
|
|
|
function ($cle) use ($masque) { |
|
|
|
|
return preg_match($masque, $cle); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// On ne renvoit que la dernière version |
|
|
|
|
natsort($stables); |
|
|
|
|
return array_pop($stables); |
|
|
|
|
|
|
|
|
|
return $liste; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get_last_branche($x='') { |
|
|
|
|
$versions = $this->get_versions(); |
|
|
|
|
$branches = array_flip($versions['branches']); |
|
|
|
|
|
|
|
|
|
if ($x) { |
|
|
|
|
$masque = "/^$x.\d+$/"; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$masque = '/^\d+\.\d+$/'; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* verifierVersionExiste |
|
|
|
|
* |
|
|
|
|
* @param string $version |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
public static function verifierVersionExiste(string $version) { |
|
|
|
|
$versions = array_merge_recursive(self::listerVersions('branches'), self::listerVersions('tags')); |
|
|
|
|
|
|
|
|
|
if (in_array($version, $versions)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// On ne garde que les trucs stables |
|
|
|
|
$stables = array_filter( |
|
|
|
|
$branches, |
|
|
|
|
function ($cle) use ($masque) { |
|
|
|
|
return preg_match($masque, $cle); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// On ne renvoit que la dernière version |
|
|
|
|
natsort($stables); |
|
|
|
|
return array_pop($stables); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get_versions() { |
|
|
|
|
if (!$this->versions) { |
|
|
|
|
$this->versions = $this->lister_versions(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* trouverVersionStable |
|
|
|
|
* |
|
|
|
|
* @param optional array $branches |
|
|
|
|
* @param optional array $tags |
|
|
|
|
* @return string dernier_tag_xy |
|
|
|
|
*/ |
|
|
|
|
public static function trouverVersionStable(?array $branches = [], ?array $tags = []) { |
|
|
|
|
if (empty($branches)) { |
|
|
|
|
$branches = self::listerVersions('branches'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $this->versions; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function lister_versions($type='') { |
|
|
|
|
$versions = array(); |
|
|
|
|
|
|
|
|
|
if ($type != 'tags') { |
|
|
|
|
// On cherche les branches |
|
|
|
|
ob_start(); |
|
|
|
|
passthru("svn list {$this->chemin_svn_racine}/branches"); |
|
|
|
|
$liste_branches = ob_get_contents(); |
|
|
|
|
ob_end_clean(); |
|
|
|
|
|
|
|
|
|
// On transforme en tableau et nettoie |
|
|
|
|
$versions['branches'] = $this->svn_to_array($liste_branches, 'branches'); |
|
|
|
|
$versions['branches']['trunk'] = 'svn://trac.rezo.net/spip/spip'; |
|
|
|
|
if (empty($tags)) { |
|
|
|
|
$tags = self::listerVersions('tags'); |
|
|
|
|
natsort($tags); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($type != 'tags') { |
|
|
|
|
// On cherche les tags |
|
|
|
|
ob_start(); |
|
|
|
|
passthru("svn list {$this->chemin_svn_racine}/tags"); |
|
|
|
|
$liste_tags = ob_get_contents(); |
|
|
|
|
ob_end_clean(); |
|
|
|
|
|
|
|
|
|
// On transforme en tableau et nettoie |
|
|
|
|
$versions['tags'] = $this->svn_to_array($liste_tags, 'tags'); |
|
|
|
|
|
|
|
|
|
$dernier_tag_xy = preg_replace('/(\d+).(\d+).\d+[a-z0-9+-]*$/', '${1}.${2}', end($tags)); |
|
|
|
|
|
|
|
|
|
if (array_search($dernier_tag_xy, $branches)) { |
|
|
|
|
return $dernier_tag_xy; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $versions; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function svn_to_array($svn, $type) { |
|
|
|
|
$liste = array(); |
|
|
|
|
$temp = explode(PHP_EOL, $svn); |
|
|
|
|
|
|
|
|
|
foreach ($temp as $dossier) { |
|
|
|
|
if ($cle = preg_replace('|(spip-)?(.*?)/?|i', '$2', $dossier)) { |
|
|
|
|
$liste[$cle] = "{$this->chemin_svn_racine}/$type/$dossier"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* trouverVersionPrecedente |
|
|
|
|
* |
|
|
|
|
* @param array $versions |
|
|
|
|
* @param string $version_installee |
|
|
|
|
* @return string $prev_version |
|
|
|
|
*/ |
|
|
|
|
public static function trouverVersionPrecedente(array $versions, string $version_installee) { |
|
|
|
|
|
|
|
|
|
if ($key = array_search($version_installee, $versions)) { |
|
|
|
|
if (preg_match('/^\d+.\d+/', $versions[$key]) && array_key_exists($key - 1, $versions)) { |
|
|
|
|
$key -= 1; |
|
|
|
|
$prev_version = $versions[$key]; |
|
|
|
|
|
|
|
|
|
preg_match('/\d+.\d+/', $version_installee, $version_xy); |
|
|
|
|
preg_match('/\d+.\d+/', $prev_version, $prev_version_xy); |
|
|
|
|
|
|
|
|
|
while ($version_xy[0] == $prev_version_xy[0]) { |
|
|
|
|
$prev_version = $versions[$key]; |
|
|
|
|
preg_match('/\d+.\d+/', $prev_version, $prev_version_xy); |
|
|
|
|
$key -= 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $prev_version; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* trouverVersionInstallee |
|
|
|
|
* |
|
|
|
|
* @return string $version |
|
|
|
|
*/ |
|
|
|
|
public static function trouverVersionInstallee() { |
|
|
|
|
global $spip_loaded; |
|
|
|
|
if ($spip_loaded) { |
|
|
|
|
if (lire_fichier('ecrire/inc_version.php', $inc)) { |
|
|
|
|
preg_match('/\$spip_version_branche = \'(\d+.\d+.\d+)\';/', $inc, $matches); |
|
|
|
|
|
|
|
|
|
return $matches[1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$liste = array_filter(array_unique($liste)); |
|
|
|
|
|
|
|
|
|
return $liste; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|