diff --git a/controllers/TagsController.php b/controllers/TagsController.php index dad6a482..46d31d6e 100644 --- a/controllers/TagsController.php +++ b/controllers/TagsController.php @@ -28,7 +28,7 @@ class TagsController extends ApiController { public function tags() { - $this->allowMethods(['HEAD', 'GET', 'DELETE']); + $this->allowMethods(['HEAD', 'GET', 'DELETE', 'POST']); if (!$this->permissions->canAccess($this->objectLibraryID)) { $this->e403(); @@ -66,7 +66,7 @@ public function tags() { } // All tags else { - $this->allowMethods(array('GET', 'DELETE')); + $this->allowMethods(array('GET', 'DELETE', 'POST')); if ($this->scopeObject) { $this->allowMethods(array('GET')); @@ -197,6 +197,28 @@ public function tags() { Zotero_DB::commit(); $this->e204(); } + else if ($this->method == 'POST') { + if (empty($this->queryParams['tag']) || empty($this->queryParams['tagName']) ) { + $this->e400("tag and tagName are required query parameters."); + } + + $oldTagName = $this->queryParams['tag']; + $newTagName = $this->queryParams['tagName']; + + $tagID = Zotero_Tags::getIDs($this->objectLibraryID, $oldTagName); + $tagCount = count($tagID); + + // Make sure only one tag has been fetched + if ($tagCount != 1) { + $this->e400("Only one tag should be found to be renamed. Found: $tagCount"); + } + + $tag = Zotero_Tags::get($this->objectLibraryID, $tagID[0], true); + $tag->name = $newTagName; + $tag -> save(); + + $this->e204(); + } else { $title = "Tags"; $results = Zotero_Tags::search($this->objectLibraryID, $this->queryParams); diff --git a/model/API.inc.php b/model/API.inc.php index 863104a3..44371d8c 100644 --- a/model/API.inc.php +++ b/model/API.inc.php @@ -88,6 +88,7 @@ class Zotero_API { 'collectionKey' => [], 'searchKey' => [], 'tag' => '', + 'tagName' => '', 'tagType' => '', 'since' => false, 'sincetime' => false,