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 string $table Table name
* @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 type $targettype Type of element target
* @param string $targettype Type of element target
* @return void
*/
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()
{
global $conf, $db, $langs;
global $conf, $db, $langs, $user;
print '<tr><td colspan="4">';
@ -4842,14 +4842,14 @@ function migrate_user_photospath()
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$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
$resql = $db->query($sql);
if ($resql)
{
while ($obj = $db->fetch_object($resql))
{
print '.';
$fuser->fetch($obj->uid);
//echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
$entity = (empty($fuser->entity) ? 1 : $fuser->entity);
@ -4860,45 +4860,52 @@ function migrate_user_photospath()
}
if ($dir)
{
$origin = $dir .'/'. get_exdir($fuser->id,2,0,0,$fuser,'user');
$destin = $dir .'/'. $fuser->id;
$origin = $dir .'/'. get_exdir($fuser->id,2,0,0,$fuser,'user');
$destin = $dir .'/'. $fuser->id;
$error = 0;
$origin_osencoded=dol_osencode($origin);
$origin_osencoded=dol_osencode($origin);
$destin_osencoded=dol_osencode($destin);
dol_mkdir($destin);
//echo '<hr>'.$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);
}
}
}
}
}
dol_mkdir($destin);
//echo '<hr>'.$origin.' -> '.$destin;
if (dol_is_dir($origin))
{
$handle=opendir($origin_osencoded);
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if ($file == '.' || $file == '..') continue;
if (dol_is_dir($origin.'/'.$file)) // it is a dir (like 'thumbs')
{
$thumbs = opendir($origin_osencoded.'/'.$file);
if (is_resource($thumbs))
{
dol_mkdir($destin.'/'.$file);
while (($thumb = readdir($thumbs)) !== false)
{
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);
}
}
else // it is a file
{
if (! dol_is_file($destin.'/'.$file))
{
print '.';
dol_move($origin.'/'.$file, $destin.'/'.$file, 0, 0, 0, 1);
}
}
}
}
}
}
}
}