summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-04 03:09:17 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-04 03:09:26 +0200
commit57e61031877e1f921e7b4446471c61e4c5ac1b13 (patch)
tree7128e8d03cddd191113e0e8e447dcee5437d37d4
parent8eedcfa1446fb6589cf57ec19ef5b5163b38b5b3 (diff)
register hooks for deleting feeds, folders and items if a user is deleted, fix #468
-rw-r--r--CHANGELOG3
-rw-r--r--appinfo/app.php3
-rw-r--r--businesslayer/feedbusinesslayer.php10
-rw-r--r--businesslayer/folderbusinesslayer.php9
-rw-r--r--businesslayer/itembusinesslayer.php9
-rw-r--r--db/feedmapper.php11
-rw-r--r--db/foldermapper.php9
-rw-r--r--db/itemmapper.php16
-rw-r--r--hooks/user.php46
-rw-r--r--tests/unit/businesslayer/FeedBusinessLayerTest.php9
-rw-r--r--tests/unit/businesslayer/FolderBusinessLayerTest.php11
-rw-r--r--tests/unit/businesslayer/ItemBusinessLayerTest.php12
-rw-r--r--tests/unit/db/FeedMapperTest.php12
-rw-r--r--tests/unit/db/FolderMapperTest.php11
-rw-r--r--tests/unit/db/ItemMapperTest.php15
15 files changed, 186 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index adfc87b79..aebe44ed6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+owncloud-news (1.809)
+* Delete folders, feeds and articles if a user is deleted
+
owncloud-news (1.808)
* Also focus article area when clicking on all unread link
* Autofocus article area by default on load
diff --git a/appinfo/app.php b/appinfo/app.php
index b2f082ee7..dcc00f3d3 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -26,6 +26,7 @@ namespace OCA\News;
use \OCA\AppFramework\Core\API;
+
// dont break owncloud when the appframework is not enabled
if(\OCP\App::isEnabled('appframework')){
@@ -54,6 +55,8 @@ if(\OCP\App::isEnabled('appframework')){
));
$api->addRegularTask('OCA\News\Backgroundjob\Task', 'run');
+ $api->connectHook('OC_User', 'pre_deleteUser',
+ 'OCA\News\Hooks\UserHooks', 'deleteUser');
} else {
$msg = 'Can not enable the News app because the App Framework App is disabled';
diff --git a/businesslayer/feedbusinesslayer.php b/businesslayer/feedbusinesslayer.php
index c9b993e5a..de6dabe63 100644
--- a/businesslayer/feedbusinesslayer.php
+++ b/businesslayer/feedbusinesslayer.php
@@ -359,4 +359,14 @@ class FeedBusinessLayer extends BusinessLayer {
}
+ /**
+ * Deletes all feeds of a user, delete items first since the user_id
+ * is not defined in there
+ * @param string $userId the name of the user
+ */
+ public function deleteUser($userId) {
+ $this->mapper->deleteUser($userId);
+ }
+
+
}
diff --git a/businesslayer/folderbusinesslayer.php b/businesslayer/folderbusinesslayer.php
index e43c705c6..b6b2ce013 100644
--- a/businesslayer/folderbusinesslayer.php
+++ b/businesslayer/folderbusinesslayer.php
@@ -171,4 +171,13 @@ class FolderBusinessLayer extends BusinessLayer {
}
+ /**
+ * Deletes all folders of a user
+ * @param string $userId the name of the user
+ */
+ public function deleteUser($userId) {
+ $this->mapper->deleteUser($userId);
+ }
+
+
}
diff --git a/businesslayer/itembusinesslayer.php b/businesslayer/itembusinesslayer.php
index 6a00d8ba1..7c8e7e02c 100644
--- a/businesslayer/itembusinesslayer.php
+++ b/businesslayer/itembusinesslayer.php
@@ -237,4 +237,13 @@ class ItemBusinessLayer extends BusinessLayer {
}
+ /**
+ * Deletes all items of a user
+ * @param string $userId the name of the user
+ */
+ public function deleteUser($userId) {
+ $this->mapper->deleteUser($userId);
+ }
+
+
}
diff --git a/db/feedmapper.php b/db/feedmapper.php
index 60f9abefa..23b6da5d6 100644
--- a/db/feedmapper.php
+++ b/db/feedmapper.php
@@ -198,4 +198,15 @@ class FeedMapper extends Mapper implements IMapper {
}
+ /**
+ * Deletes all feeds of a user, delete items first since the user_id
+ * is not defined in there
+ * @param string $userId the name of the user
+ */
+ public function deleteUser($userId) {
+ $sql = 'DELETE FROM `*PREFIX*news_feeds` WHERE `user_id` = ?';
+ $this->execute($sql, array($userId));
+ }
+
+
}
diff --git a/db/foldermapper.php b/db/foldermapper.php
index 8f6c32cde..2abe89b29 100644
--- a/db/foldermapper.php
+++ b/db/foldermapper.php
@@ -127,5 +127,14 @@ class FolderMapper extends Mapper implements IMapper {
}
+ /**
+ * Deletes all folders of a user
+ * @param string $userId the name of the user
+ */
+ public function deleteUser($userId) {
+ $sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?';
+ $this->execute($sql, array($userId));
+ }
+
} \ No newline at end of file
diff --git a/db/itemmapper.php b/db/itemmapper.php
index 1ec283826..5b2ab5346 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -300,4 +300,20 @@ class ItemMapper extends Mapper implements IMapper {
return (int) $result['max_id'];
}
+
+ /**
+ * Deletes all items of a user
+ * @param string $userId the name of the user
+ */
+ public function deleteUser($userId) {
+ $sql = 'DELETE FROM `*PREFIX*news_items` `items` ' .
+ 'WHERE `items`.`feed_id` IN (' .
+ 'SELECT `feeds`.`id` FROM `*PREFIX*news_feeds` `feeds` ' .
+ 'WHERE `feeds`.`user_id` = ?' .
+ ')';
+
+ $this->execute($sql, array($userId));
+ }
+
+
}
diff --git a/hooks/user.php b/hooks/user.php
new file mode 100644
index 000000000..820f0f881
--- /dev/null
+++ b/hooks/user.php
@@ -0,0 +1,46 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Cosentino
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Hooks;
+
+use \OCA\News\DependencyInjection\DIContainer;
+
+
+class UserHooks {
+
+
+ public static deleteUser($params) {
+ $userId = $params['uid'];
+
+ $container = new DIContainer();
+
+ // order is important!
+ $container['ItemBusinessLayer']->deleteUser($userId);
+ $container['FeedBusinessLayer']->deleteUser($userId);
+ $container['FolderBusinessLayer']->deleteUser($userId);
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php
index 357ee73eb..40b1fa883 100644
--- a/tests/unit/businesslayer/FeedBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php
@@ -733,5 +733,14 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
}
+ public function testDeleteUser() {
+ $this->feedMapper->expects($this->once())
+ ->method('deleteUser')
+ ->will($this->returnValue($this->user));
+
+ $this->feedBusinessLayer->deleteUser($this->user);
+ }
+
+
}
diff --git a/tests/unit/businesslayer/FolderBusinessLayerTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php
index 7f512920e..b473e5dea 100644
--- a/tests/unit/businesslayer/FolderBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php
@@ -285,4 +285,15 @@ class FolderBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->folderBusinessLayer->purgeDeleted($this->user, false);
}
+
+
+ public function testDeleteUser() {
+ $this->folderMapper->expects($this->once())
+ ->method('deleteUser')
+ ->will($this->returnValue($this->user));
+
+ $this->folderBusinessLayer->deleteUser($this->user);
+ }
+
+
}
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php
index 5dc6c9895..c120b753d 100644
--- a/tests/unit/businesslayer/ItemBusinessLayerTest.php
+++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php
@@ -360,6 +360,18 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->assertEquals($star, $result);
}
+
+
+ public function testDeleteUser() {
+ $this->mapper->expects($this->once())
+ ->method('deleteUser')
+ ->will($this->returnValue($this->user));
+
+ $this->itemBusinessLayer->deleteUser($this->user);
+ }
+
+
+
}
diff --git a/tests/unit/db/FeedMapperTest.php b/tests/unit/db/FeedMapperTest.php
index 005f17a03..b7d095861 100644
--- a/tests/unit/db/FeedMapperTest.php
+++ b/tests/unit/db/FeedMapperTest.php
@@ -356,4 +356,16 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->assertEquals($this->feeds, $result);
}
+
+
+ public function testDeleteFromUser(){
+ $userId = 'john';
+ $sql = 'DELETE FROM `*PREFIX*news_feeds` WHERE `user_id` = ?';
+
+ $this->setMapperResult($sql, array($userId));
+
+ $this->mapper->deleteUser($userId);
+ }
+
+
}
diff --git a/tests/unit/db/FolderMapperTest.php b/tests/unit/db/FolderMapperTest.php
index 082931c25..989f7a339 100644
--- a/tests/unit/db/FolderMapperTest.php
+++ b/tests/unit/db/FolderMapperTest.php
@@ -237,4 +237,15 @@ class FolderMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->assertEquals($this->folders, $result);
}
+
+ public function testDeleteFromUser(){
+ $userId = 'john';
+ $sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?';
+
+ $this->setMapperResult($sql, array($userId));
+
+ $this->folderMapper->deleteUser($userId);
+ }
+
+
} \ No newline at end of file
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index fb7489f3d..a2df2178a 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -435,4 +435,19 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$result = $this->mapper->getNewestItemId($this->user);
}
+
+ public function testDeleteFromUser(){
+ $userId = 'john';
+ $sql = 'DELETE FROM `*PREFIX*news_items` `items` ' .
+ 'WHERE `items`.`feed_id` IN (' .
+ 'SELECT `feeds`.`id` FROM `*PREFIX*news_feeds` `feeds` ' .
+ 'WHERE `feeds`.`user_id` = ?' .
+ ')';
+
+ $this->setMapperResult($sql, array($userId));
+
+ $this->mapper->deleteUser($userId);
+ }
+
+
}