Fix migration

This commit is contained in:
Laurent Destailleur 2018-12-07 19:05:24 +01:00
parent 37fe8afea3
commit 3538e9ab3b

View File

@ -2922,9 +2922,9 @@ function migrate_project_task_actors($db,$langs,$conf)
* @param Conf $conf Object conf * @param Conf $conf Object conf
* @param string $table Table name * @param string $table Table name
* @param int $fk_source Id of element source * @param int $fk_source Id of element source
* @param type $sourcetype Type of element source * @param string $sourcetype Type of element source
* @param int $fk_target Id of element target * @param int $fk_target Id of element target
* @param type $targettype Type of element target * @param string $targettype Type of element target
* @return void * @return void
*/ */
function migrate_relationship_tables($db,$langs,$conf,$table,$fk_source,$sourcetype,$fk_target,$targettype) function migrate_relationship_tables($db,$langs,$conf,$table,$fk_source,$sourcetype,$fk_target,$targettype)
@ -4833,7 +4833,7 @@ function migrate_reload_menu($db,$langs,$conf,$versionto)
*/ */
function migrate_user_photospath() function migrate_user_photospath()
{ {
global $conf, $db, $langs; global $conf, $db, $langs, $user;
print '<tr><td colspan="4">'; print '<tr><td colspan="4">';
@ -4842,14 +4842,14 @@ function migrate_user_photospath()
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$fuser = new User($db); $fuser = new User($db);
if (! is_object($user)) $user = $fuser; // To avoid error during migration
$sql = "SELECT rowid as uid from ".MAIN_DB_PREFIX."user"; // Get list of all users $sql = "SELECT rowid as uid from ".MAIN_DB_PREFIX."user"; // Get list of all users
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
while ($obj = $db->fetch_object($resql)) while ($obj = $db->fetch_object($resql))
{ {
print '.';
$fuser->fetch($obj->uid); $fuser->fetch($obj->uid);
//echo '<hr>'.$fuser->id.' -> '.$fuser->entity; //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
$entity = (empty($fuser->entity) ? 1 : $fuser->entity); $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
@ -4863,10 +4863,8 @@ function migrate_user_photospath()
$origin = $dir .'/'. get_exdir($fuser->id,2,0,0,$fuser,'user'); $origin = $dir .'/'. get_exdir($fuser->id,2,0,0,$fuser,'user');
$destin = $dir .'/'. $fuser->id; $destin = $dir .'/'. $fuser->id;
$error = 0;
$origin_osencoded=dol_osencode($origin); $origin_osencoded=dol_osencode($origin);
$destin_osencoded=dol_osencode($destin);
dol_mkdir($destin); dol_mkdir($destin);
//echo '<hr>'.$origin.' -> '.$destin; //echo '<hr>'.$origin.' -> '.$destin;
if (dol_is_dir($origin)) if (dol_is_dir($origin))
@ -4876,7 +4874,9 @@ function migrate_user_photospath()
{ {
while (($file = readdir($handle)) !== false) while (($file = readdir($handle)) !== false)
{ {
if ($file != '.' && $file != '..' && is_dir($origin_osencoded.'/'.$file)) if ($file == '.' || $file == '..') continue;
if (dol_is_dir($origin.'/'.$file)) // it is a dir (like 'thumbs')
{ {
$thumbs = opendir($origin_osencoded.'/'.$file); $thumbs = opendir($origin_osencoded.'/'.$file);
if (is_resource($thumbs)) if (is_resource($thumbs))
@ -4884,16 +4884,23 @@ function migrate_user_photospath()
dol_mkdir($destin.'/'.$file); dol_mkdir($destin.'/'.$file);
while (($thumb = readdir($thumbs)) !== false) while (($thumb = readdir($thumbs)) !== false)
{ {
dol_move($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb); if (! dol_is_file($destin.'/'.$file.'/'.$thumb))
{
if ($thumb == '.' || $thumb == '..') continue;
print '.';
dol_move($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, 0, 0, 0, 0);
}
} }
// dol_delete_dir($origin.'/'.$file); // dol_delete_dir($origin.'/'.$file);
} }
} }
else else // it is a file
{ {
if (dol_is_file($origin.'/'.$file) ) if (! dol_is_file($destin.'/'.$file))
{ {
dol_move($origin.'/'.$file, $destin.'/'.$file); print '.';
dol_move($origin.'/'.$file, $destin.'/'.$file, 0, 0, 0, 1);
} }
} }
} }