Debug function to show list of files in ECM module

This commit is contained in:
Laurent Destailleur 2020-11-11 22:47:06 +01:00
parent 03e60bf084
commit 767f07d02e
2 changed files with 58 additions and 19 deletions

View File

@ -1035,10 +1035,9 @@ class FormFile
public function list_of_documents($filearray, $object, $modulepart, $param = '', $forcedownload = 0, $relativepath = '', $permonobject = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $title = '', $url = '', $showrelpart = 0, $permtoeditline = -1, $upload_dir = '', $sortfield = '', $sortorder = 'ASC', $disablemove = 1, $addfilterfields = 0, $disablecrop = -1)
{
// phpcs:enable
global $user, $conf, $langs, $hookmanager;
global $user, $conf, $langs, $hookmanager, $form;
global $sortfield, $sortorder, $maxheightmini;
global $dolibarr_main_url_root;
global $form;
if ($disablecrop == -1)
{
@ -1407,9 +1406,9 @@ class FormFile
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Show list of documents in a directory
* Show list of documents in a directory of ECM module.
*
* @param string $upload_dir Directory that was scanned
* @param string $upload_dir Directory that was scanned. This directory will contains files into subdirs REF/files
* @param array $filearray Array of files loaded by dol_dir_list function before calling this function
* @param string $modulepart Value for modulepart used by download wrapper
* @param string $param Parameters on sort links
@ -1427,9 +1426,10 @@ class FormFile
public function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permissiontodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $url = '', $addfilterfields = 0)
{
// phpcs:enable
global $user, $conf, $langs, $form;
global $user, $conf, $langs, $hookmanager, $form;
global $sortfield, $sortorder;
global $search_doc_ref;
global $dolibarr_main_url_root;
dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
@ -1547,6 +1547,23 @@ class FormFile
$object_instance = new Mo($this->db);
}
//var_dump($filearray);
// Get list of files stored into database for same relative directory
$relativepathfromroot = preg_replace('/'.preg_quote(DOL_DATA_ROOT.'/', '/').'/', '', $upload_dir);
if ($relativepathfromroot)
{
completeFileArrayWithDatabaseInfo($filearray, $relativepathfromroot.'/%');
//var_dump($sortfield.' - '.$sortorder);
if ($sortfield && $sortorder) // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
{
$filearray = dol_sort_array($filearray, $sortfield, $sortorder);
}
}
//var_dump($filearray);
foreach ($filearray as $key => $file)
{
if (!is_dir($file['name'])
@ -1558,7 +1575,7 @@ class FormFile
// Define relative path used to store the file
$relativefile = preg_replace('/'.preg_quote($upload_dir.'/', '/').'/', '', $file['fullname']);
$id = 0; $ref = ''; $label = '';
$id = 0; $ref = '';
// To show ref or specific information according to view to show (defined by $module)
$reg = array();
@ -1590,7 +1607,7 @@ class FormFile
{
$found = 1;
} else {
//print 'Fetch '.$id." - ".$ref.'<br>';
//print 'Fetch '.$id." - ".$ref.' class='.get_class($object_instance).'<br>';
if ($id) {
$result = $object_instance->fetch($id);
@ -1619,13 +1636,12 @@ class FormFile
else print $langs->trans("ObjectDeleted", ($id ? $id : $ref));
//$modulesubdir=dol_sanitizeFileName($ref);
$modulesubdir = dirname($relativefile);
//$modulesubdir = dirname($relativefile);
//$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
$filedir = $file['path'];
//$filedir = $file['path'];
//$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
//print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
print '</td>';
// File
@ -1639,12 +1655,30 @@ class FormFile
print '</a>';
//print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
print $this->showPreview($file, $modulepart, $file['relativename']);
print "</td>\n";
print '<td class="right">'.dol_print_size($file['size'], 1, 1).'</td>';
print '<td class="center">'.dol_print_date($file['date'], "dayhour").'</td>';
print '<td class="right">';
if ($file['share']) {
// Define $urlwithroot
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
//print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
$forcedownload = 0;
$paramlink = '';
if (!empty($file['share'])) $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1';
$fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
print img_picto($langs->trans("FileSharedViaALink"), 'globe').' ';
print '<input type="text" class="quatrevingtpercent width100" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
}
//if (! empty($useinecm) && $useinecm != 6) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
//if ($forcedownload) print '&attachment=1';
//print '&file='.urlencode($relativefile).'">';

View File

@ -228,8 +228,12 @@ function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $s
$sql .= " date_c, tms as date_m, fk_user_c, fk_user_m, acl, position, share";
if ($mode) $sql .= ", description";
$sql .= " FROM ".MAIN_DB_PREFIX."ecm_files";
$sql .= " WHERE filepath = '".$db->escape($path)."'";
$sql .= " AND entity = ".$conf->entity;
$sql .= " WHERE entity = ".$conf->entity;
if (preg_match('/%$/', $path)) {
$sql .= " AND filepath LIKE '".$db->escape($path)."'";
} else {
$sql .= " AND filepath = '".$db->escape($path)."'";
}
$resql = $db->query($sql);
if ($resql)
@ -242,6 +246,7 @@ function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $s
$obj = $db->fetch_object($resql);
if ($obj)
{
$reg = array();
preg_match('/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename, $reg);
$level1name = (isset($reg[1]) ? $reg[1] : '');
$file_list[] = array(
@ -289,7 +294,7 @@ function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $s
* Complete $filearray with data from database.
* This will call doldir_list_indatabase to complate filearray.
*
* @param array $filearray Array of files get using dol_dir_list
* @param array $filearray Array of files obtained using dol_dir_list
* @param string $relativedir Relative dir from DOL_DATA_ROOT
* @return void
*/
@ -315,19 +320,19 @@ function completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
}
}
//var_dump($filearray);
//var_dump($filearrayindatabase);
/*var_dump($relativedir);
var_dump($filearray);
var_dump($filearrayindatabase);*/
// Complete filearray with properties found into $filearrayindatabase
foreach ($filearray as $key => $val)
{
$tmpfilename = preg_replace('/\.noexe$/', '', $filearray[$key]['name']);
$found = 0;
// Search if it exists into $filearrayindatabase
foreach ($filearrayindatabase as $key2 => $val2)
{
if ($filearrayindatabase[$key2]['name'] == $tmpfilename)
if (($filearrayindatabase[$key2]['path'] == $filearray[$key]['path']) && ($filearrayindatabase[$key2]['name'] == $tmpfilename))
{
$filearray[$key]['position_name'] = ($filearrayindatabase[$key2]['position'] ? $filearrayindatabase[$key2]['position'] : '0').'_'.$filearrayindatabase[$key2]['name'];
$filearray[$key]['position'] = $filearrayindatabase[$key2]['position'];
@ -348,6 +353,7 @@ function completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
$filearray[$key]['acl'] = '';
$rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filearray[$key]['fullname']);
if (!preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filename)) // If not a tmp file
{
dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it");
@ -379,8 +385,7 @@ function completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
}
}
}
/*var_dump($filearray);*/
//var_dump($filearray); var_dump($relativedir.' - tmpfilename='.$tmpfilename.' - found='.$found);
}