Skip to content

Commit

Permalink
Request: 13688 Add a rough removeUserData method to trean.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael J Rubinsky <mrubinsk@horde.org>
  • Loading branch information
Lukas Weiss authored and mrubinsk committed Feb 5, 2015
1 parent aba10d6 commit efe24cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
31 changes: 31 additions & 0 deletions trean/lib/Application.php
Expand Up @@ -126,4 +126,35 @@ public function cleanupData()
return Horde_Data::IMPORT_FILE;
}

/**
*/
public function removeUserData($user)
{
$error = false;

$userManager = $GLOBALS['injector']->getInstance('Content_Users_Manager');
try {
$userId = current($userManager->ensureUsers($user));
} catch (Content_Exception $e) {
Horde::log($e, 'NOTICE');
$error = true;
}

if (!$error) {
try {
$bookmarks = $GLOBALS['trean_gateway']->listBookmarks('title', 0, 0, 0, $userId);
foreach ($bookmarks as $bookmark) {
$GLOBALS['trean_gateway']->removeBookmark($bookmark);
}
} catch (Trean_Exception $e) {
Horde::log($e, 'NOTICE');
$error = true;
}
}

if ($error) {
throw new Trean_Exception(sprintf(_("There was an error removing bookmarks for %s. Details have been logged."), $user));
}
}

}
6 changes: 3 additions & 3 deletions trean/lib/Bookmarks.php
Expand Up @@ -76,9 +76,9 @@ public function newBookmark(array $properties, $crawl = true)
*
* @return array An array of Trean_Bookmark objects.
*/
public function listBookmarks($sortby = 'title', $sortdir = 0, $from = 0, $count = 0)
public function listBookmarks($sortby = 'title', $sortdir = 0, $from = 0, $count = 0, $userId = NULL)
{
$values = array($this->_userId);
$values = array(is_null($userId) ? $this->_userId : $userId);

$sql = 'SELECT bookmark_id, user_id, bookmark_url, bookmark_title, bookmark_description, bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
Expand Down Expand Up @@ -220,7 +220,7 @@ public function getBookmarks(array $ids, array $options = array())
public function removeBookmark(Trean_Bookmark $bookmark)
{
/* Check permissions. */
if ($bookmark->userId != $this->_userId) {
if ($bookmark->userId != $this->_userId && !$GLOBALS['registry']->isAdmin()) {
throw new Horde_Exception_PermissionDenied();
}

Expand Down

0 comments on commit efe24cc

Please sign in to comment.