diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-05-20 08:08:15 -0700 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-05-20 08:08:15 -0700 |
commit | 54d3b381a8fec41df9c211f9a61aa23680081705 (patch) | |
tree | 544c91d7e30a7c9acc31e47f32ca90073419370a | |
parent | 6609de28d832262e8f72fb19e5f0343cd021cca3 (diff) | |
parent | 946740a71f9f48df8afb69852688c3e5c28b213f (diff) | |
download | nextcloud-server-54d3b381a8fec41df9c211f9a61aa23680081705.tar.gz nextcloud-server-54d3b381a8fec41df9c211f9a61aa23680081705.zip |
Merge pull request #3430 from owncloud/vcategory_rename
Add rename() method to OC_VCategories.
-rw-r--r-- | lib/vcategories.php | 31 | ||||
-rw-r--r-- | tests/lib/vcategories.php | 11 |
2 files changed, 42 insertions, 0 deletions
diff --git a/lib/vcategories.php b/lib/vcategories.php index 5975e688b75..91c72d5dfae 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -325,6 +325,37 @@ 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)) { + 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. diff --git a/tests/lib/vcategories.php b/tests/lib/vcategories.php index e79dd49870c..df5f600f20d 100644 --- a/tests/lib/vcategories.php +++ b/tests/lib/vcategories.php @@ -81,6 +81,17 @@ class Test_VCategories extends PHPUnit_Framework_TestCase { } + public function testrenameCategory() { + $defcategories = array('Friends', 'Family', 'Wrok', 'Other'); + $catmgr = new OC_VCategories($this->objectType, $this->user, $defcategories); + + $this->assertTrue($catmgr->rename('Wrok', 'Work')); + $this->assertTrue($catmgr->hasCategory('Work')); + $this->assertFalse($catmgr->hasCategory('Wrok')); + $this->assertFalse($catmgr->rename('Wrok', 'Work')); + + } + public function testAddToCategory() { $objids = array(1, 2, 3, 4, 5, 6, 7, 8, 9); |