Try to use old uid when importing
This commit is contained in:
parent
514c9ad8e7
commit
0fa5e196ef
|
@ -40,69 +40,10 @@ if (isset($_POST['user_import'])) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
OC_Migrate::import( $to, 'user', 'newuser' );
|
if( !OC_Migrate::import( $to, 'user' ) ){
|
||||||
die();
|
die( 'failed to to import' );
|
||||||
// Find folder
|
|
||||||
$files = scandir( $importdir );
|
|
||||||
unset($files[0]);
|
|
||||||
unset($files[1]);
|
|
||||||
|
|
||||||
// Get the user
|
|
||||||
if( count($files) != 1 ){
|
|
||||||
OC_Log::write('migration', 'Invalid import file', OC_Log::ERROR);
|
|
||||||
die('invalid import, no user included');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$olduser = reset($files);
|
|
||||||
|
|
||||||
// Check for dbexport.xml and export info and data dir
|
|
||||||
$files = scandir( $importdir . '/' . $olduser );
|
|
||||||
|
|
||||||
$required = array( 'migration.db', 'export_info.json', 'files');
|
|
||||||
foreach($required as $require){
|
|
||||||
if( !in_array( $require, $files) ){
|
|
||||||
OC_Log::write('migration', 'Invlaid import file', OC_Log::ERROR);
|
|
||||||
die('invalid import');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$migrateinfo = $importdir . '/' . $olduser . '/export_info.json';
|
|
||||||
$migrateinfo = json_decode( file_get_contents( $migrateinfo ) );
|
|
||||||
|
|
||||||
// Check if uid is available
|
|
||||||
if( OC_User::UserExists( $olduser ) ){
|
|
||||||
OC_Log::write('migration','Username exists', OC_Log::ERROR);
|
|
||||||
die('user exists');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the user
|
|
||||||
if( !OC_Migrate::createUser( $olduser, $migrateinfo->hash ) ){
|
|
||||||
OC_Log::write('migration', 'Failed to create the new user', OC_Log::ERROR);
|
|
||||||
die('coundlt create new user');
|
|
||||||
}
|
|
||||||
|
|
||||||
$datadir = OC_Config::getValue( 'datadirectory' );
|
|
||||||
// Make the new users data dir
|
|
||||||
$path = $datadir . '/' . $olduser . '/files/';
|
|
||||||
if( !mkdir( $path, 0755, true ) ){
|
|
||||||
OC_Log::write('migration','Failed to create users data dir: '.$path, OC_Log::ERROR);
|
|
||||||
die('failed to create users data dir');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy data
|
|
||||||
if( !copy_r( $importdir . '/' . $olduser . '/files', $datadir . '/' . $olduser . '/files' ) ){
|
|
||||||
OC_Log::write('migration','Failed to copy user files to destination', OC_Log::ERROR);
|
|
||||||
die('failed to copy user files');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Import user data
|
|
||||||
if( !OC_Migrate::importAppData( $importdir . '/' . $olduser . '/migration.db', $migrateinfo ) ){
|
|
||||||
OC_Log::write('migration','Failed to import user data', OC_Log::ERROR);
|
|
||||||
die('failed to import user data');
|
|
||||||
}
|
|
||||||
|
|
||||||
// All done!
|
|
||||||
die('done');
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// fill template
|
// fill template
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OC_APP::registerPersonal('user_migrate','settings');
|
OC_APP::registerPersonal('user_migrate','settings');
|
||||||
OC_APP::registerAdmin('user_migrate','admin');
|
|
||||||
|
|
||||||
// add settings page to navigation
|
// add settings page to navigation
|
||||||
$entry = array(
|
$entry = array(
|
||||||
|
|
|
@ -190,9 +190,10 @@ class OC_Migrate{
|
||||||
/**
|
/**
|
||||||
* @breif imports a user, or owncloud instance
|
* @breif imports a user, or owncloud instance
|
||||||
* @param $path string path to zip
|
* @param $path string path to zip
|
||||||
|
* @param optional $type type of import (user or instance)
|
||||||
* @param optional $uid userid of new user
|
* @param optional $uid userid of new user
|
||||||
*/
|
*/
|
||||||
public static function import( $path, $uid=null ){
|
public static function import( $path, $type='user', $uid=null ){
|
||||||
OC_Util::checkAdminUser();
|
OC_Util::checkAdminUser();
|
||||||
$datadir = OC_Config::getValue( 'datadirectory' );
|
$datadir = OC_Config::getValue( 'datadirectory' );
|
||||||
// Extract the zip
|
// Extract the zip
|
||||||
|
@ -207,8 +208,12 @@ class OC_Migrate{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$json = json_decode( file_get_contents( $extractpath . 'export_info.json' ) );
|
$json = json_decode( file_get_contents( $extractpath . 'export_info.json' ) );
|
||||||
self::$exporttype = $json->exporttype;
|
if( !$json->exporttype != $type ){
|
||||||
|
OC_Log::write( 'migration', 'Invalid import file', OC_Log::ERROR );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
self::$exporttype = $type;
|
||||||
|
|
||||||
// Have we got a user if type is user
|
// Have we got a user if type is user
|
||||||
if( self::$exporttype == 'user' ){
|
if( self::$exporttype == 'user' ){
|
||||||
if( !$uid ){
|
if( !$uid ){
|
||||||
|
|
Loading…
Reference in New Issue