diff --git a/htdocs/ecm/ajax/ecmdatabase.php b/htdocs/ecm/ajax/ecmdatabase.php
index cfdfb7fe26d..7a1a667d332 100644
--- a/htdocs/ecm/ajax/ecmdatabase.php
+++ b/htdocs/ecm/ajax/ecmdatabase.php
@@ -51,7 +51,9 @@ if (isset($action) && ! empty($action))
require DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php';
$ecmdirstatic = new EcmDirectory($db);
+ $ecmdirtmp = new EcmDirectory($db);
+ // This part of code is same than into file index.php for action refreshmanual TODO Remove duplicate
clearstatcache();
$diroutputslash=str_replace('\\', '/', $conf->$element->dir_output);
@@ -129,7 +131,6 @@ if (isset($action) && ! empty($action))
if ($fk_parent >= 0)
{
- $ecmdirtmp=new EcmDirectory($db);
$ecmdirtmp->ref = 'NOTUSEDYET';
$ecmdirtmp->label = dol_basename($dirdesc['fullname']);
$ecmdirtmp->description = '';
@@ -163,7 +164,21 @@ if (isset($action) && ! empty($action))
}
}
+ // Loop now on each sql tree to check if dir exists
+ foreach($sqltree as $dirdesc) // Loop on each sqltree to check dir is on disk
+ {
+ $dirtotest=$conf->$element->dir_output.'/'.$dirdesc['fullrelativename'];
+ if (! dol_is_dir($dirtotest))
+ {
+ $mesg.=$dirtotest." not found onto disk. We delete from database dir with id=".$dirdesc['id']."
\n";
+ $ecmdirtmp->id=$dirdesc['id'];
+ $ecmdirtmp->delete($user,'databaseonly');
+ //exit;
+ }
+ }
+
$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);
}
}
diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php
index 3c12fe066e9..ff914772b2f 100644
--- a/htdocs/ecm/class/ecmdirectory.class.php
+++ b/htdocs/ecm/class/ecmdirectory.class.php
@@ -143,7 +143,7 @@ class EcmDirectory // extends CommonObject
$dir=$conf->ecm->dir_output.'/'.$this->getRelativePath();
$result=dol_mkdir($dir);
if ($result < 0) { $error++; $this->error="ErrorFailedToCreateDir"; }
-
+
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
@@ -317,21 +317,23 @@ class EcmDirectory // extends CommonObject
/**
- * Delete object on database and on disk
+ * Delete object on database and/or on disk
*
* @param User $user User that delete
+ * @param int $mode 'all'=delete all, 'databaseonly'=only database entry, 'fileonly' (not implemented)
* @return int <0 if KO, >0 if OK
*/
- function delete($user)
+ function delete($user, $mode='all')
{
global $conf, $langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$error=0;
+ $result=0;
- $relativepath=$this->getRelativePath(1); // Ex: dir1/dir2/dir3
+ if ($mode != 'databaseonly') $relativepath=$this->getRelativePath(1); // Ex: dir1/dir2/dir3
- dol_syslog(get_class($this)."::delete remove directory ".$relativepath);
+ dol_syslog(get_class($this)."::delete remove directory id=".$this->id." mode=".$mode.(($mode == 'databaseonly')?'':' relativepath='.$relativepath));
$this->db->begin();
@@ -348,8 +350,11 @@ class EcmDirectory // extends CommonObject
return -2;
}
- $file = $conf->ecm->dir_output . "/" . $relativepath;
- $result=@dol_delete_dir($file);
+ if ($mode != 'databaseonly')
+ {
+ $file = $conf->ecm->dir_output . "/" . $relativepath;
+ $result=@dol_delete_dir($file);
+ }
if ($result || ! @is_dir(dol_osencode($file)))
{
diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php
index bb8844eafc6..0939dc9a77d 100644
--- a/htdocs/ecm/index.php
+++ b/htdocs/ecm/index.php
@@ -201,7 +201,10 @@ if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
// Refresh directory view
if ($action == 'refreshmanual')
{
- clearstatcache();
+ $ecmdirtmp = new EcmDirectory($db);
+
+ // This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate
+ clearstatcache();
$diroutputslash=str_replace('\\','/',$conf->ecm->dir_output);
$diroutputslash.='/';
@@ -264,7 +267,7 @@ if ($action == 'refreshmanual')
//break; // We found parent, we can stop the while loop
}
else
- {
+ {
dol_syslog("No");
//print "No
\n";
}
@@ -277,7 +280,6 @@ if ($action == 'refreshmanual')
if ($fk_parent >= 0)
{
- $ecmdirtmp=new EcmDirectory($db);
$ecmdirtmp->ref = 'NOTUSEDYET';
$ecmdirtmp->label = dol_basename($dirdesc['fullname']);
$ecmdirtmp->description = '';
@@ -311,6 +313,19 @@ if ($action == 'refreshmanual')
}
}
+ // Loop now on each sql tree to check if dir exists
+ foreach($sqltree as $dirdesc) // Loop on each sqltree to check dir is on disk
+ {
+ $dirtotest=$conf->ecm->dir_output.'/'.$dirdesc['fullrelativename'];
+ if (! dol_is_dir($dirtotest))
+ {
+ $mesg.=$dirtotest." not found onto disk. We delete from database dir with id=".$dirdesc['id']."
\n";
+ $ecmdirtmp->id=$dirdesc['id'];
+ $ecmdirtmp->delete($user,'databaseonly');
+ //exit;
+ }
+ }
+
$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);
diff --git a/htdocs/ecm/tpl/builddatabase.tpl.php b/htdocs/ecm/tpl/builddatabase.tpl.php
index 7f997ed6209..38137fa4997 100644
--- a/htdocs/ecm/tpl/builddatabase.tpl.php
+++ b/htdocs/ecm/tpl/builddatabase.tpl.php
@@ -39,7 +39,15 @@ $(document).ready( function() {
);
$('#refreshbutton').click( function() {
- ecmBuildDatabase();
+ $.pleaseBePatient("trans('PleaseBePatient'); ?>");
+ $.getJSON( "", {
+ action: "build",
+ element: "ecm"
+ },
+ function(response) {
+ $.unblockUI();
+ location.href="";
+ });
});
});
@@ -67,16 +75,5 @@ function loadandshowpreview(filedirname,section)
});
}
-ecmBuildDatabase = function() {
- $.pleaseBePatient("trans('PleaseBePatient'); ?>");
- $.getJSON( "", {
- action: "build",
- element: "ecm"
- },
- function(response) {
- $.unblockUI();
- location.href="";
- });
-};
\ No newline at end of file