Skip to content
Extraits de code Groupes Projets
Valider 43d520b3 rédigé par cerdic's avatar cerdic
Parcourir les fichiers

Mettre a jour la facon dont on liste les repos modifies telle que generee par le debardeur

parent e355c069
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -53,10 +53,10 @@ class SalvatoreRecharger extends Command { ...@@ -53,10 +53,10 @@ class SalvatoreRecharger extends Command {
null null
) )
->addOption( ->addOption(
'changelog', 'changedir',
null, null,
InputOption::VALUE_REQUIRED, InputOption::VALUE_REQUIRED,
'Chemin vers le fichier JSON changelog des dernières modifications sur la zone', 'Chemin vers le repertoires qui contient les traces JSON posees par le debardeur',
null null
) )
->addOption( ->addOption(
...@@ -113,14 +113,16 @@ class SalvatoreRecharger extends Command { ...@@ -113,14 +113,16 @@ class SalvatoreRecharger extends Command {
salvatore_log("<info>$n modules à traiter : " . $modules . "</info>"); salvatore_log("<info>$n modules à traiter : " . $modules . "</info>");
} }
$changelogFile = $input->getOption('changelog'); // https://git.spip.net/spip-contrib-extensions/debardeur/src/branch/master/action/api_debardeur_hook.php#L224
if (!$changelogFile or !file_exists($changelogFile)) { $changedir = $input->getOption('changedir');
salvatore_log("<error>Indiquez un fichier valide comme changelog</error>"); if (empty($changedir) or !is_dir($changedir)) {
salvatore_log("<error>Indiquez un repertoire valide pour changedir</error>");
return self::FAILURE; return self::FAILURE;
} }
$changelog = file_get_contents($changelogFile);
if (!$changelog or !$changelog = json_decode($changelog, true)) { $changed = $this->lister_depots_modifies($changedir);
salvatore_log("<info>Rien a faire, changelog vide</info>"); if (empty($changed)) {
salvatore_log("<info>Rien a faire, changedir vide</info>");
return self::SUCCESS; return self::SUCCESS;
} }
...@@ -134,7 +136,7 @@ class SalvatoreRecharger extends Command { ...@@ -134,7 +136,7 @@ class SalvatoreRecharger extends Command {
return self::FAILURE; return self::FAILURE;
} }
$changed_trad = $this->filter_changed_traductions($liste_trad, $changelog, $t_since); $changed_trad = $this->filter_changed_traductions($liste_trad, $changed, $t_since);
if ($changed_trad) { if ($changed_trad) {
$n = count($changed_trad); $n = count($changed_trad);
$changed_modules = array_column($changed_trad, 'module'); $changed_modules = array_column($changed_trad, 'module');
...@@ -156,48 +158,46 @@ class SalvatoreRecharger extends Command { ...@@ -156,48 +158,46 @@ class SalvatoreRecharger extends Command {
} }
protected function filter_changed_traductions($liste_trad, $changelog, $t_since) { protected function lister_depots_modifies($changedir) {
$changed_trad = array(); $changed = [];
$changed = array(); $files = glob(rtrim($changedir,'/')."/*.json");
foreach($changelog as $file => $lastmodified) { foreach ($files as $file) {
if ($lastmodified > $t_since if ($json = file_get_contents($file)
and strpos($file, "/lang") !== false and $json = json_decode($json, true)) {
) { if (empty($json['time'])) {
$changed[] = $file; $json['time'] = filemtime($file);
}
$changed[] = $json;
} }
@unlink($file);
} }
$changed = array_unique($changed);
salvatore_log(count($changed) . " fichiers changés"); return $changed;
}
protected function filter_changed_traductions($liste_trad, $changed, $t_since) {
$changed_trad = array();
salvatore_log(count($changed) . " depots changés");
foreach($changed as $c) { foreach($changed as $c) {
$depots_possibles = [ /*
"svn://zone.spip.org/spip-zone/" . rtrim($c, '/'), [
'methode' => 'git',
'url' => $url,
'branche' => $branch,
'short' => $data['repository']['name'],
'time' => time(),
]; ];
if (strpos($c, "spip-zone/_core_/plugins/") === 0) { */
$r = explode('/', $c);
array_shift($r);
array_shift($r);
array_shift($r);
$r = array_shift($r);
$depots_possibles[] = "https://git.spip.net/spip/$r.git";
}
if (strpos($c, "spip-zone/_plugins_/") === 0) {
$r = explode('/', $c);
array_shift($r);
array_shift($r);
$r = array_shift($r);
$depots_possibles[] = "https://git.spip.net/spip-contrib-extensions/$r.git";
}
if (strpos($c, "spip-zone/_squelette_/") === 0) {
$r = explode('/', $c);
array_shift($r);
array_shift($r);
$r = array_shift($r);
$depots_possibles[] = "https://git.spip.net/spip-contrib-squelettes/$r.git";
}
foreach ($liste_trad as $k=>$source) { foreach ($liste_trad as $k=>$source) {
if (in_array(rtrim($source['url'], '/'), $depots_possibles)) { if ($source['url'] === $c['url']
and $source['branche'] === $c['branche']
) {
$changed_trad[$k] = $source; $changed_trad[$k] = $source;
unset($liste_trad[$k]); unset($liste_trad[$k]);
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter