1: <?php
2: /**
3: * Class for interfacing with the tickets API.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Release
9: * @author Michael J. Rubinsky <mrubinsk@horde.org>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://www.horde.org/libraries/Horde_Release
12: */
13:
14: /**
15: * Glue class for a modular CLI.
16: *
17: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Horde
23: * @package Release
24: * @author Michael J. Rubinsky <mrubinsk@horde.org>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://www.horde.org/libraries/Horde_Release
27: */
28: class Horde_Release_Whups
29: {
30: /**
31: * Local copy of config params.
32: *
33: * @var array
34: */
35: protected $_params;
36:
37: /**
38: * Http client
39: *
40: * @var Horde_Http_Client
41: */
42: protected $_http;
43:
44: /**
45: * Constructor.
46: *
47: * @param array $params TODO
48: */
49: public function __construct($params)
50: {
51: if (isset($params['client'])) {
52: $this->_http = $params['client'];
53: unset($params['client']);
54: } else {
55: $this->_http = new Horde_Http_Client(
56: array('request.username' => $params['user'],
57: 'request.password' => $params['pass']));
58: }
59: $this->_params = $params;
60: }
61:
62: /**
63: * Add a new version to the current modules queue.
64: *
65: * @param string $module The name of the module.
66: * @param string $version The version string.
67: * @param string $desc Descriptive text for this version.
68: *
69: * @throws Horde_Exception
70: */
71: public function addNewVersion($module, $version, $desc = '')
72: {
73: $id = $this->getQueueId($module);
74: if ($id === false) {
75: throw new Horde_Exception('Unable to locate requested queue');
76: }
77:
78: $method = 'tickets.addVersion';
79: $params = array($id, $version, $desc);
80: try {
81: Horde_Rpc::request('jsonrpc', $this->_params['url'], $method, $this->_http, $params);
82: } catch (Horde_Http_Client_Exception $e) {
83: throw new Horde_Exception_Wrapped($e);
84: }
85: }
86:
87: /**
88: * Look up the queue id for the requested module name.
89: *
90: * @param string $module TODO
91: *
92: * @return boolean TODO
93: */
94: public function getQueueId($module)
95: {
96: $queues = $this->_listQueues();
97:
98: foreach ($queues as $id => $queue) {
99: if ($queue == $module) {
100: return $id;
101: }
102: }
103:
104: return false;
105: }
106:
107: /**
108: * Perform a listQueue api call.
109: *
110: * @return string TODO
111: * @throws Horde_Exception
112: */
113: protected function _listQueues()
114: {
115: return Horde_Rpc::request('jsonrpc',
116: $this->_params['url'],
117: 'tickets.listSlugs',
118: $this->_http,
119: null)->result;
120: }
121:
122: }
123: