source: trunk/spip/esqueleto-redcta/plugins/svn_update/inc/svn_update.php @ 30

Last change on this file since 30 was 30, checked in by sebas, 17 years ago

nueva importacion del codigo del esqueleto de redcta con los plugins

File size: 1.5 KB
Line 
1<?php
2
3        define('_SVN_COMMAND', 'svn');
4
5        // la fonction qui fait le travail
6        function update_svn($l) {
7                $l = trim($l);
8
9                if (!$l OR substr($l,0,1) == '#') return NULL; // commentaires
10
11                @list($src, $dest, $rev, $user) = explode(' ',$l);
12
13                if (!preg_match(',^(https?|svn)://,', $src))
14                        return $src; // erreur
15
16                if (!is_dir($dest))
17                        mkdir($dest, 0777, 'recursive');
18
19                if (!is_dir($dest)
20                OR !is_writable($dest))
21                        return "Impossible d'ecrire dans ".$dest; // erreur
22
23                // Checkout ?
24                if (!file_exists($entries = "$dest/.svn/entries")) {
25                        $command = "checkout $src/ $dest/";
26                }
27
28                else {
29                        $entries = join("\n", file($entries));
30                        if (!preg_match(',\surl="([^"]+)",', $entries, $r))
31                                return "fichier .svn/entries non conforme ou illisible";
32                        $old_src = $r[1];
33
34                        // Switch ?
35                        if ($old_src != $src) {
36                                $command = "switch --relocate $old_src/ $src/ $dest/";
37                        }
38                       
39                        // Update
40                        else {
41                                if ($rev)
42                                        $command = "update --revision $rev $dest/";
43                                else
44                                        $command = "update $dest/";
45                        }
46                }
47
48                if ($command) {
49                        $command = _SVN_COMMAND." $user ".$command;
50                        $out = array();
51                        exec($command,$out);
52                        array_unshift($out, $command);
53                        return $out;
54                }
55
56        }
57
58        function traiter_config_svn($config = array()) {
59                foreach($config as $l) {
60                        echo "<hr /><b>", htmlspecialchars($l), "</b>";
61                        $res = update_svn($l);
62                        if (is_string($res))
63                                echo "<br /><b>Erreur: ",
64                                        htmlspecialchars($res),
65                                        "</b>";
66                        if (is_array($res))
67                                echo "<br />".nl2br(htmlspecialchars(join("\n", $res)));
68                        echo "<br />\n";
69                }
70        }
71
72?>
Note: See TracBrowser for help on using the repository browser.