FIX #3726 Better support for PRODUCT_USE_OLD_PATH_FOR_PHOTO

This commit is contained in:
Laurent Destailleur 2015-11-02 17:56:00 +01:00
parent 3ba97627ff
commit f928062e2b
6 changed files with 45 additions and 27 deletions

View File

@ -820,7 +820,12 @@ class FormFile
if ($object->element == 'member') $relativepath=get_exdir($object->id,2,0,0,$object,'member').$relativepath; // TODO Call using a defined value for $relativepath
if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
}
// For backward compatiblity, we detect file is stored into an old path
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $file['level1name'] == 'photos')
{
$relativepath=preg_replace('/^.*\/produit\//','',$file['path']).'/';
}
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>';

View File

@ -3744,13 +3744,14 @@ function yn($yesno, $case=1, $color=0)
/**
* Return a path to have a directory according to object.
* Examples: '001' with level 3->"0/0/1/", '015' with level 3->"0/1/5/"
* Examples: 'ABC-1' with level 3 ->"0/0/1/", '015' with level 1->"5/"
* New usage: $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'modulepart')
* Old usage: '001' with level 3->"0/0/1/", '015' with level 3->"0/1/5/"
* Old usage: 'ABC-1' with level 3 ->"0/0/1/", '015' with level 1->"5/"
*
* @param string $num Id of object
* @param int $level Level of subdirs to return (1, 2 or 3 levels)
* @param int $alpha 0=Keep number only to forge path, 1=Use alpha part afer the - (By default, use 0).
* @param int $withoutslash 0=With slash at end, 1=without slash at end (except if '/', we return '')
* @param string $num Id of object (deprecated, $object will be used in future)
* @param int $level Level of subdirs to return (1, 2 or 3 levels). (deprecated, global option will be used in future)
* @param int $alpha 0=Keep number only to forge path, 1=Use alpha part afer the - (By default, use 0). (deprecated, global option will be used in future)
* @param int $withoutslash 0=With slash at end (except if '/', we return ''), 1=without slash at end
* @param Object $object Object
* @param string $modulepart Type of object ('invoice_supplier, 'donation', 'invoice', ...')
* @return string Dir to use ending. Example '' or '1/' or '1/2/'
@ -3761,10 +3762,7 @@ function get_exdir($num,$level,$alpha,$withoutslash,$object,$modulepart)
$path = '';
// TODO if object is null, load it from id and modulepart.
if (! empty($level) && in_array($modulepart, array('cheque','user','category','holiday','shipment', 'member','don','donation','supplier_invoice','invoice_supplier','product')))
if (! empty($level) && in_array($modulepart, array('cheque','user','category','holiday','shipment', 'member','don','donation','supplier_invoice','invoice_supplier')))
{
// This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided
if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num);
@ -3778,7 +3776,7 @@ function get_exdir($num,$level,$alpha,$withoutslash,$object,$modulepart)
{
// TODO
// We will introduce here a common way of forging path for document storage
// Here, $num=id, ref and modulepart are required.
// Here, object->id, object->ref and object->modulepart are required.
}

View File

@ -181,11 +181,11 @@ class pdf_azur extends ModelePDFPropales
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
{
$pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
$pdir[1] = dol_sanitizeFileName($objphoto->ref).'/';
$pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
}
else
{
$pdir[0] = dol_sanitizeFileName($objphoto->ref).'/'; // default
$pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/'; // default
$pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/"; // alternative
}

View File

@ -18,6 +18,7 @@
*/
// Variable $upload_dir must be defined when entering here
// Variable $upload_dirold may also exists.
// Send file/link
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
@ -54,16 +55,18 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
$urlfile=basename($urlfile);
$file = $upload_dir . "/" . $urlfile;
if (! empty($upload_dirold)) $fileold = $upload_dirold . "/" . $urlfile;
}
$linkid = GETPOST('linkid', 'int'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
if ($urlfile)
{
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
$ret = dol_delete_file($file, 0, 0, 0, $object);
if (! empty($fileold)) dol_delete_file($fileold, 0, 0, 0, $object); // Delete file using old path
// Si elle existe, on efface la vignette
if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i',$file,$regs))
{

View File

@ -3411,7 +3411,7 @@ class Product extends CommonObject
$dir = $sdir;
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos";
else $dir .= '/'.dol_sanitizeFileName($this->ref);
else $dir .= '/'.get_exdir(0,0,0,0,$this,'product').dol_sanitizeFileName($this->ref);
dol_mkdir($dir);
@ -3449,7 +3449,7 @@ class Product extends CommonObject
$dir = $sdir;
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
else $dir .= '/'.dol_sanitizeFileName($this->ref).'/';
else $dir .= '/'.get_exdir(0,0,0,0,$this,'product').dol_sanitizeFileName($this->ref).'/';
$nbphoto=0;
@ -3500,8 +3500,8 @@ class Product extends CommonObject
}
else
{
$dir .= $this->ref.'/';
$pdir .= $this->ref.'/';
$dir .= get_exdir(0,0,0,0,$this,'product').$this->ref.'/';
$pdir .= get_exdir(0,0,0,0,$this,'product').$this->ref.'/';
}
$dirthumb = $dir.'thumbs/';

View File

@ -70,10 +70,14 @@ if ($id > 0 || ! empty($ref))
{
$result = $object->fetch($id, $ref);
if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/';
elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/';
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $upload_dir.= get_exdir($object->id,2,0,0,$object,'product').$object->id."/photos";
else $upload_dir.= dol_sanitizeFileName($object->ref);
if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'product').dol_sanitizeFileName($object->ref);
elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'product').dol_sanitizeFileName($object->ref);
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs
{
if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos";
else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos";
}
}
$modulepart='produit';
@ -177,12 +181,19 @@ if ($object->id)
// Construit liste des fichiers
$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs
{
$filearrayold=dol_dir_list($upload_dirold,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$filearray=array_merge($filearray, $filearrayold);
}
$totalsize=0;
foreach($filearray as $key => $file)
{
$totalsize+=$file['size'];
}
print '<table class="border" width="100%">';
@ -235,7 +246,8 @@ if ($object->id)
$filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', 'name', SORT_ASC, 1);
// For each file build select list with PDF extention
if (count($filearray) > 0) {
if (count($filearray) > 0)
{
print '<br>';
// Actual file to merge is :
if (count($filetomerge->lines) > 0) {