Fix refresh cache value of nb of files into a dir into ECM module

This commit is contained in:
Laurent Destailleur 2016-07-30 15:51:27 +02:00
parent a6147ee73b
commit 7678940e50
5 changed files with 26 additions and 5 deletions

View File

@ -169,6 +169,10 @@ then
cp -pr $mydir/documents_demo/* "$documentdir/" cp -pr $mydir/documents_demo/* "$documentdir/"
echo cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/" echo cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/"
cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/" cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/"
mkdir -p "$documentdir/ecm/Administrative documents"
mkdir -p "$documentdir/ecm/Images"
echo cp -pr $mydir/../../doc/images/* "$documentdir/ecm/Images"
cp -pr $mydir/../../doc/images/* "$documentdir/ecm/Images"
else else
echo Detection of documents directory failed so demo files were not copied. echo Detection of documents directory failed so demo files were not copied.
fi fi

View File

@ -239,14 +239,15 @@ class EcmDirectory // extends CommonObject
/** /**
* Update cache of nb of documents into database * Update cache of nb of documents into database
* *
* @param string $sign '+' or '-' * @param string $value '+' or '-' or new number
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function changeNbOfFiles($sign) function changeNbOfFiles($value)
{ {
// Update request // Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET";
$sql.= " cachenbofdoc = cachenbofdoc ".$sign." 1"; if (preg_match('/[0-9]+/', $value)) $sql.= " cachenbofdoc = ".(int) $value;
else $sql.= " cachenbofdoc = cachenbofdoc ".$value." 1";
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::changeNbOfFiles", LOG_DEBUG); dol_syslog(get_class($this)."::changeNbOfFiles", LOG_DEBUG);
@ -256,6 +257,12 @@ class EcmDirectory // extends CommonObject
$this->error="Error ".$this->db->lasterror(); $this->error="Error ".$this->db->lasterror();
return -1; return -1;
} }
else
{
if (preg_match('/[0-9]+/', $value)) $this->cachenbofdoc = (int) $value;
else if ($value == '+') $this->cachenbofdoc++;
else if ($value == '-') $this->cachenbofdoc--;
}
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -272,7 +272,13 @@ print '<tr><td>'.$langs->trans("ECMDirectoryForFiles").'</td><td>';
print '/ecm/'.$relativepath; print '/ecm/'.$relativepath;
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans("ECMNbOfDocs").'</td><td>'; print '<tr><td>'.$langs->trans("ECMNbOfDocs").'</td><td>';
print count($filearray); $nbofiles=count($filearray);
print $nbofiles;
// Test if nb is same than in cache
if ($nbofiles != $ecmdir->cachenbofdoc)
{
$ecmdir->changeNbOfFiles((string) $nbofiles);
}
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'; print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>';
print dol_print_size($totalsize); print dol_print_size($totalsize);

View File

@ -201,8 +201,11 @@ if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
} }
// Refresh directory view // Refresh directory view
// This refresh list of dirs, not list of files (for preformance reason). List of files is refresh only if dir was not synchronized.
// To refresh content of dir with cache, just open the dir in edit mode.
if ($action == 'refreshmanual') if ($action == 'refreshmanual')
{ {
$ecmdirtmp = new EcmDirectory($db); $ecmdirtmp = new EcmDirectory($db);
// This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate // This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate

View File

@ -50,6 +50,7 @@ $(document).ready(function() {
); );
$('#refreshbutton').click( function() { $('#refreshbutton').click( function() {
console.log("Click on refreshbutton");
$.pleaseBePatient("<?php echo $langs->trans('PleaseBePatient'); ?>"); $.pleaseBePatient("<?php echo $langs->trans('PleaseBePatient'); ?>");
$.get( "<?php echo DOL_URL_ROOT . '/ecm/ajax/ecmdatabase.php'; ?>", { $.get( "<?php echo DOL_URL_ROOT . '/ecm/ajax/ecmdatabase.php'; ?>", {
action: "build", action: "build",