Fix: When database is not synchronized with dir, we clean database.
This commit is contained in:
parent
84e3457023
commit
eaa6d987b6
@ -51,7 +51,9 @@ if (isset($action) && ! empty($action))
|
|||||||
require DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php';
|
require DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php';
|
||||||
|
|
||||||
$ecmdirstatic = new EcmDirectory($db);
|
$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();
|
clearstatcache();
|
||||||
|
|
||||||
$diroutputslash=str_replace('\\', '/', $conf->$element->dir_output);
|
$diroutputslash=str_replace('\\', '/', $conf->$element->dir_output);
|
||||||
@ -129,7 +131,6 @@ if (isset($action) && ! empty($action))
|
|||||||
|
|
||||||
if ($fk_parent >= 0)
|
if ($fk_parent >= 0)
|
||||||
{
|
{
|
||||||
$ecmdirtmp=new EcmDirectory($db);
|
|
||||||
$ecmdirtmp->ref = 'NOTUSEDYET';
|
$ecmdirtmp->ref = 'NOTUSEDYET';
|
||||||
$ecmdirtmp->label = dol_basename($dirdesc['fullname']);
|
$ecmdirtmp->label = dol_basename($dirdesc['fullname']);
|
||||||
$ecmdirtmp->description = '';
|
$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']."<br>\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"
|
$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);
|
$db->query($sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 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
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function delete($user)
|
function delete($user, $mode='all')
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
|
||||||
$error=0;
|
$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();
|
$this->db->begin();
|
||||||
|
|
||||||
@ -348,8 +350,11 @@ class EcmDirectory // extends CommonObject
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $conf->ecm->dir_output . "/" . $relativepath;
|
if ($mode != 'databaseonly')
|
||||||
$result=@dol_delete_dir($file);
|
{
|
||||||
|
$file = $conf->ecm->dir_output . "/" . $relativepath;
|
||||||
|
$result=@dol_delete_dir($file);
|
||||||
|
}
|
||||||
|
|
||||||
if ($result || ! @is_dir(dol_osencode($file)))
|
if ($result || ! @is_dir(dol_osencode($file)))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -201,7 +201,10 @@ if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
|
|||||||
// Refresh directory view
|
// Refresh directory view
|
||||||
if ($action == 'refreshmanual')
|
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=str_replace('\\','/',$conf->ecm->dir_output);
|
||||||
$diroutputslash.='/';
|
$diroutputslash.='/';
|
||||||
@ -264,7 +267,7 @@ if ($action == 'refreshmanual')
|
|||||||
//break; // We found parent, we can stop the while loop
|
//break; // We found parent, we can stop the while loop
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog("No");
|
dol_syslog("No");
|
||||||
//print "No<br>\n";
|
//print "No<br>\n";
|
||||||
}
|
}
|
||||||
@ -277,7 +280,6 @@ if ($action == 'refreshmanual')
|
|||||||
|
|
||||||
if ($fk_parent >= 0)
|
if ($fk_parent >= 0)
|
||||||
{
|
{
|
||||||
$ecmdirtmp=new EcmDirectory($db);
|
|
||||||
$ecmdirtmp->ref = 'NOTUSEDYET';
|
$ecmdirtmp->ref = 'NOTUSEDYET';
|
||||||
$ecmdirtmp->label = dol_basename($dirdesc['fullname']);
|
$ecmdirtmp->label = dol_basename($dirdesc['fullname']);
|
||||||
$ecmdirtmp->description = '';
|
$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']."<br>\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"
|
$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);
|
dol_syslog("sql = ".$sql);
|
||||||
$db->query($sql);
|
$db->query($sql);
|
||||||
|
|||||||
@ -39,7 +39,15 @@ $(document).ready( function() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$('#refreshbutton').click( function() {
|
$('#refreshbutton').click( function() {
|
||||||
ecmBuildDatabase();
|
$.pleaseBePatient("<?php echo $langs->trans('PleaseBePatient'); ?>");
|
||||||
|
$.getJSON( "<?php echo DOL_URL_ROOT . '/ecm/ajax/ecmdatabase.php'; ?>", {
|
||||||
|
action: "build",
|
||||||
|
element: "ecm"
|
||||||
|
},
|
||||||
|
function(response) {
|
||||||
|
$.unblockUI();
|
||||||
|
location.href="<?php echo $_SERVER['PHP_SELF']; ?>";
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -67,16 +75,5 @@ function loadandshowpreview(filedirname,section)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ecmBuildDatabase = function() {
|
|
||||||
$.pleaseBePatient("<?php echo $langs->trans('PleaseBePatient'); ?>");
|
|
||||||
$.getJSON( "<?php echo DOL_URL_ROOT . '/ecm/ajax/ecmdatabase.php'; ?>", {
|
|
||||||
action: "build",
|
|
||||||
element: "ecm"
|
|
||||||
},
|
|
||||||
function(response) {
|
|
||||||
$.unblockUI();
|
|
||||||
location.href="<?php echo $_SERVER['PHP_SELF']; ?>";
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
<!-- END PHP TEMPLATE FOR JQUERY -->
|
<!-- END PHP TEMPLATE FOR JQUERY -->
|
||||||
Loading…
Reference in New Issue
Block a user