|
28 | 28 |
|
29 | 29 | class TagsController extends ApiController {
|
30 | 30 | public function tags() {
|
31 |
| - $this->allowMethods(['HEAD', 'GET', 'DELETE']); |
| 31 | + $this->allowMethods(['HEAD', 'GET', 'DELETE', 'POST']); |
32 | 32 |
|
33 | 33 | if (!$this->permissions->canAccess($this->objectLibraryID)) {
|
34 | 34 | $this->e403();
|
@@ -66,7 +66,7 @@ public function tags() {
|
66 | 66 | }
|
67 | 67 | // All tags
|
68 | 68 | else {
|
69 |
| - $this->allowMethods(array('GET', 'DELETE')); |
| 69 | + $this->allowMethods(array('GET', 'DELETE', 'POST')); |
70 | 70 |
|
71 | 71 | if ($this->scopeObject) {
|
72 | 72 | $this->allowMethods(array('GET'));
|
@@ -197,6 +197,28 @@ public function tags() {
|
197 | 197 | Zotero_DB::commit();
|
198 | 198 | $this->e204();
|
199 | 199 | }
|
| 200 | + else if ($this->method == 'POST') { |
| 201 | + if (empty($this->queryParams['tag']) || empty($this->queryParams['tagName']) ) { |
| 202 | + $this->e400("tag and tagName are required query parameters."); |
| 203 | + } |
| 204 | + |
| 205 | + $oldTagName = $this->queryParams['tag']; |
| 206 | + $newTagName = $this->queryParams['tagName']; |
| 207 | + |
| 208 | + $tagID = Zotero_Tags::getIDs($this->objectLibraryID, $oldTagName); |
| 209 | + $tagCount = count($tagID); |
| 210 | + |
| 211 | + // Make sure only one tag has been fetched |
| 212 | + if ($tagCount != 1) { |
| 213 | + $this->e400("Only one tag should be found to be renamed. Found: $tagCount"); |
| 214 | + } |
| 215 | + |
| 216 | + $tag = Zotero_Tags::get($this->objectLibraryID, $tagID[0], true); |
| 217 | + $tag->name = $newTagName; |
| 218 | + $tag -> save(); |
| 219 | + |
| 220 | + $this->e204(); |
| 221 | + } |
200 | 222 | else {
|
201 | 223 | $title = "Tags";
|
202 | 224 | $results = Zotero_Tags::search($this->objectLibraryID, $this->queryParams);
|
|
0 commit comments