mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-08 10:38:15 +01:00
FIX member photo and thirdparty logo not deleted in documents directory (#36197)
* FIX member photo with web portal don't need login * FIX member photo not deleted * FIX pre-commit * FIX phan error and uniformize code * FIX pfffffff pre-commit * FIX uniformize code * FIX remove TODO * FIX change const name * FIX missing add in ECM during creation * FIX add user photo in ecm * FIX phan error
This commit is contained in:
@@ -371,11 +371,15 @@ if (empty($reshook)) {
|
||||
//$object->note = trim(GETPOST("comment", "restricthtml"));
|
||||
$object->morphy = GETPOST("morphy", 'alpha');
|
||||
|
||||
if (GETPOST('deletephoto', 'alpha')) {
|
||||
$object->photo = '';
|
||||
} elseif (!empty($_FILES['photo']['name'])) {
|
||||
$current_photo = '';
|
||||
if (!empty($_FILES['photo']['name'])) {
|
||||
$current_photo = $object->photo;
|
||||
$object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
|
||||
}
|
||||
if (GETPOST('deletephoto')) {
|
||||
$current_photo = $object->photo;
|
||||
$object->photo = '';
|
||||
}
|
||||
|
||||
// Get status and public property
|
||||
$object->statut = GETPOSTINT("statut");
|
||||
@@ -425,16 +429,21 @@ if (empty($reshook)) {
|
||||
// Logo/Photo save
|
||||
$dir = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos';
|
||||
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
|
||||
if (GETPOST('deletephoto') && $current_photo) {
|
||||
$fileimg = $dir.'/'.$current_photo;
|
||||
$dirthumbs = $dir.'/thumbs';
|
||||
dol_delete_file($fileimg);
|
||||
dol_delete_dir_recursive($dirthumbs);
|
||||
}
|
||||
if ($file_OK) {
|
||||
if (GETPOST('deletephoto')) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
$fileimg = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos/'.$object->photo;
|
||||
$dirthumbs = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos/thumbs';
|
||||
if (image_format_supported($_FILES['photo']['name']) > 0) {
|
||||
if ($current_photo != $object->photo) {
|
||||
$fileimg = $dir.'/'.$current_photo;
|
||||
$dirthumbs = $dir.'/thumbs';
|
||||
dol_delete_file($fileimg);
|
||||
dol_delete_dir_recursive($dirthumbs);
|
||||
}
|
||||
|
||||
if (image_format_supported($_FILES['photo']['name']) > 0) {
|
||||
dol_mkdir($dir);
|
||||
|
||||
if (@is_dir($dir)) {
|
||||
@@ -444,6 +453,15 @@ if (empty($reshook)) {
|
||||
} else {
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
|
||||
// Index file in database
|
||||
if (getDolGlobalString('MEMBER_PHOTO_ALLOW_EXTERNAL_DOWNLOAD')) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
|
||||
deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', $object);
|
||||
// now we index the uploaded logo file
|
||||
addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1, $object);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1104,11 +1104,11 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep
|
||||
* @param int<0,1> $testvirus Do an antivirus test. Move is canceled if a virus is found.
|
||||
* @param int<0,1> $indexdatabase Index new file into database.
|
||||
* @param array<string,mixed> $moreinfo Array with more information to set in index table
|
||||
* @param int $entity Entity
|
||||
* @param int|null $entity Entity (it's null by default to avoid problem with entity = 0)
|
||||
* @return boolean True if OK, false if KO
|
||||
* @see dol_move_uploaded_file()
|
||||
*/
|
||||
function dol_move($srcfile, $destfile, $newmask = '0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array(), $entity = 0)
|
||||
function dol_move($srcfile, $destfile, $newmask = '0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array(), $entity = null)
|
||||
{
|
||||
global $user, $db;
|
||||
$result = false;
|
||||
@@ -1671,7 +1671,8 @@ function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0,
|
||||
dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
|
||||
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
|
||||
$ecmfile = new EcmFiles($db);
|
||||
$result = $ecmfile->fetch(0, '', $rel_filetodelete, '', '', '', 0, $object->entity ?? 0);
|
||||
$entity = (isset($object->entity) ? $object->entity : null);
|
||||
$result = $ecmfile->fetch(0, '', $rel_filetodelete, '', '', '', 0, $entity);
|
||||
if ($result >= 0 && $ecmfile->id > 0) {
|
||||
$result = $ecmfile->delete($user);
|
||||
}
|
||||
|
||||
@@ -410,10 +410,10 @@ class EcmFiles extends CommonObject
|
||||
* @param string $hashforshare Hash of file sharing, or 'shared'
|
||||
* @param string $src_object_type src_object_type to search (value of object->table_element)
|
||||
* @param int $src_object_id src_object_id to search
|
||||
* @param int $entity entity
|
||||
* @param int|null $entity entity (it's null by default to avoid problem with entity = 0)
|
||||
* @return int Return integer <0 if KO, 0 if not found, >0 if OK
|
||||
*/
|
||||
public function fetch($id, $ref = '', $relativepath = '', $hashoffile = '', $hashforshare = '', $src_object_type = '', $src_object_id = 0, $entity = 0)
|
||||
public function fetch($id, $ref = '', $relativepath = '', $hashoffile = '', $hashforshare = '', $src_object_type = '', $src_object_id = 0, $entity = null)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@@ -461,7 +461,7 @@ class EcmFiles extends CommonObject
|
||||
if ($filename != '*') {
|
||||
$sql .= " AND t.filename = '".$this->db->escape($filename)."'";
|
||||
}
|
||||
if (! empty($entity)) {
|
||||
if (isset($entity)) {
|
||||
$sql .= " AND t.entity = " . (int) $entity;
|
||||
} else {
|
||||
$sql .= " AND t.entity = " . $conf->entity; // unique key include the entity so each company has its own index
|
||||
@@ -470,7 +470,7 @@ class EcmFiles extends CommonObject
|
||||
}
|
||||
if (!empty($ref)) { // hash of file path
|
||||
$sql .= " AND t.ref = '".$this->db->escape($ref)."'";
|
||||
if (! empty($entity)) {
|
||||
if (isset($entity)) {
|
||||
$sql .= " AND t.entity = " . (int) $entity;
|
||||
} else {
|
||||
$sql .= " AND t.entity = " . $conf->entity; // unique key include the entity so each company has its own index
|
||||
@@ -479,7 +479,7 @@ class EcmFiles extends CommonObject
|
||||
}
|
||||
if (!empty($hashoffile)) { // hash of content
|
||||
$sql .= " AND t.label = '".$this->db->escape($hashoffile)."'";
|
||||
if (! empty($entity)) {
|
||||
if (isset($entity)) {
|
||||
$sql .= " AND t.entity = " . (int) $entity;
|
||||
} else {
|
||||
$sql .= " AND t.entity = " . $conf->entity; // unique key include the entity so each company has its own index
|
||||
@@ -497,7 +497,7 @@ class EcmFiles extends CommonObject
|
||||
}
|
||||
if ($src_object_type && $src_object_id) {
|
||||
$sql .= " AND t.src_object_type = '".$this->db->escape($src_object_type)."' AND t.src_object_id = ".((int) $src_object_id);
|
||||
if (! empty($entity)) {
|
||||
if (isset($entity)) {
|
||||
$sql .= " AND t.entity = " . (int) $entity;
|
||||
} else {
|
||||
$sql .= " AND t.entity = " . $conf->entity; // unique key include the entity so each company has its own index
|
||||
|
||||
@@ -602,6 +602,15 @@ if (empty($reshook)) {
|
||||
} else {
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
|
||||
// Index file in database
|
||||
if (getDolGlobalString('THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD')) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
|
||||
deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', $object);
|
||||
// now we index the uploaded logo file
|
||||
addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1, $object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -740,8 +749,8 @@ if (empty($reshook)) {
|
||||
// Logo/Photo save
|
||||
$dir = $conf->societe->multidir_output[$object->entity ?? $conf->entity]."/".$object->id."/logos";
|
||||
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
|
||||
if (GETPOST('deletephoto') && $object->logo) {
|
||||
$fileimg = $dir.'/'.$object->logo;
|
||||
if (GETPOST('deletephoto') && $current_logo) {
|
||||
$fileimg = $dir.'/'.$current_logo;
|
||||
$dirthumbs = $dir.'/thumbs';
|
||||
dol_delete_file($fileimg);
|
||||
dol_delete_dir_recursive($dirthumbs);
|
||||
@@ -773,7 +782,7 @@ if (empty($reshook)) {
|
||||
// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
|
||||
deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', $object);
|
||||
// now we index the uploaded logo file
|
||||
addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
|
||||
addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1, $object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,6 +645,15 @@ if (empty($reshook)) {
|
||||
} else {
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
|
||||
// Index file in database
|
||||
if (getDolGlobalString('USER_PHOTO_ALLOW_EXTERNAL_DOWNLOAD')) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
|
||||
deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', $object);
|
||||
// now we index the uploaded logo file
|
||||
addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1, $object);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
|
||||
Reference in New Issue
Block a user