diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2013-05-20 10:16:07 +0200 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2013-05-20 10:16:07 +0200 |
commit | b1bb899867b787f024c94ae26907b857e203d59c (patch) | |
tree | 4335797b38053f80be2a7e75c81a1b63a3ae2580 /lib/vcategories.php | |
parent | 6609de28d832262e8f72fb19e5f0343cd021cca3 (diff) | |
download | nextcloud-server-b1bb899867b787f024c94ae26907b857e203d59c.tar.gz nextcloud-server-b1bb899867b787f024c94ae26907b857e203d59c.zip |
Add rename() method to OC_VCategories.
Diffstat (limited to 'lib/vcategories.php')
-rw-r--r-- | lib/vcategories.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/vcategories.php b/lib/vcategories.php index 5975e688b75..74864704e30 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -325,6 +325,38 @@ class OC_VCategories { } /** + * @brief Rename category. + * @param string $from The name of the existing category + * @param string $to The new name of the category. + * @returns bool + */ + public function rename($from, $to) { + $id = $this->array_searchi($from, $this->categories); + if($id === false) { + OCP\Util::writeLog('core', __METHOD__.', category: ' . $from. ' does not exist', OCP\Util::DEBUG); + return false; + } + + $sql = 'UPDATE `' . self::CATEGORY_TABLE . '` SET `category` = ? ' + . 'WHERE `uid` = ? AND `type` = ? AND `id` = ?'; + try { + $stmt = OCP\DB::prepare($sql); + $result = $stmt->execute(array($to, $this->user, $this->type, $id)); + if (OC_DB::isError($result)) { + echo 'DB error: ' . $result . "\n"; + OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR); + return false; + } + } catch(Exception $e) { + OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), + OCP\Util::ERROR); + return false; + } + $this->categories[$id] = $to; + return true; + } + + /** * @brief Add a new category. * @param $names A string with a name or an array of strings containing * the name(s) of the categor(y|ies) to add. |