mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-24 10:21:32 +01:00
NEW The purge of iles can purge only if older than a number of seconds
This commit is contained in:
@@ -54,10 +54,11 @@ function dol_basename($pathfile)
|
||||
* @param int $nohook Disable all hooks
|
||||
* @param string $relativename For recursive purpose only. Must be "" at first call.
|
||||
* @param string $donotfollowsymlinks Do not follow symbolic links
|
||||
* @param string $nbsecondsold Only files older than $nbsecondsold
|
||||
* @return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file',...)
|
||||
* @see dol_dir_list_in_database()
|
||||
*/
|
||||
function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename = "", $donotfollowsymlinks = 0)
|
||||
function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename = "", $donotfollowsymlinks = 0, $nbsecondsold = 0)
|
||||
{
|
||||
global $db, $hookmanager;
|
||||
global $object;
|
||||
@@ -67,13 +68,14 @@ function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excl
|
||||
//print 'xxx'."files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter);
|
||||
}
|
||||
|
||||
$loaddate = ($mode == 1 || $mode == 2) ?true:false;
|
||||
$loadsize = ($mode == 1 || $mode == 3) ?true:false;
|
||||
$loadperm = ($mode == 1 || $mode == 4) ?true:false;
|
||||
$loaddate = ($mode == 1 || $mode == 2 || $nbsecondsold) ? true : false;
|
||||
$loadsize = ($mode == 1 || $mode == 3) ?true : false;
|
||||
$loadperm = ($mode == 1 || $mode == 4) ?true : false;
|
||||
|
||||
// Clean parameters
|
||||
$path = preg_replace('/([\\/]+)$/i', '', $path);
|
||||
$newpath = dol_osencode($path);
|
||||
$now = dol_now();
|
||||
|
||||
$reshook = 0;
|
||||
$file_list = array();
|
||||
@@ -170,7 +172,7 @@ function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excl
|
||||
if ($recursive > 0) {
|
||||
if (empty($donotfollowsymlinks) || !is_link($path."/".$file)) {
|
||||
//var_dump('eee '. $path."/".$file. ' '.is_dir($path."/".$file).' '.is_link($path."/".$file));
|
||||
$file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive + 1, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename != '' ? $relativename.'/' : '').$file, $donotfollowsymlinks));
|
||||
$file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive + 1, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename != '' ? $relativename.'/' : '').$file, $donotfollowsymlinks, $nbsecondsold));
|
||||
}
|
||||
}
|
||||
} elseif (!$isdir && (($types == "files") || ($types == "all"))) {
|
||||
@@ -183,18 +185,20 @@ function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excl
|
||||
}
|
||||
|
||||
if (!$filter || preg_match('/'.$filter.'/i', $file)) { // We do not search key $filter into $path, only into $file
|
||||
preg_match('/([^\/]+)\/[^\/]+$/', $path.'/'.$file, $reg);
|
||||
$level1name = (isset($reg[1]) ? $reg[1] : '');
|
||||
$file_list[] = array(
|
||||
"name" => $file,
|
||||
"path" => $path,
|
||||
"level1name" => $level1name,
|
||||
"relativename" => ($relativename ? $relativename.'/' : '').$file,
|
||||
"fullname" => $path.'/'.$file,
|
||||
"date" => $filedate,
|
||||
"size" => $filesize,
|
||||
"type" => 'file'
|
||||
);
|
||||
if (empty($nbsecondsold) || $filedate <= ($now - $nbsecondsold)) {
|
||||
preg_match('/([^\/]+)\/[^\/]+$/', $path.'/'.$file, $reg);
|
||||
$level1name = (isset($reg[1]) ? $reg[1] : '');
|
||||
$file_list[] = array(
|
||||
"name" => $file,
|
||||
"path" => $path,
|
||||
"level1name" => $level1name,
|
||||
"relativename" => ($relativename ? $relativename.'/' : '').$file,
|
||||
"fullname" => $path.'/'.$file,
|
||||
"date" => $filedate,
|
||||
"size" => $filesize,
|
||||
"type" => 'file'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user