Fix: Some fix into ajax ecm.
New: The cache for nb of files into a dir is now implemented. By default it is "not defined" and we refresh it when making a scan of a dir for all subdirs.
This commit is contained in:
parent
913b923886
commit
2927a58606
@ -61,8 +61,8 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call
|
||||
$result=$ecmdir->fetch($section);
|
||||
if (! $result > 0)
|
||||
{
|
||||
dol_print_error($db,$ecmdir->error);
|
||||
exit;
|
||||
//dol_print_error($db,$ecmdir->error);
|
||||
//exit;
|
||||
}
|
||||
}
|
||||
else // For no ajax call
|
||||
|
||||
@ -78,7 +78,7 @@ $userstatic=new User($db);
|
||||
$form=new Form($db);
|
||||
$ecmdirstatic = new EcmDirectory($db);
|
||||
|
||||
// Load full tree. We will use it to define nbofsubdir and nboffilesinsubdir
|
||||
// Load full tree from database. We will use it to define nbofsubdir and nboffilesinsubdir
|
||||
if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0);
|
||||
|
||||
// Try to find key into $sqltree
|
||||
@ -93,13 +93,13 @@ foreach($sqltree as $keycursor => $val)
|
||||
}
|
||||
|
||||
|
||||
if( file_exists($fullpathselecteddir) )
|
||||
if (file_exists($fullpathselecteddir))
|
||||
{
|
||||
$files = @scandir($fullpathselecteddir);
|
||||
if ($files)
|
||||
{
|
||||
natcasesort($files);
|
||||
if( count($files) > 2 ) /* The 2 accounts for . and .. */
|
||||
if ( count($files) > 2 ) /* The 2 accounts for . and .. */
|
||||
{
|
||||
echo "<ul class=\"ecmjqft\" style=\"display: none;\">\n";
|
||||
|
||||
@ -111,16 +111,27 @@ if( file_exists($fullpathselecteddir) )
|
||||
$nbofsubdir=0;
|
||||
$nboffilesinsubdir=0;
|
||||
|
||||
// Try to find key into $sqltree
|
||||
$val=array();
|
||||
|
||||
// Loop on all database entries (sqltree) to find the one matching the subdir found into dir to scan
|
||||
foreach($sqltree as $key => $tmpval)
|
||||
{
|
||||
//print "-- ".$val['fullrelativename']." vs ".(($selecteddir != '/'?$selecteddir.'/':'').$file).'<br>';
|
||||
if ($tmpval['fullrelativename'] == (($selecteddir != '/'?$selecteddir.'/':'').$file))
|
||||
//print "-- key=".$key." - ".$val['fullrelativename']." vs ".(($selecteddir != '/'?$selecteddir.'/':'').$file).'<br>';
|
||||
if ($tmpval['fullrelativename'] == (($selecteddir != '/'?$selecteddir.'/':'').$file)) // We found equivalent record into database
|
||||
{
|
||||
$val=$tmpval;
|
||||
$resarray=tree_showpad($sqltree,$key,1);
|
||||
$resarray=tree_showpad($sqltree,$key,1);
|
||||
|
||||
// Refresh cache for this subdir
|
||||
if (isset($val['cachenbofdoc']) && $val['cachenbofdoc'] < 0) // Cache is not up to date, so we update it for this directory t
|
||||
{
|
||||
$result=$ecmdirstatic->fetch($val['id']);
|
||||
$ecmdirstatic->ref=$ecmdirstatic->label;
|
||||
|
||||
$result=$ecmdirstatic->refreshcachenboffile(0);
|
||||
$val['cachenbofdoc']=$result;
|
||||
}
|
||||
|
||||
$a=$resarray[0];
|
||||
$nbofsubdir=$resarray[1];
|
||||
$nboffilesinsubdir=$resarray[2];
|
||||
@ -128,10 +139,18 @@ if( file_exists($fullpathselecteddir) )
|
||||
}
|
||||
}
|
||||
|
||||
//if (file_exists($fullpathselecteddir . $file) && $file != '.' && $file != '..' && is_dir($fullpathselecteddir . $file))
|
||||
if ($file != '.' && $file != '..' && ((! empty($val['fullrelativename']) && $val['id'] >= 0) || dol_is_dir($fullpathselecteddir . $file)))
|
||||
//print 'modulepart='.$modulepart.' fullpathselecteddir='.$fullpathselecteddir.' - val[fullrelativename] (in database)='.$val['fullrelativename'].' - val[id]='.$val['id'].' - is_dir='.dol_is_dir($fullpathselecteddir . $file).' - file='.$file."\n";
|
||||
if ($file != '.' && $file != '..' && ((! empty($val['fullrelativename']) && $val['id'] >= 0) || dol_is_dir($fullpathselecteddir . (preg_match('/\/$/',$fullpathselecteddir)?'':'/') . $file)))
|
||||
{
|
||||
print '<li class="directory collapsed">';
|
||||
if (empty($val['fullrelativename'])) // If we did not find entry into database, but found a directory (dol_is_dir was ok at previous test)
|
||||
{
|
||||
$val['fullrelativename']=$file; $val['id']=0;
|
||||
$val['label']=$file;
|
||||
$val['description']='';
|
||||
$nboffilesinsubdir=$langs->trans("Unknown");
|
||||
}
|
||||
|
||||
print '<li class="directory collapsed">';
|
||||
|
||||
print "<a class=\"fmdirlia jqft ecmjqft\" href=\"#\" rel=\"" . dol_escape_htmltag($val['fullrelativename'].'/') . "\" id=\"fmdirlia_id_".$val['id']."\"";
|
||||
print " onClick=\"loadandshowpreview('".dol_escape_js($val['fullrelativename'])."',".$val['id'].")\">";
|
||||
@ -148,10 +167,10 @@ if( file_exists($fullpathselecteddir) )
|
||||
|
||||
// Nb of docs
|
||||
print '<td align="right">';
|
||||
print isset($val['cachenbofdoc'])?$val['cachenbofdoc']:' ';
|
||||
print (isset($val['cachenbofdoc']) && $val['cachenbofdoc'] >= 0)?$val['cachenbofdoc']:' ';
|
||||
print '</td>';
|
||||
print '<td align="left">';
|
||||
if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
|
||||
if ($nbofsubdir > 0 && $nboffilesinsubdir > 0) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
|
||||
print '</td>';
|
||||
|
||||
// Edit link
|
||||
@ -163,16 +182,16 @@ if( file_exists($fullpathselecteddir) )
|
||||
|
||||
// Info
|
||||
print '<td align="right" width="18">';
|
||||
$userstatic->id=$val['fk_user_c'];
|
||||
$userstatic->lastname=$val['login_c'];
|
||||
$userstatic->id=isset($val['fk_user_c'])?$val['fk_user_c']:0;
|
||||
$userstatic->lastname=isset($val['login_c'])?$val['login_c']:0;
|
||||
$htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
|
||||
$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
|
||||
$htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1).'<br>';
|
||||
$htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dol_print_date($val['date_c'],"dayhour").'<br>';
|
||||
$htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.(isset($val['date_c'])?dol_print_date($val['date_c'],"dayhour"):$langs->trans("NeedRefresh")).'<br>';
|
||||
$htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
|
||||
$htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
|
||||
if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
|
||||
else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
|
||||
$htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.((isset($val['cachenbofdoc']) && $val['cachenbofdoc'] >= 0)?$val['cachenbofdoc']:$langs->trans("NeedRefresh")).'<br>';
|
||||
if ($nboffilesinsubdir > 0) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
|
||||
else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.($nbofsubdir >= 0 ? $nbofsubdir : $langs->trans("NeedRefresh")).'<br>';
|
||||
print $form->textwithpicto('',$htmltooltip,1,"info");
|
||||
print "</td>";
|
||||
|
||||
|
||||
@ -101,8 +101,7 @@ function tree_showpad(&$fulltree,$key,$silent=0)
|
||||
if ($fulltree[$key2]['level'] > $pos)
|
||||
{
|
||||
$nbofdirinsub++;
|
||||
if (! empty($fulltree[$key2]['cachenbofdoc']))
|
||||
$nbofdocinsub+=$fulltree[$key2]['cachenbofdoc'];
|
||||
if (isset($fulltree[$key2]['cachenbofdoc']) && $fulltree[$key2]['cachenbofdoc'] > 0) $nbofdocinsub+=$fulltree[$key2]['cachenbofdoc'];
|
||||
}
|
||||
if ($fulltree[$key2]['level'] == $pos)
|
||||
{
|
||||
|
||||
@ -38,7 +38,7 @@ class EcmDirectory // extends CommonObject
|
||||
var $label;
|
||||
var $fk_parent;
|
||||
var $description;
|
||||
var $cachenbofdoc;
|
||||
var $cachenbofdoc=-1; // By default cache initialized with value 'not calculated'
|
||||
var $date_c;
|
||||
var $date_m;
|
||||
|
||||
@ -77,7 +77,6 @@ class EcmDirectory // extends CommonObject
|
||||
$this->label=dol_sanitizeFileName(trim($this->label));
|
||||
$this->fk_parent=trim($this->fk_parent);
|
||||
$this->description=trim($this->description);
|
||||
if (! $this->cachenbofdoc) $this->cachenbofdoc=0;
|
||||
$this->date_c=$now;
|
||||
$this->fk_user_c=$user->id;
|
||||
if ($this->fk_parent <= 0) $this->fk_parent=0;
|
||||
@ -132,7 +131,7 @@ class EcmDirectory // extends CommonObject
|
||||
$sql.= " '".$conf->entity."',";
|
||||
$sql.= " '".$this->fk_parent."',";
|
||||
$sql.= " '".$this->db->escape($this->description)."',";
|
||||
$sql.= " ".($this->cachenbofdoc).",";
|
||||
$sql.= " ".$this->cachenbofdoc.",";
|
||||
$sql.= " '".$this->db->idate($this->date_c)."',";
|
||||
$sql.= " '".$this->fk_user_c."'";
|
||||
$sql.= ")";
|
||||
@ -544,8 +543,7 @@ class EcmDirectory // extends CommonObject
|
||||
$sql.= " c.date_c,";
|
||||
$sql.= " u.login as login_c,";
|
||||
$sql.= " ca.rowid as rowid_fille";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."ecm_directories as c";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."ecm_directories as c";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."ecm_directories as ca";
|
||||
$sql.= " ON c.rowid = ca.fk_parent";
|
||||
$sql.= " WHERE c.fk_user_c = u.rowid";
|
||||
@ -650,10 +648,10 @@ class EcmDirectory // extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh value for cachenboffile
|
||||
* Refresh value for cachenboffile. This scan and count files into directory.
|
||||
*
|
||||
* @param int $all 0=refresh this id , 1=refresh this entity
|
||||
* @return int <0 if KO, Nb of files in directory if OK
|
||||
* @param int $all 0=refresh record using this->id , 1=refresh record using this->entity
|
||||
* @return int -1 if KO, Nb of files in directory if OK
|
||||
*/
|
||||
function refreshcachenboffile($all=0)
|
||||
{
|
||||
|
||||
@ -205,7 +205,7 @@ if ($action == 'refreshmanual')
|
||||
$diroutputslash.='/';
|
||||
|
||||
// Scan directory tree on disk
|
||||
$disktree=dol_dir_list($conf->ecm->dir_output,'directories',1,'','','','',0);
|
||||
$disktree=dol_dir_list($conf->ecm->dir_output,'directories',1,'','^temp$','','',0);
|
||||
|
||||
// Scan directory tree in database
|
||||
$sqltree=$ecmdirstatic->get_full_arbo(0);
|
||||
@ -283,7 +283,7 @@ if ($action == 'refreshmanual')
|
||||
|
||||
$txt="We create directory ".$ecmdirtmp->label." with parent ".$fk_parent;
|
||||
dol_syslog($txt);
|
||||
//print $txt."<br>\n";
|
||||
//print $ecmdirtmp->cachenbofdoc."<br>\n";exit;
|
||||
$id = $ecmdirtmp->create($user);
|
||||
if ($id > 0)
|
||||
{
|
||||
@ -309,7 +309,8 @@ if ($action == 'refreshmanual')
|
||||
}
|
||||
}
|
||||
|
||||
$sql="UPDATE ".MAIN_DB_PREFIX."ecm_directories set cachenbofdoc=0 WHERE cachenbofdoc < 0";
|
||||
$sql="UPDATE ".MAIN_DB_PREFIX."ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0"; // If pb into cahce counting, we set to value -1 = "unknown"
|
||||
dol_syslog("sql = ".$sql);
|
||||
$db->query($sql);
|
||||
|
||||
// If a directory was added, the fulltree array is not correctly completed and sorted, so we clean
|
||||
@ -693,7 +694,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
|
||||
$result=$ecmdirstatic->fetch($val['id']);
|
||||
$ecmdirstatic->ref=$ecmdirstatic->label;
|
||||
|
||||
$result=$ecmdirstatic->refreshcachenboffile();
|
||||
$result=$ecmdirstatic->refreshcachenboffile(0);
|
||||
$val['cachenbofdoc']=$result;
|
||||
}
|
||||
|
||||
|
||||
@ -84,3 +84,4 @@ ALTER TABLE llx_facturedet_rec ADD COLUMN label varchar(255) DEFAULT NULL AFTER
|
||||
ALTER TABLE llx_accountingaccount ADD COLUMN active tinyint DEFAULT 1 NOT NULL AFTER label;
|
||||
|
||||
ALTER TABLE llx_actioncomm MODIFY elementtype VARCHAR(32);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user