diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php
index 024e62dbf27..1460d87bfba 100644
--- a/htdocs/core/ajax/ajaxdirpreview.php
+++ b/htdocs/core/ajax/ajaxdirpreview.php
@@ -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
diff --git a/htdocs/core/ajax/ajaxdirtree.php b/htdocs/core/ajax/ajaxdirtree.php
index 9de59a527d1..21487924b91 100644
--- a/htdocs/core/ajax/ajaxdirtree.php
+++ b/htdocs/core/ajax/ajaxdirtree.php
@@ -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 "
\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).'
';
- if ($tmpval['fullrelativename'] == (($selecteddir != '/'?$selecteddir.'/':'').$file))
+ //print "-- key=".$key." - ".$val['fullrelativename']." vs ".(($selecteddir != '/'?$selecteddir.'/':'').$file).'
';
+ 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 '- ';
+ 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 '
- ';
print "";
@@ -148,10 +167,10 @@ if( file_exists($fullpathselecteddir) )
// Nb of docs
print '
| ';
- print isset($val['cachenbofdoc'])?$val['cachenbofdoc']:' ';
+ print (isset($val['cachenbofdoc']) && $val['cachenbofdoc'] >= 0)?$val['cachenbofdoc']:' ';
print ' | ';
print '';
- if ($nbofsubdir && $nboffilesinsubdir) print '+'.$nboffilesinsubdir.' ';
+ if ($nbofsubdir > 0 && $nboffilesinsubdir > 0) print '+'.$nboffilesinsubdir.' ';
print ' | ';
// Edit link
@@ -163,16 +182,16 @@ if( file_exists($fullpathselecteddir) )
// Info
print '';
- $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=''.$langs->trans("ECMSection").': '.$val['label'].' ';
$htmltooltip=''.$langs->trans("Type").': '.$langs->trans("ECMSectionManual").' ';
$htmltooltip.=''.$langs->trans("ECMCreationUser").': '.$userstatic->getNomUrl(1).' ';
- $htmltooltip.=''.$langs->trans("ECMCreationDate").': '.dol_print_date($val['date_c'],"dayhour").' ';
+ $htmltooltip.=''.$langs->trans("ECMCreationDate").': '.(isset($val['date_c'])?dol_print_date($val['date_c'],"dayhour"):$langs->trans("NeedRefresh")).' ';
$htmltooltip.=''.$langs->trans("Description").': '.$val['description'].' ';
- $htmltooltip.=''.$langs->trans("ECMNbOfFilesInDir").': '.$val['cachenbofdoc'].' ';
- if ($nbofsubdir) $htmltooltip.=''.$langs->trans("ECMNbOfFilesInSubDir").': '.$nboffilesinsubdir;
- else $htmltooltip.=''.$langs->trans("ECMNbOfSubDir").': '.$nbofsubdir.' ';
+ $htmltooltip.=''.$langs->trans("ECMNbOfFilesInDir").': '.((isset($val['cachenbofdoc']) && $val['cachenbofdoc'] >= 0)?$val['cachenbofdoc']:$langs->trans("NeedRefresh")).' ';
+ if ($nboffilesinsubdir > 0) $htmltooltip.=''.$langs->trans("ECMNbOfFilesInSubDir").': '.$nboffilesinsubdir;
+ else $htmltooltip.=''.$langs->trans("ECMNbOfSubDir").': '.($nbofsubdir >= 0 ? $nbofsubdir : $langs->trans("NeedRefresh")).' ';
print $form->textwithpicto('',$htmltooltip,1,"info");
print " | ";
diff --git a/htdocs/core/lib/treeview.lib.php b/htdocs/core/lib/treeview.lib.php
index 0b72e156b40..06eda753b3d 100644
--- a/htdocs/core/lib/treeview.lib.php
+++ b/htdocs/core/lib/treeview.lib.php
@@ -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)
{
diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php
index 6a20cca9426..e0519073386 100644
--- a/htdocs/ecm/class/ecmdirectory.class.php
+++ b/htdocs/ecm/class/ecmdirectory.class.php
@@ -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)
{
diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php
index 6cefad2a4d4..17b00274582 100644
--- a/htdocs/ecm/index.php
+++ b/htdocs/ecm/index.php
@@ -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."
\n";
+ //print $ecmdirtmp->cachenbofdoc."
\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;
}
diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql
index 86f7a852f11..001c21dad2f 100755
--- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql
+++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql
@@ -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);
+