diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index b13224782c9..8ba38b81edb 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6861,10 +6861,10 @@ class Form $dir=$conf->user->dir_output; if (! empty($object->photo)) { - if ((string) $imagesize == 'mini') $file=get_exdir($id, 2, 0, 0, $object, 'user').getImageFileNameForSize($object->photo, '_mini'); - else if ((string) $imagesize == 'small') $file=get_exdir($id, 2, 0, 0, $object, 'user').getImageFileNameForSize($object->photo, '_small'); - else $file=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo; - $originalfile=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo; + if ((string) $imagesize == 'mini') $file=get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_mini'); + else if ((string) $imagesize == 'small') $file=get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_small'); + else $file=get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo; + $originalfile=get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo; } if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 1011dcef9cb..08fa147fb0d 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -446,7 +446,7 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09 $beforeversionarray=explode('.','9.0.9'); if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) { - //migrate_rename_directories($db,$langs,$conf,'/contracts','/contract'); + migrate_user_photospath(); } } @@ -4826,7 +4826,76 @@ function migrate_reload_menu($db,$langs,$conf,$versionto) } } +/** + * Migrate file from old path to new one for users + * + * @return void + */ +function migrate_user_photospath() +{ + global $conf, $db, $langs; + + print ''; + print ''.$langs->trans('MigrationUserPhotoPath')."
\n"; + + include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; + $fuser = new User($db); + + $sql = "SELECT rowid as uid from ".MAIN_DB_PREFIX."user"; // Get list of all users + $resql = $db->query($sql); + if ($resql) + { + while ($obj = $db->fetch_object($resql)) + { + $fuser->fetch($obj->uid); + //echo '
'.$fuser->id.' -> '.$fuser->entity; + $entity = (!empty($fuser->entity)) ? $fuser->entity : 1; + $dir = $conf->user->multidir_output[$entity]; + $origin = $dir .'/'. get_exdir($fuser->id,2,0,0,$fuser,'user'); + $destin = $dir.'/'.$fuser->id; + + $error = 0; + + $origin_osencoded=dol_osencode($origin); + $destin_osencoded=dol_osencode($destin); + dol_mkdir($destin); + //echo '
'.$origin.' -> '.$destin; + if (dol_is_dir($origin)) + { + $handle=opendir($origin_osencoded); + if (is_resource($handle)) + { + while (($file = readdir($handle)) !== false) + { + if ($file != '.' && $file != '..' && is_dir($origin_osencoded.'/'.$file)) + { + $thumbs = opendir($origin_osencoded.'/'.$file); + if (is_resource($thumbs)) + { + dol_mkdir($destin.'/'.$file); + while (($thumb = readdir($thumbs)) !== false) + { + dol_move($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb); + } + // dol_delete_dir($origin.'/'.$file); + } + } + else + { + if (dol_is_file($origin.'/'.$file) ) + { + dol_move($origin.'/'.$file, $destin.'/'.$file); + } + } + } + } + } + } + } + + print ''; +} /* A faire egalement: Modif statut paye et fk_facture des factures payes completement diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index bcca348c861..c92d83988ff 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -200,6 +200,7 @@ MigrationRemiseEntity=Update entity field value of llx_societe_remise MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except MigrationUserRightsEntity=Update entity field value of llx_user_rights MigrationUserGroupRightsEntity=Update entity field value of llx_usergroup_rights +MigrationUserPhotoPath=Migration of photo paths for users MigrationReloadModule=Reload module %s MigrationResetBlockedLog=Reset module BlockedLog for v7 algorithm ShowNotAvailableOptions=Show unavailable options diff --git a/htdocs/user/card.php b/htdocs/user/card.php index fd6234268b2..b4aed9f7844 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -449,14 +449,14 @@ if (empty($reshook)) { if (!$error && !count($object->errors)) { if (GETPOST('deletephoto') && $object->photo) { - $fileimg = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/'.$object->photo; - $dirthumbs = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/thumbs'; + $fileimg = $conf->user->dir_output.'/'.get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/logos/'.$object->photo; + $dirthumbs = $conf->user->dir_output.'/'.get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/logos/thumbs'; dol_delete_file($fileimg); dol_delete_dir_recursive($dirthumbs); } if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) { - $dir = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user'); + $dir = $conf->user->dir_output.'/'.get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id; dol_mkdir($dir);