diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 153214c76e1..8dabb714504 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -704,7 +704,7 @@ class FormFile $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']); //var_dump($file); - $id=0; $ref=''; $object_instance->id=0; $object_instance->ref=''; $label=''; + $id=0; $ref=''; $label=''; // To show ref or specific information according to view to show (defined by $module) if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } @@ -715,24 +715,27 @@ class FormFile if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1]; } - $result=0; - if (is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) $object_instance=$this->cache_objects[$modulepart.'_'.$id.'_'.$ref]; + if (! $id && ! $ref) continue; + + $found=0; + if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) + { + $found=1; + } else { //print 'Fetch '.$idorref.'
'; $result=$object_instance->fetch($id,$ref); - if ($result > 0) $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]=dol_clone($object_instance); // Save object into a cache - if ($result == 0) // Not found but no error - { - // Clean of orphelins directories are done into repair.php - //dol_delete_file($file['fullname'],1,1,1); - } + if ($result > 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]=dol_clone($object_instance); } // Save object into a cache + if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; } } + if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue; // We do not show orphelins files + $var=!$var; print ''; print ''; - if ($object_instance->id) print $object_instance->getNomUrl(1,'document'); + if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document'); else print $langs->trans("ObjectDeleted",($id?$id:$ref)); print ''; print ''; diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 2051217db9b..161b1f246c5 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -209,7 +209,7 @@ if (GETPOST('purge')) if ($modulepart == 'contract') $upload_dir = $conf->contrat->dir_output; if ($modulepart == 'tax') $upload_dir = $conf->tax->dir_output; - if (empty($upload_dir)) break; + if (empty($upload_dir)) continue; print 'Clean orphelins files into files '.$upload_dir.'';