Fix: When database is not synchronized with dir, we clean database.

This commit is contained in:
Laurent Destailleur 2013-12-01 17:32:05 +01:00
parent 84e3457023
commit eaa6d987b6
4 changed files with 55 additions and 23 deletions

View File

@ -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']."<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"
dol_syslog("sql = ".$sql);
$db->query($sql);
}
}

View File

@ -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)))
{

View File

@ -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<br>\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']."<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"
dol_syslog("sql = ".$sql);
$db->query($sql);

View File

@ -39,7 +39,15 @@ $(document).ready( 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>
<!-- END PHP TEMPLATE FOR JQUERY -->