Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-10-03 00:46:37 +0400
committerThomas Tanghus <thomas@tanghus.net>2012-10-03 00:47:59 +0400
commit6bfb2ca2a8ca18fe45997d720b1adc7781d51d2a (patch)
tree08bb988f78c2e3217172036a429cb573821283d1 /lib/vcategories.php
parent52eded06791519613a9c5fb2824f89d04bdb65b8 (diff)
Added post_deleteUser hook to VCategories. Added methods for adding/removing object/category relations.
Diffstat (limited to 'lib/vcategories.php')
-rw-r--r--lib/vcategories.php116
1 files changed, 110 insertions, 6 deletions
diff --git a/lib/vcategories.php b/lib/vcategories.php
index 08faa0d9035..499fffad3ff 100644
--- a/lib/vcategories.php
+++ b/lib/vcategories.php
@@ -21,6 +21,7 @@
*
*/
+OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_VCategories', 'post_deleteUser');
/**
* Class for easy access to categories in VCARD, VEVENT, VTODO and VJOURNAL.
@@ -147,7 +148,7 @@ class OC_VCategories {
/**
* @brief Get the a list if items belonging to $category.
* @param string|integer $category Category id or name.
- * @param string $table The name of table to query.
+ * @param array $tableinfo Array in the form {'tablename' => table, 'fields' => ['field1', 'field2']}
* @param int $limit
* @param int $offset
*
@@ -327,7 +328,7 @@ class OC_VCategories {
private function save() {
if(is_array($this->categories)) {
foreach($this->categories as $category) {
- OCP\DB::insertIfNotExist('*PREFIX*vcategory',
+ OCP\DB::insertIfNotExist(self::$category_table,
array(
'uid' => $this->user,
'type' => $this->type,
@@ -345,7 +346,7 @@ class OC_VCategories {
$catid = $this->array_searchi($relation['category'], $categories);
OC_Log::write('core', __METHOD__ . 'catid, ' . $relation['category'] . ' ' . $catid, OC_Log::DEBUG);
if($catid) {
- OCP\DB::insertIfNotExist('*PREFIX*vcategory_to_object',
+ OCP\DB::insertIfNotExist(self::$relation_table,
array(
'objid' => $relation['objid'],
'categoryid' => $catid,
@@ -361,21 +362,124 @@ class OC_VCategories {
}
/**
+ * @brief Delete categories and category/object relations for a user.
+ * For hooking up on post_deleteUser
+ * @param string $uid The user id for which entries should be purged.
+ */
+ public static function post_deleteUser($arguments) {
+ // Find all objectid/categoryid pairs.
+ $result = null;
+ try {
+ $stmt = OCP\DB::prepare('SELECT `id` FROM `*PREFIX*vcategory` '
+ . 'WHERE `uid` = ?');
+ $result = $stmt->execute(array($arguments['uid']));
+ } catch(Exception $e) {
+ OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+ OCP\Util::ERROR);
+ }
+
+ if(!is_null($result)) {
+ try {
+ $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*vcategory_to_object` '
+ . 'WHERE `categoryid` = ?');
+ while( $row = $result->fetchRow()) {
+ try {
+ $stmt->execute(array($row['id']));
+ } catch(Exception $e) {
+ OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+ OCP\Util::ERROR);
+ }
+ }
+ } catch(Exception $e) {
+ OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+ OCP\Util::ERROR);
+ }
+ }
+ try {
+ $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*vcategory` '
+ . 'WHERE `uid` = ? AND');
+ $result = $stmt->execute(array($arguments['uid']));
+ } catch(Exception $e) {
+ OCP\Util::writeLog('core', __METHOD__ . ', exception: '
+ . $e->getMessage(), OCP\Util::ERROR);
+ }
+ }
+
+ /**
* @brief Delete category/object relations from the db
- * @param $id The id of the object
- * @param $type The type of object (event/contact/task/journal).
+ * @param int $id The id of the object
+ * @param string $type The type of object (event/contact/task/journal).
* Defaults to the type set in the instance
+ * @returns boolean
*/
public function purgeObject($id, $type = null) {
$type = is_null($type) ? $this->type : $type;
try {
- $stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*vcategory_to_object` '
+ $stmt = OCP\DB::prepare('DELETE FROM `' . self::$relation_table . '` '
. 'WHERE `objid` = ? AND `type`= ?');
$stmt->execute(array($id, $type));
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @brief Creates a category/object relation.
+ * @param int $objid The id of the object
+ * @param int|string $category The id or name of the category
+ * @param string $type The type of object (event/contact/task/journal).
+ * Defaults to the type set in the instance
+ * @returns boolean
+ */
+ public function createRelation($objid, $category, $type = null) {
+ $type = is_null($type) ? $this->type : $type;
+ $categoryid = (is_string($category) && !is_numeric($category))
+ ? $this->array_searchi($category, $this->categories)
+ : $category;
+ try {
+ OCP\DB::insertIfNotExist(self::$relation_table,
+ array(
+ 'objid' => $objid,
+ 'categoryid' => $categoryid,
+ 'type' => $type,
+ ));
+ } catch(Exception $e) {
+ OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+ OCP\Util::ERROR);
+ return false;
}
+ return true;
+ }
+
+ /**
+ * @brief Delete single category/object relation from the db
+ * @param int $objid The id of the object
+ * @param int|string $category The id or name of the category
+ * @param string $type The type of object (event/contact/task/journal).
+ * Defaults to the type set in the instance
+ * @returns boolean
+ */
+ public function removeRelation($objid, $category, $type = null) {
+ $type = is_null($type) ? $this->type : $type;
+ $categoryid = (is_string($category) && !is_numeric($category))
+ ? $this->array_searchi($category, $this->categories)
+ : $category;
+ try {
+ $sql = 'DELETE FROM `' . self::$relation_table . '` '
+ . 'WHERE `objid` = ? AND `categoryid` = ? AND `type` = ?';
+ OCP\Util::writeLog('core', __METHOD__.', sql: ' . $objid . ' ' . $categoryid . ' ' . $type,
+ OCP\Util::DEBUG);
+ $stmt = OCP\DB::prepare($sql);
+ $stmt->execute(array($objid, $categoryid, $type));
+ } catch(Exception $e) {
+ OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+ OCP\Util::ERROR);
+ return false;
+ }
+ return true;
}
/**