--- /dev/null
+<?php
+
+class UpgradeCommand extends Command {
+
+ public function getDescription(){
+ return "Vérifie qu'un patch est disponible et l'execute";
+ }
+
+ public function go(){
+ $this->verifInit();
+ $uuid = $this->getAlloUUID();
+ $info = $this->getAlloServeur()->applianceInfo($uuid);
+
+ $fqdn = $info['internal_fqdn']['value'];
+ $content = $this->getInfoFromInstance($fqdn);
+
+ if ( ($content['version'] != $info['version']['value'])
+ || ($content['produit'] != $info['produit_name']['value'])
+ ){
+ throw new Exception("Les informations locales ne correspondent pas : veuillez mettre à jour Allo (allo update)");
+ }
+
+ $result = $this->getAlloServeur()->patchExists($uuid);
+ if (! $result){
+ echo "Aucun patch n'est disponible\n";
+ return;
+ }
+ echo "Le patch suivant est disponible : {$result['name']} {$result['value']} ({$result['channel_name']})\n";
+
+ $reponse = $this->readline("Voulez-vous executer ce patch ? (oui/NON)");
+
+ if (strtolower($reponse) != 'oui'){
+ echo "Le patch n'a pas été installé\n";
+ return;
+ }
+
+ echo "Installation du patch...\n";
+ $file = str_replace("\r", "", $result['script_content']);
+ file_put_contents("/tmp/allo_patch.sh",$file);
+
+ exec("/bin/bash /tmp/allo_patch.sh",$output,$return);
+ echo "Le patch a été executé : \n";
+ echo implode("\n",$output);
+ echo "\n";
+ if ($return != 0){
+ throw new Exception("Le patch a échoué (code $return) ...");
+ }
+
+ echo "Le patch a réussi. Mise à jour des informations sur le serveur\n";
+ $updateComand = new UpdateCommand($this->allo_serveur_url);
+ $updateComand->go();
+ }
+
+}
\ No newline at end of file