Index: trunk/tools/bugzilla/client/bugzilla.php |
— | — | @@ -121,6 +121,62 @@ |
122 | 122 | } |
123 | 123 | return $this->dependency; |
124 | 124 | } |
| 125 | + |
| 126 | + public function undoLastChangeIfBy( $email ) { |
| 127 | + $hist = $this->getHistory(); |
| 128 | + $change = array_pop( $hist['bugs'][0]['history'] ); |
| 129 | + $reverse = array(); |
| 130 | + |
| 131 | + if( $change['who'] == $email ) { |
| 132 | + echo "{$this->id}: Undoing last change by $email made at {$change['when']}:\n"; |
| 133 | + foreach($change['changes'] as $c) { |
| 134 | + $reverse = array_merge( $reverse, $this->addResetField( $c ) ); |
| 135 | + } |
| 136 | + return $this->bz->update( $this->id, $reverse ); |
| 137 | + } else { |
| 138 | + return false; |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + public function addResetField( $changeLog ) { |
| 143 | + if( $this->bz->isListField( $changeLog['field_name'] ) ) { |
| 144 | + return array( $changeLog['field_name'] => |
| 145 | + array( "add" => (array)$changeLog['removed'], "remove" => (array)$changeLog['added'] ) ); |
| 146 | + } else { |
| 147 | + return array( $changeLog['field_name'] => $changeLog['removed'] ); |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + public function resetField( $change ) { |
| 152 | + if( !isset( $change['field_name'] ) ) |
| 153 | + throw new Exception( "no field_name given!" ); |
| 154 | + if( !isset( $change['removed'] ) ) |
| 155 | + throw new Exception( "no removed value given!" ); |
| 156 | + if( !isset( $change['added'] ) ) |
| 157 | + throw new Exception( "no added value given!" ); |
| 158 | + |
| 159 | + if( $change['removed'] == "" ) { |
| 160 | + return $this->removeFromFieldList( $change['field_name'], $change['added'] ); |
| 161 | + } |
| 162 | + |
| 163 | + if( $change['added'] == "" ) { |
| 164 | + return $this->addToFieldList( $change['field_name'], $change['removed'] ); |
| 165 | + } |
| 166 | + |
| 167 | + return $this->setFieldValue( $change['field_name'], $change['removed'] ); |
| 168 | + } |
| 169 | + |
| 170 | + public function addToFieldList( $field, $value ) { |
| 171 | + return $this->bz->addToFieldList( $this->id, $field, $value ); |
| 172 | + } |
| 173 | + |
| 174 | + public function removeFromFieldList( $field, $value ) { |
| 175 | + return $this->bz->removeFromFieldList( $this->id, $field, $value ); |
| 176 | + } |
| 177 | + |
| 178 | + public function setFieldValue( $field, $value ) { |
| 179 | + return $this->bz->update( $this->id, array( $field => $value ) ); |
| 180 | + } |
125 | 181 | } |
126 | 182 | |
127 | 183 | class BugzillaSearchIterator implements Iterator { |
— | — | @@ -180,6 +236,7 @@ |
181 | 237 | |
182 | 238 | class BugzillaWebClient { |
183 | 239 | private $bz = null; |
| 240 | + private $lists = array( "blocks", "depends_on", "cc", "groups", "keywords", "see_also" ); |
184 | 241 | |
185 | 242 | public function __construct( $url, $user = null, $password = null, $debug = false ) { |
186 | 243 | $this->bz = new jsonRPCClient( $url, $debug ); |
— | — | @@ -188,6 +245,10 @@ |
189 | 246 | } |
190 | 247 | } |
191 | 248 | |
| 249 | + public function isListField( $field ) { |
| 250 | + return in_array( $field, $this->lists ); |
| 251 | + } |
| 252 | + |
192 | 253 | public function getById( $id ) { |
193 | 254 | return new BugzillaBug( $id, $this ); |
194 | 255 | } |
— | — | @@ -197,6 +258,10 @@ |
198 | 259 | return $this->bz->__call( "Bug.fields", array( "" => "" ) ); |
199 | 260 | } |
200 | 261 | |
| 262 | + public function getState( $id ) { |
| 263 | + $this->bz->__call( "Bug.get", array( "id" => (array)$id ) ); |
| 264 | + } |
| 265 | + |
201 | 266 | public function search( $conditions ) { |
202 | 267 | if(is_array($conditions)) { |
203 | 268 | return $this->bz->__call( "Bug.search", $conditions ); |
— | — | @@ -223,4 +288,25 @@ |
224 | 289 | if(!is_array($resolution)) $resolution = array($resolution); |
225 | 290 | return $this->search(array("resolution" => $resolution, "limit" => 10)); |
226 | 291 | } |
| 292 | + |
| 293 | + public function addToFieldList( $ids, $field, $value ) { |
| 294 | + if( !in_array( $field, $this->lists ) ) { |
| 295 | + throw new Exception( "This field ($field) isn't a list!" ); |
| 296 | + } else { |
| 297 | + return $this->update( $ids, array( $field => array( "add" => (array)$value ) ) ); |
| 298 | + } |
| 299 | + } |
| 300 | + |
| 301 | + public function removeFromFieldList( $ids, $field, $value ) { |
| 302 | + if( !in_array( $field, $this->lists ) ) { |
| 303 | + throw new Exception( "This field ($field) isn't a list!" ); |
| 304 | + } else { |
| 305 | + return $this->update( $ids, array( $field => array( "remove" => (array)$value ) ) ); |
| 306 | + } |
| 307 | + } |
| 308 | + |
| 309 | + public function update( $ids, $fields ) { |
| 310 | + $fields['ids'] = (array)$ids; |
| 311 | + return $this->bz->__call( "Bug.update", $fields ); |
| 312 | + } |
227 | 313 | } |