Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add two new parameters to the ls action, only playing for recursive c…
Browse files Browse the repository at this point in the history
…ase: max_depth and max_nodes. If activated ( = recursion is cut before the end), the folder nodes have a new property ajxp_has_children = true|false to decide whether client must recurse again or not.
  • Loading branch information
cdujeu committed Jan 6, 2014
1 parent 64f9ef6 commit 3ee195e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
40 changes: 31 additions & 9 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -784,10 +784,6 @@ public function switchAction($action, $httpVars, $fileVars)
if ($this->wrapperClassName == "fsAccessWrapper") {
$nonPatchedPath = fsAccessWrapper::unPatchPathForBaseDir($path);
}
$threshold = $this->repository->getOption("PAGINATION_THRESHOLD");
if(!isSet($threshold) || intval($threshold) == 0) $threshold = 500;
$limitPerPage = $this->repository->getOption("PAGINATION_NUMBER");
if(!isset($limitPerPage) || intval($limitPerPage) == 0) $limitPerPage = 200;

if ($this->getFilteredOption("REMOTE_SORTING")) {
$orderDirection = isSet($httpVars["order_direction"])?strtolower($httpVars["order_direction"]):"asc";
Expand All @@ -796,9 +792,23 @@ public function switchAction($action, $httpVars, $fileVars)
$orderField = "ajxp_label";
}
}
if(isSet($httpVars["recursive"])){
$max_depth = (isSet($httpVars["max_depth"])?intval($httpVars["max_depth"]):0);
$max_nodes = (isSet($httpVars["max_nodes"])?intval($httpVars["max_nodes"]):0);
$crt_depth = (isSet($httpVars["crt_depth"])?intval($httpVars["crt_depth"])+1:1);
$crt_nodes = (isSet($httpVars["crt_nodes"])?intval($httpVars["crt_nodes"]):0);
}else{
$threshold = $this->repository->getOption("PAGINATION_THRESHOLD");
if(!isSet($threshold) || intval($threshold) == 0) $threshold = 500;
$limitPerPage = $this->repository->getOption("PAGINATION_NUMBER");
if(!isset($limitPerPage) || intval($limitPerPage) == 0) $limitPerPage = 200;
}

$countFiles = $this->countFiles($path, !$lsOptions["f"]);
if ($countFiles > $threshold) {
if(isSet($crt_nodes)){
$crt_nodes += $countFiles;
}
if (isSet($threshold) && isSet($limitPerPage) && $countFiles > $threshold) {
if (isSet($uniqueFile)) {
$originalLimitPerPage = $limitPerPage;
$offset = $limitPerPage = 0;
Expand Down Expand Up @@ -857,15 +867,15 @@ public function switchAction($action, $httpVars, $fileVars)
closedir($handle);
$fullList = array("d" => array(), "z" => array(), "f" => array());

if (isSet($orderField) && $orderField == "ajxp_label" && $orderDirection == "desc") {
if (isSet($orderField) && isSet($orderDirection) && $orderField == "ajxp_label" && $orderDirection == "desc") {
$nodes = scandir($path, 1);
} else {
$nodes = scandir($path);
}
if (!empty($this->driverConf["SCANDIR_RESULT_SORTFONC"])) {
usort($nodes, $this->driverConf["SCANDIR_RESULT_SORTFONC"]);
}
if (isSet($orderField) && $orderField != "ajxp_label") {
if (isSet($orderField) && isSet($orderDirection) && $orderField != "ajxp_label") {
$toSort = array();
foreach ($nodes as $node) {
if($orderField == "filesize") $toSort[$node] = is_file($nonPatchedPath."/".$node) ? $this->filesystemFileSize($nonPatchedPath."/".$node) : 0;
Expand Down Expand Up @@ -938,11 +948,23 @@ public function switchAction($action, $httpVars, $fileVars)
}
}
if (isSet($httpVars["recursive"]) && $httpVars["recursive"] == "true") {
foreach ($fullList["d"] as $nodeDir) {
$breakNow = false;
if(isSet($max_depth) && $max_depth > 0 && $crt_depth >= $max_depth) $breakNow = true;
if(isSet($max_nodes) && $max_nodes > 0 && $crt_nodes >= $max_nodes) $breakNow = true;
foreach ($fullList["d"] as &$nodeDir) {
if($breakNow){
$nodeDir->mergeMetadata(array("ajxp_has_children" => $this->countFiles($nodeDir->getUrl(), false, true)?"true":"false"));
AJXP_XMLWriter::renderAjxpNode($nodeDir, true);
continue;
}
$this->switchAction("ls", array(
"dir" => SystemTextEncoding::toUTF8($nodeDir->getPath()),
"options"=> $httpVars["options"],
"recursive" => "true"
"recursive" => "true",
"max_depth"=> $max_depth,
"max_nodes"=> $max_nodes,
"crt_depth"=> $crt_depth,
"crt_nodes"=> $crt_nodes,
), array());
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions core/src/plugins/access.fs/fsActions.xml
Expand Up @@ -36,6 +36,8 @@
<input_param description="One folder to list or one or more files to check" name="nodes" type="AJXP_NODE[]" mandatory="false"/>
<input_param description="Details to send back" name="options" type="string" mandatory="false" default="al"/>
<input_param description="Recursively list all folders" name="recursive" type="boolean" mandatory="false" default="false"/>
<input_param description="If recursive listing, maximum depth" name="max_depth" type="integer" mandatory="false"/>
<input_param description="If recursive listing, maximum number of nodes gathered (soft limit)" name="max_nodes" type="integer" mandatory="false"/>
<input_param description="Trigger remote order" name="remote_order" type="boolean" mandatory="false" default="false"/>
<input_param description="Remote order column" name="order_column" type="string" mandatory="false"/>
<input_param description="Remote order direction" name="order_direction" type="string" mandatory="false"/>
Expand Down

0 comments on commit 3ee195e

Please sign in to comment.