From eeaeefe20c20935e39480555ccd033d2a84fe438 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 11 Sep 2019 15:46:37 +0200 Subject: [PATCH] FIX Add repair.php option 'restore' to restore user picture after v10 --- htdocs/install/repair.php | 204 +++++++++++++++++++++++++++++--------- 1 file changed, 159 insertions(+), 45 deletions(-) diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 472e77e1974..d34d43384d0 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -69,6 +69,7 @@ print '

'.$langs->trans("Repair").'

'; print 'Option standard (\'test\' or \'confirmed\') is '.(GETPOST('standard', 'alpha')?GETPOST('standard', 'alpha'):'undefined').'
'."\n"; print 'Option restore_thirdparties_logos (\'test\' or \'confirmed\') is '.(GETPOST('restore_thirdparties_logos', 'alpha')?GETPOST('restore_thirdparties_logos', 'alpha'):'undefined').'
'."\n"; +print 'Option restore_user_pictures (\'test\' or \'confirmed\') is '.(GETPOST('restore_user_pictures', 'alpha')?GETPOST('restore_user_pictures', 'alpha'):'undefined').'
'."\n"; print 'Option clean_linked_elements (\'test\' or \'confirmed\') is '.(GETPOST('clean_linked_elements', 'alpha')?GETPOST('clean_linked_elements', 'alpha'):'undefined').'
'."\n"; print 'Option clean_menus (\'test\' or \'confirmed\') is '.(GETPOST('clean_menus', 'alpha')?GETPOST('clean_menus', 'alpha'):'undefined').'
'."\n"; print 'Option clean_orphelin_dir (\'test\' or \'confirmed\') is '.(GETPOST('clean_orphelin_dir', 'alpha')?GETPOST('clean_orphelin_dir', 'alpha'):'undefined').'
'."\n"; @@ -492,70 +493,183 @@ if ($ok && GETPOST('restore_thirdparties_logos')) $ext=''; print '
*** Restore thirdparties logo
'; - //foreach($exts as $ext) - //{ - $sql="SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX."societe as s ORDER BY s.nom"; - $resql=$db->query($sql); - if ($resql) + + $sql="SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX."societe as s ORDER BY s.nom"; + $resql=$db->query($sql); + if ($resql) + { + $num=$db->num_rows($resql); + $i=0; + + while($i < $num) { - $num=$db->num_rows($resql); - $i=0; + $obj=$db->fetch_object($resql); - while($i < $num) + /* + $name=preg_replace('/é/','',$obj->name); + $name=preg_replace('/ /','_',$name); + $name=preg_replace('/\'/','',$name); + */ + + $tmp=explode('.', $obj->logo); + $name=$tmp[0]; + if (isset($tmp[1])) $ext='.'.$tmp[1]; + + if (! empty($name)) { - $obj=$db->fetch_object($resql); - - /* - $name=preg_replace('/é/','',$obj->name); - $name=preg_replace('/ /','_',$name); - $name=preg_replace('/\'/','',$name); - */ - - $tmp=explode('.', $obj->logo); - $name=$tmp[0]; - if (isset($tmp[1])) $ext='.'.$tmp[1]; - - if (! empty($name)) + $filetotest=$dolibarr_main_data_root.'/societe/logos/'.$name.$ext; + $filetotestsmall=$dolibarr_main_data_root.'/societe/logos/thumbs/'.$name.'_small'.$ext; + $exists=dol_is_file($filetotest); + print 'Check thirdparty '.$obj->rowid.' name='.$obj->name.' logo='.$obj->logo.' file '.$filetotest." exists=".$exists."
\n"; + if ($exists) { - $filetotest=$dolibarr_main_data_root.'/societe/logos/'.$name.$ext; - $filetotestsmall=$dolibarr_main_data_root.'/societe/logos/thumbs/'.$name.$ext; - $exists=dol_is_file($filetotest); - print 'Check thirdparty '.$obj->rowid.' name='.$obj->name.' logo='.$obj->logo.' file '.$filetotest." exists=".$exists."
\n"; - if ($exists) + $filetarget=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/'.$name.$ext; + $filetargetsmall=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs/'.$name.'_small'.$ext; + $existt=dol_is_file($filetarget); + if (! $existt) { - $filetarget=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/'.$name.$ext; - $filetargetsmall=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs/'.$name.'_small'.$ext; - $existt=dol_is_file($filetarget); - if (! $existt) + if (GETPOST('restore_thirdparties_logos', 'alpha') == 'confirmed') { dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos'); - - print "       -> Copy file ".$filetotest." -> ".$filetarget."
\n"; - dol_copy($filetotest, $filetarget, '', 0); } - $existtt=dol_is_file($filetargetsmall); - if (! $existtt) + print "       -> Copy file ".$filetotest." -> ".$filetarget."
\n"; + if (GETPOST('restore_thirdparties_logos', 'alpha') == 'confirmed') + { + dol_copy($filetotest, $filetarget, '', 0); + } + } + + $existtt=dol_is_file($filetargetsmall); + if (! $existtt) + { + if (GETPOST('restore_thirdparties_logos', 'alpha') == 'confirmed') { dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs'); - - print "       -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."
\n"; + } + print "       -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."
\n"; + if (GETPOST('restore_thirdparties_logos', 'alpha') == 'confirmed') + { dol_copy($filetotestsmall, $filetargetsmall, '', 0); } } } - - $i++; } + + $i++; } - else - { - $ok=0; - dol_print_error($db); - } + } + else + { + $ok=0; + dol_print_error($db); + } + + print ''; +} + + + +// restore_user_pictures: Move pictures to correct new directory. +if ($ok && GETPOST('restore_user_pictures', 'alpha')) +{ + //$exts=array('gif','png','jpg'); + + $ext=''; + + print '
*** Restore user pictures
'; + + $sql="SELECT s.rowid, s.firstname, s.lastname, s.login, s.photo FROM ".MAIN_DB_PREFIX."user as s ORDER BY s.rowid"; + $resql=$db->query($sql); + if ($resql) + { + $num=$db->num_rows($resql); + $i=0; + + while($i < $num) + { + $obj=$db->fetch_object($resql); + + /* + $name=preg_replace('/é/','',$obj->name); + $name=preg_replace('/ /','_',$name); + $name=preg_replace('/\'/','',$name); + */ + + $tmp=explode('.', $obj->photo); + $name=$tmp[0]; + if (isset($tmp[1])) $ext='.'.$tmp[1]; + + if (! empty($name)) + { + $filetotest=$dolibarr_main_data_root.'/users/'.substr(sprintf('%08d', $obj->rowid), -1, 1).'/'.substr(sprintf('%08d', $obj->rowid), -2, 1).'/'.$name.$ext; + $filetotestsmall=$dolibarr_main_data_root.'/users/'.substr(sprintf('%08d', $obj->rowid), -1, 1).'/'.substr(sprintf('%08d', $obj->rowid), -2, 1).'/thumbs/'.$name.'_small'.$ext; + $filetotestmini=$dolibarr_main_data_root.'/users/'.substr(sprintf('%08d', $obj->rowid), -1, 1).'/'.substr(sprintf('%08d', $obj->rowid), -2, 1).'/thumbs/'.$name.'_mini'.$ext; + $exists=dol_is_file($filetotest); + print 'Check user '.$obj->rowid.' lastname='.$obj->lastname.' fistname='.$obj->firstname.' photo='.$obj->photo.' file '.$filetotest." exists=".$exists."
\n"; + if ($exists) + { + $filetarget=$dolibarr_main_data_root.'/users/'.$obj->rowid.'/'.$name.$ext; + $filetargetsmall=$dolibarr_main_data_root.'/users/'.$obj->rowid.'/thumbs/'.$name.'_small'.$ext; + $filetargetmini=$dolibarr_main_data_root.'/users/'.$obj->rowid.'/thumbs/'.$name.'_mini'.$ext; + + $existt=dol_is_file($filetarget); + if (! $existt) + { + if (GETPOST('restore_user_pictures', 'alpha') == 'confirmed') + { + dol_mkdir($dolibarr_main_data_root.'/users/'.$obj->rowid); + } + + print "       -> Copy file ".$filetotest." -> ".$filetarget."
\n"; + if (GETPOST('restore_user_pictures', 'alpha') == 'confirmed') + { + dol_copy($filetotest, $filetarget, '', 0); + } + } + + $existtt=dol_is_file($filetargetsmall); + if (! $existtt) + { + if (GETPOST('restore_user_pictures', 'alpha') == 'confirmed') + { + dol_mkdir($dolibarr_main_data_root.'/users/'.$obj->rowid.'/thumbs'); + } + + print "       -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."
\n"; + if (GETPOST('restore_user_pictures', 'alpha') == 'confirmed') + { + dol_copy($filetotestsmall, $filetargetsmall, '', 0); + } + } + + $existtt=dol_is_file($filetargetmini); + if (! $existtt) + { + if (GETPOST('restore_user_pictures', 'alpha') == 'confirmed') + { + dol_mkdir($dolibarr_main_data_root.'/users/'.$obj->rowid.'/thumbs'); + } + + print "       -> Copy file ".$filetotestmini." -> ".$filetargetmini."
\n"; + if (GETPOST('restore_user_pictures', 'alpha') == 'confirmed') + { + dol_copy($filetotestmini, $filetargetmini, '', 0); + } + } + } + } + + $i++; + } + } + else + { + $ok=0; + dol_print_error($db); + } print ''; - //} }