Skip to content

Commit a886d4d

Browse files
committed
post method to update tag's name
/users/ID/tags?tag=CURRENT_NAME&tagName=NEW_NAME Fixes: zotero#108
1 parent 2cf66c3 commit a886d4d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

controllers/TagsController.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class TagsController extends ApiController {
3030
public function tags() {
31-
$this->allowMethods(['HEAD', 'GET', 'DELETE']);
31+
$this->allowMethods(['HEAD', 'GET', 'DELETE', 'POST']);
3232

3333
if (!$this->permissions->canAccess($this->objectLibraryID)) {
3434
$this->e403();
@@ -66,7 +66,7 @@ public function tags() {
6666
}
6767
// All tags
6868
else {
69-
$this->allowMethods(array('GET', 'DELETE'));
69+
$this->allowMethods(array('GET', 'DELETE', 'POST'));
7070

7171
if ($this->scopeObject) {
7272
$this->allowMethods(array('GET'));
@@ -197,6 +197,28 @@ public function tags() {
197197
Zotero_DB::commit();
198198
$this->e204();
199199
}
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+
}
200222
else {
201223
$title = "Tags";
202224
$results = Zotero_Tags::search($this->objectLibraryID, $this->queryParams);

model/API.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class Zotero_API {
8888
'collectionKey' => [],
8989
'searchKey' => [],
9090
'tag' => '',
91+
'tagName' => '',
9192
'tagType' => '',
9293
'since' => false,
9394
'sincetime' => false,

0 commit comments

Comments
 (0)