php8
[web.mtrack] / MTrack / Repo.php
1 <?php
2 require_once 'MTrack/SCM.php';
3 require_once 'MTrack/DB.php';
4 require_once 'MTrack/Config.php';
5 require_once 'MTrack/Project.php';
6 require_once 'MTrack/SCMFileEvent.php';
7  //require_once 'MTrack/Changeset.php';
8 //require_once 'MTrack/Wiki.php';
9
10
11 class MTrack_Repo extends MTrackSCM 
12 {
13     public $id = null;
14     public $shortname = null;
15     public $scmtype = null;
16     public $repopath = null;
17     public $browserurl = null;
18     public $browsertype = null;
19     public $description = null;
20     public $parent = '';
21     public $clonedfrom = null;
22     public $serverurl = null;
23     
24     
25     private $links_to_add = array();
26     private $links_to_remove = array();
27     private $links = null;
28     static $scms = array();
29     /**
30      *load class and create instance using array as properties
31      */
32     
33     static function factory($ar)
34     {
35         //print_r($ar);
36         $type = ucfirst($ar['scmtype']);
37         $fn = 'MTrack/SCM/'.$type .'/Repo.php';
38         $cls = 'MTrack_SCM_'.$type .'_Repo';
39         require_once $fn;
40         
41         $ret = new $cls($ar);
42         
43         return $ret;
44         
45     }
46     
47  
48     static function getAvailableSCMs()
49     {
50         $ret = array();
51         $ar = scandir(dirname(__FILE__).'/SCM');
52         
53         foreach($ar as $a) {
54             if (empty($a) || $a[0] == '.') {
55                 continue;
56             }
57             $fn = dirname(__FILE__).'/SCM/'.$a.'/Repo.php';
58             if (!file_exists($fn)) {
59                 continue;
60             } 
61             $ret[$a] = MTrack_Repo::factory(array('scmtype'=> $a));
62             
63         }
64         return $ret;
65     }  
66      
67     function __construct($ar = null) {
68         
69         if (!is_array($ar)) {
70             return; // can accept empty ctrs
71         }
72         foreach($ar as $k=>$v) {
73             $this->$k = $v;
74         }
75         
76     }
77     
78     function reconcileRepoSettings(MTrackSCM $r)
79     {
80         $c = self::Factory(array('scmtype'=>$this->scmtype));
81         $s->reconcileRepoSettings($this);
82     }
83     
84     function getServerURL()
85     {
86         if ($this->serverurl) {
87             return $this->serverurl;
88         }
89         /*
90         $url = MTrackConfig::get('repos', "$this->scmtype.serverurl");
91         if ($url) {
92           return $url . $this->getBrowseRootName();
93         }
94         */
95         return null;
96     }
97
98     function getCheckoutCommand() {
99         $url = $this->getServerURL();
100         if (strlen($url)) {
101           return $this->scmtype . ' clone ' . $this->getServerURL();
102         }
103         return null;
104     }
105
106     function canFork() {
107         return false;
108     }
109
110     function getWorkingCopy() {
111          throw new Exception("cannot getWorkingCopy from a generic repo object");
112     }
113     /*
114     function deleteRepo(MTrackChangeset $CS) {
115         MTrackDB::q('delete from repos where repoid = ?', $this->repoid);
116         mtrack_rmdir($this->repopath);
117     }
118     */
119  
120 /**
121  * i could not find where this is used..
122     function getLinks()
123   {
124     if ($this->links === null) {
125       $this->links = array();
126       foreach (MTrackDB::q('select linkid, projid, repopathregex
127           from project_repo_link where repoid = ? order by repopathregex',
128           $this->repoid)->fetchAll() as $row) {
129         $this->links[$row[0]] = array($row[1], $row[2]);
130       }
131     }
132     return $this->links;
133   }
134
135     function addLink($proj, $regex)
136   {
137     if ($proj instanceof MTrackProject) {
138       $this->links_to_add[] = array($proj->projid, $regex);
139     } else {
140       $this->links_to_add[] = array($proj, $regex);
141     }
142   }
143
144     function removeLink($linkid)
145   {
146     $this->links_to_remove[$linkid] = $linkid;
147   }
148  */
149
150 // these are needed just to implement the abstract interface..
151     function getBranches() {}
152     function getTags() {}
153     function readdir($path, $object = null, $ident = null) {}
154     function file($path, $object = null, $ident = null) {}
155     function history($path, $limit = null, $object = null, $ident = null){}
156     function diff($path, $from = null, $to = null) {}
157     function getRelatedChanges($revision) {}
158     function getSCMMetaData() { return null; }
159     /**
160      *  converts a commit log message (cached locally into a working object..)
161      *  see Browse.php
162      */
163     function commitLogToEvent($str) {
164         throw new Exception("no implementation for commitLogToEvent");
165     }
166 }