Permalink
Browse files

Clear broken links.

Clear activity feed.
  • Loading branch information...
1 parent 19d0b9f commit f49c3bd2afd8b7aca57ca767193b95961da5d868 @cdujeu cdujeu committed Jul 29, 2016
@@ -968,9 +968,10 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
$itemsPerPage = 50;
$crtPage = 1;
$crtOffset = 0;
- $parentRepoId = isset($httpVars["parent_repository_id"]) ? $httpVars["parent_repository_id"] : "";
- $userContext = $httpVars["user_context"];
- $currentUser = $ctx->getUser()->getId();
+ $parentRepoId = isset($httpVars["parent_repository_id"]) ? $httpVars["parent_repository_id"] : "";
+ $userContext = $httpVars["user_context"];
+ $currentUser = $ctx->getUser()->getId();
+ $clearBroken = (isSet($httpVars["clear_broken_links"]) && $httpVars["clear_broken_links"] === "true") ? 0 : -1;
if($userContext == "global" && $ctx->getUser()->isAdmin()){
$currentUser = false;
}else if($userContext == "user" && $ctx->getUser()->isAdmin() && !empty($httpVars["user_id"])){
@@ -982,7 +983,14 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
$crtOffset = ($crtPage - 1) * $itemsPerPage;
}
$cursor = [$crtOffset, $itemsPerPage];
- $nodes = $this->listSharesAsNodes($ctx, "/data/repositories/$parentRepoId/shares", $currentUser, $parentRepoId, $cursor);
+ if($clearBroken > -1) {
+ $cursor = null;
+ }
+ $nodes = $this->listSharesAsNodes($ctx, "/data/repositories/$parentRepoId/shares", $currentUser, $parentRepoId, $cursor, $clearBroken);
+ if($clearBroken > -1){
+ $responseInterface = new JsonResponse(["cleared_count" => $clearBroken]);
+ break;
+ }
$total = $cursor["total"];
$nodesList = new NodesList();
@@ -1848,10 +1856,10 @@ public function listShares($currentUser, $parentRepositoryId="", &$cursor = null
* @param bool|string $currentUser if true, currently logged user. if false all users. If string, user ID.
* @param string $parentRepositoryId
* @param null $cursor
- * @param bool $xmlPrint
+ * @param int $clearBroken
* @return AJXP_Node[]
*/
- public function listSharesAsNodes(ContextInterface $ctx, $rootPath, $currentUser, $parentRepositoryId = "", &$cursor = null, $xmlPrint = false){
+ public function listSharesAsNodes(ContextInterface $ctx, $rootPath, $currentUser, $parentRepositoryId = "", &$cursor = null, &$clearBroken = -1){
$shares = $this->listShares($currentUser, $parentRepositoryId, $cursor);
$nodes = array();
@@ -1876,6 +1884,10 @@ public function listSharesAsNodes(ContextInterface $ctx, $rootPath, $currentUser
$repoObject = RepositoryService::getRepositoryById($repoId);
if($repoObject == null){
$meta["text"] = "Invalid link";
+ if($clearBroken > -1){
+ $this->getShareStore($ctx)->deleteShare($shareType, $hash, false, true);
+ $clearBroken ++;
+ }
continue;
}
$meta["text"] = $repoObject->getDisplay();
@@ -1929,6 +1941,20 @@ public function listSharesAsNodes(ContextInterface $ctx, $rootPath, $currentUser
if(!empty($parentPath) && strpos($meta["original_path"], $parentPath) === 0){
$meta["original_path"] = substr($meta["original_path"], strlen($parentPath));
}
+ try{
+ // Test node really exists
+ $originalNode = new AJXP_Node("pydio://".$meta["owner"]."@".$meta["shared_element_parent_repository"].$meta["original_path"]);
+ $test = @file_exists($originalNode->getUrl());
+ if(!$test){
+ if($clearBroken > -1){
+ $this->getShareStore($ctx)->deleteShare($shareType, $hash);
+ $clearBroken ++;
+ }else{
+ $meta["broken_link"] = true;
+ $meta["original_path"] .= " (BROKEN)";
+ }
+ }
+ }catch(\Exception $e){}
}else if($shareData["REPOSITORY"] instanceof Repository && !empty($shareData["FILE_PATH"])){
@@ -1946,12 +1972,8 @@ public function listSharesAsNodes(ContextInterface $ctx, $rootPath, $currentUser
continue;
}
+ $nodes[] = new AJXP_Node($rootPath."/".$hash, $meta);
- if($xmlPrint){
- XMLWriter::renderAjxpNode(new AJXP_Node($rootPath."/".$hash, $meta));
- }else{
- $nodes[] = new AJXP_Node($rootPath."/".$hash, $meta);
- }
}
return $nodes;
@@ -57,6 +57,16 @@ public function persistEvent($hookName, $data, $repositoryId, $repositoryScope,
public function loadEvents($filterByRepositories, $filterByPath, $userGroup, $offset = 0, $limit = 10, $enlargeToOwned = true, $userId);
/**
+ * Delete feed data
+ * @param string $types
+ * @param null $userId
+ * @param null $repositoryId
+ * @param int $count
+ * @return mixed
+ */
+ public function deleteFeed($types='event', $userId = null, $repositoryId = null, &$count = 0);
+
+ /**
* @abstract
* @param Notification $notif
* @return mixed
@@ -20,17 +20,22 @@
*/
namespace Pydio\Notification\Core;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\AJXP_Node;
+use Pydio\Core\Exception\PydioException;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Controller\Controller;
use Pydio\Core\Services\LocaleService;
use Pydio\Core\Services\RepositoryService;
+use Pydio\Core\Utils\Vars\InputFilter;
use Pydio\Core\Utils\Vars\StatHelper;
use Pydio\Core\PluginFramework\Plugin;
use Pydio\Core\Utils\TextEncoder;
use \DOMXPath as DOMXPath;
+use Zend\Diactoros\Response\JsonResponse;
defined('AJXP_EXEC') or die( 'Access not allowed');
@@ -328,6 +333,27 @@ public function loadUserFeed(\Psr\Http\Message\ServerRequestInterface $requestIn
}
+ /**
+ * @param ServerRequestInterface $requestInterface
+ * @param ResponseInterface $responseInterface
+ * @throws PydioException
+ */
+ public function clearUserFeed(ServerRequestInterface $requestInterface, ResponseInterface &$responseInterface){
+
+ if(!$this->eventStore){
+ return;
+ }
+ $data = $requestInterface->getParsedBody();
+ $contextType = $data["context_type"];
+ if(!in_array($contextType, ["all", "user", "repository"])){
+ throw new PydioException("Invalid Arguments");
+ }
+ $contextValue = InputFilter::sanitize($data["context_value"], InputFilter::SANITIZE_ALPHANUM);
+ $this->eventStore->deleteFeed('event', $contextType === 'user' ? $contextValue : null, $contextType === 'repository' ? $contextValue : null, $count);
+ $responseInterface = new JsonResponse(["cleared_rows" => $count]);
+
+ }
+
/**
* @param $actionName
@@ -69,6 +69,12 @@
</serverCallback>
</processing>
</action>
+ <action name="clear_feed">
+ <processing><serverCallback methodName="clearUserFeed" restParams="/context_type/context_value">
+ <input_param name="context_type" type="string" description="all|repository|user"/>
+ <input_param name="context_value" type="string" description="Either empty, or a repo ID, or a userId depending on the context_type"/>
+ </serverCallback></processing>
+ </action>
<action name="dismiss_user_alert">
<gui text="notification_center.7" title="notification_center.7" iconClass="mdi mdi-close-circle" src="notification_center/ICON_SIZE/feed.png" accessKey="" hasAccessKey="false">
<context selection="true" dir="" recycle="true" actionBar="true" actionBarGroup="inline-notifications" contextMenu="false" infoPanel="false"/>
@@ -432,4 +432,32 @@ public function installSQLTables($param)
return DBHelper::runCreateTablesQuery($p, $this->getBaseDir() . "/create.sql");
}
+ /**
+ * Delete feed data
+ * @param array|string $types
+ * @param null $userId
+ * @param null $repositoryId
+ * @param int $count
+ * @return mixed
+ */
+ public function deleteFeed($types = 'event', $userId = null, $repositoryId = null, &$count = 0)
+ {
+ $wheres = [];
+ if($types !== 'both') {
+ $wheres[] = ['etype = %s', $types];
+ }
+ if($userId != null) {
+ $wheres[] = ['user_id = %s OR index_path LIKE %s', $userId, '%pydio://'.$userId.'@%'];
+ }
+ if($repositoryId != null) {
+ $wheres[] = ['repository_id = %s OR index_path LIKE %s', $repositoryId, '%pydio://%@'.$repositoryId.'/%'];
+ }
+ if(count($wheres)){
+ $count = dibi::query("SELECT count(*) FROM [ajxp_feed] WHERE %and ", $wheres)->fetchSingle();
+ dibi::query("DELETE FROM [ajxp_feed] WHERE %and", $wheres);
+ }else{
+ $count = dibi::query("SELECT count(*) FROM [ajxp_feed]")->fetchSingle();
+ dibi::query("DELETE FROM [ajxp_feed]");
+ }
+ }
}

0 comments on commit f49c3bd

Please sign in to comment.