Skip to content

Commit

Permalink
post method to update a tag's name
Browse files Browse the repository at this point in the history
Takes 2 query parameters:
tag (old name) and tagName (which becomes the new name.)
Fixes: zotero#108
  • Loading branch information
abaevbog committed Jun 19, 2023
1 parent eb0a76e commit 751662e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions controllers/TagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions model/API.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Zotero_API {
'collectionKey' => [],
'searchKey' => [],
'tag' => '',
'tagName' => '',
'tagType' => '',
'since' => false,
'sincetime' => false,
Expand Down

0 comments on commit 751662e

Please sign in to comment.