[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins-dist / svp / teleporter / svn.php
index 26952e1..89ee902 100644 (file)
@@ -1,17 +1,25 @@
 <?php
 /**
- * Gestion du téléporteur HTTP. 
+ * Gestion du téléporteur HTTP.
  *
  * @plugin SVP pour SPIP
  * @license GPL
  * @package SPIP\SVP\Teleporteur
  */
+
+
+if (!defined('_SVN_COMMAND')) {
+       define('_SVN_COMMAND', "svn");
+} // Securite : mettre le chemin absolu dans mes_options.php
+
 /**
  * Téléporter et déballer un composant SVN
- * 
+ *
  * Déployer un repository SVN depuis une source et une révision données
  *
+ * @uses  teleporter_svn_read()
+ * @uses  teleporter_nettoyer_vieille_version()
+ *
  * @param string $methode
  *     Méthode de téléportation : http|git|svn|...
  * @param string $source
  * @return bool
  *     True si l'opération réussie, false sinon.
  */
-function teleporter_svn_dist($methode,$source,$dest,$options=array()){
-       if (is_dir($dest)){
+function teleporter_svn_dist($methode, $source, $dest, $options = array()) {
+       if (is_dir($dest)) {
                $infos = teleporter_svn_read($dest);
-               if (!$infos){
-                       spip_log("Suppression de $dest qui n'est pas au format SVN","teleport");
+               if (!$infos) {
+                       spip_log("Suppression de $dest qui n'est pas au format SVN", "teleport");
                        $old = teleporter_nettoyer_vieille_version($dest);
-               }
-               elseif ($infos['source']!==$source) {
-                       spip_log("Suppression de $dest qui n'est pas sur le bon repository SVN","teleport");
+               } elseif ($infos['source'] !== $source) {
+                       spip_log("Suppression de $dest qui n'est pas sur le bon repository SVN", "teleport");
                        $old = teleporter_nettoyer_vieille_version($dest);
-               }
-               elseif (!isset($options['revision'])
-                 OR $options['revision']!=$infos['revision']){
-                       $command = "svn up ";
-                       if (isset($options['revision']))
-                               $command .= escapeshellarg("-r".$options['revision'])." ";
-                       if (isset($options['ignore-externals']))
+               } elseif (!isset($options['revision'])
+                       or $options['revision'] != $infos['revision']
+               ) {
+                       $command = _SVN_COMMAND . " up ";
+                       if (isset($options['revision'])) {
+                               $command .= escapeshellarg("-r" . $options['revision']) . " ";
+                       }
+                       if (isset($options['ignore-externals'])) {
                                $command .= "--ignore-externals ";
+                       }
 
                        $command .= escapeshellarg($dest);
-                       spip_log($command,"teleport");
+                       spip_log($command, "teleport");
                        exec($command);
-               }
-               else {
+               } else {
                        // Rien a faire !
-                       spip_log("$dest deja a jour (Revision ".$options['revision']." SVN de $source)","teleport");
+                       spip_log("$dest deja a jour (Revision " . $options['revision'] . " SVN de $source)", "teleport");
                }
        }
 
-       if (!is_dir($dest)){
-               $command = "svn co ";
-               if (isset($options['revision']))
-                       $command .= escapeshellarg("-r".$options['revision'])." ";
-               if (isset($options['ignore-externals']))
+       if (!is_dir($dest)) {
+               $command = _SVN_COMMAND . " co ";
+               if (isset($options['revision'])) {
+                       $command .= escapeshellarg("-r" . $options['revision']) . " ";
+               }
+               if (isset($options['ignore-externals'])) {
                        $command .= "--ignore-externals ";
-               $command .= escapeshellarg($source)." ".escapeshellarg($dest);
-               spip_log($command,"teleport");
+               }
+               $command .= escapeshellarg($source) . " " . escapeshellarg($dest);
+               spip_log($command, "teleport");
                exec($command);
        }
 
        // verifier que tout a bien marche
        $infos = teleporter_svn_read($dest);
-       if (!$infos) return false;
+       if (!$infos) {
+               return false;
+       }
 
        return true;
 }
@@ -75,7 +87,7 @@ function teleporter_svn_dist($methode,$source,$dest,$options=array()){
 /**
  * Lire source et révision d'un répertoire SVN
  * et reconstruire la ligne de commande
- * 
+ *
  * @param string $dest
  *     Chemin du répertoire SVN
  * @param array $options
@@ -87,26 +99,29 @@ function teleporter_svn_dist($methode,$source,$dest,$options=array()){
  *     - revision : numéro de la révision SVN
  *     - dest : Chemin du répertoire
  */
-function teleporter_svn_read($dest,$options=array()){
+function teleporter_svn_read($dest, $options = array()) {
 
-       if (!is_dir("$dest/.svn"))
+       if (!is_dir("$dest/.svn")) {
                return "";
+       }
 
        // on veut lire ce qui est actuellement deploye
        // et reconstituer la ligne de commande pour le deployer
-       exec("svn info ".escapeshellarg($dest),$output);
-       $output = implode("\n",$output);
+       exec(_SVN_COMMAND . " info " . escapeshellarg($dest), $output);
+       $output = implode("\n", $output);
 
        // URL
        // URL: svn://trac.rezo.net/spip/spip
-       if (!preg_match(",^URL[^:\w]*:\s+(.*)$,Uims",$output,$m))
+       if (!preg_match(",^URL[^:\w]*:\s+(.*)$,Uims", $output, $m)) {
                return "";
+       }
        $source = $m[1];
 
        // Revision
        // Revision: 18763
-       if (!preg_match(",^R..?vision[^:\w]*:\s+(\d+)$,Uims",$output,$m))
+       if (!preg_match(",^R..?vision[^:\w]*:\s+(\d+)$,Uims", $output, $m)) {
                return "";
+       }
 
        $revision = $m[1];
 
@@ -116,3 +131,19 @@ function teleporter_svn_read($dest,$options=array()){
                'dest' => $dest
        );
 }
+
+
+/**
+ * Tester si la commande 'svn' est disponible
+ *
+ * @return bool
+ *     true si on peut utiliser la commande svn
+ **/
+function teleporter_svn_tester() {
+       static $erreurs = null;
+       if (is_null($erreurs)) {
+               exec(_SVN_COMMAND . " --version", $output, $erreurs);
+       }
+
+       return !$erreurs;
+}