4 * repositoryapiPlugin Class
6 * Copyright 2016-2017, Roland Mas
7 * https://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 class repositoryapiPlugin extends Plugin {
26 public function __construct($id=0) {
27 parent::__construct($id) ;
28 $this->name = "repositoryapi";
29 $this->text = "Repository API"; // To show in the tabs, use...
30 $this->_addHook('register_soap');
33 public function register_soap(&$params) {
34 $server = &$params['server'];
35 $uri = util_make_url();
37 $server->wsdl->addComplexType(
38 'RepositoryAPIRepositoryInfo',
44 'group_id' => array('name'=>'group_id', 'type' => 'xsd:int'),
45 'repository_id' => array('name'=>'repository_id', 'type' => 'xsd:string'),
46 'repository_urls' => array('name'=>'repository_urls', 'type' => 'tns:ArrayOfstring'),
47 'repository_type' => array('name'=>'repository_type', 'type' => 'xsd:string'),
51 $server->wsdl->addComplexType(
52 'ArrayOfRepositoryAPIRepositoryInfo',
58 array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:RepositoryAPIRepositoryInfo[]')),
59 'tns:RepositoryAPIRepositoryInfo');
62 'repositoryapi_repositoryList',
63 array('session_ser'=>'xsd:string',
67 array('return'=>'tns:ArrayOfRepositoryAPIRepositoryInfo'),
69 $uri.'#repositoryapi_repositoryList','rpc','encoded'
73 'repositoryapi_repositoryInfo',
74 array('session_ser'=>'xsd:string',
75 'repository_id'=>'xsd:string'),
76 array('return'=>'tns:RepositoryAPIRepositoryInfo'),
78 $uri.'#repositoryapi_repositoryInfo','rpc','encoded'
81 $server->wsdl->addComplexType(
82 'RepositoryAPIActivity',
88 'group_id' => array('name'=>'group_id', 'type' => 'xsd:int'),
89 'repository_id' => array('name'=>'repository_id', 'type' => 'xsd:string'),
90 'timestamp' => array('name'=>'timestamp', 'type' => 'xsd:int'),
91 'type' => array('name'=>'type', 'type' => 'xsd:string'),
95 $server->wsdl->addComplexType(
96 'ArrayOfRepositoryAPIActivity',
102 array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:RepositoryAPIActivity[]')),
103 'tns:RepositoryAPIActivity'
106 $server->wsdl->addComplexType(
107 'RepositoryAPIActivityReturn',
113 'effective_t0'=>'xsd:int',
114 'effective_t1'=>'xsd:int',
115 'activities' => array('name'=>'activities', 'type' => 'tns:ArrayOfRepositoryAPIActivity'),
120 'repositoryapi_repositoryActivity',
121 array('session_ser'=>'xsd:string',
127 array('return'=>'tns:RepositoryAPIActivityReturn'),
129 $uri.'#repositoryapi_repositoryActivity','rpc','encoded'
134 function &repositoryapi_repositoryList($session_ser, $limit=0, $offset=0) {
135 continue_session($session_ser);
138 if ($limit > $maxnum || $limit <= 0) {
144 $params['results'] = &$results;
145 plugin_hook('get_scm_repo_list',$params);
148 foreach ($results as $res) {
149 if (forge_check_perm('scm',$res['group_id'],'read')) {
157 foreach ($res as $r) {
158 if (count($res2) >= $limit) {
161 if ($skipped >= $offset) {
164 $skipped = $skipped + 1;
172 function &repositoryapi_repositoryInfo($session_ser, $repository_id) {
173 continue_session($session_ser);
177 $params['repository_id'] = $repository_id;
178 $params['results'] = &$results;
179 plugin_hook('get_scm_repo_info',$params);
181 if ($params['results'] == NULL) {
182 $sf = new soap_fault('','repositoryapi_repositoryInfo',_('Error when fetching repository info'),_('Error when fetching repository info'));
186 return $params['results'];
189 function &repositoryapi_repositoryActivity($session_ser, $t0, $t1, $limit=0, $offset=0) {
190 continue_session($session_ser);
198 if ($t1 - $t0 > $maxspan) {
199 $t0 = $t1 - $maxspan;
202 if ($limit > $maxnum || $limit <= 0) {
207 // "type" is "change" only so far, but extensible for the future
208 $res = db_query_params("SELECT tstamp, repository_id, group_id, 'change' AS type FROM scm_activities WHERE tstamp BETWEEN $1 AND $2 ORDER BY tstamp, group_id, repository_id",
213 while ((count($results) < $limit) && ($arr = db_fetch_array($res))) {
214 if (!forge_check_perm('scm',$arr['group_id'],'read')) {
218 if ($skipped >= $offset) {
219 $results[] = array('timestamp' => $arr['tstamp'],
220 'repository_id' => $arr['repository_id'],
221 'group_id' => $arr['group_id'],
222 'type' => $arr['type']);
224 $skipped = $skipped + 1;
229 'effective_t0' => $t0,
230 'effective_t1' => $t1,
231 'activities' => $results,
239 // c-file-style: "bsd"