summaryrefslogtreecommitdiffstats
path: root/lib/migrate.php
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-03-12 21:41:32 +0000
committerTom Needham <needham.thomas@gmail.com>2012-03-12 21:41:32 +0000
commitd108bdc7c7940d23355c9a16f3f355387bbb66ef (patch)
treeb17978d797da3a20d6b84b931b8a4fd31df81f3b /lib/migrate.php
parent1cdb4396a4bc71ee564e73144bfdcd74a1a7493b (diff)
downloadnextcloud-server-d108bdc7c7940d23355c9a16f3f355387bbb66ef.tar.gz
nextcloud-server-d108bdc7c7940d23355c9a16f3f355387bbb66ef.zip
Improved import function. Added param to connectDB() to load the db from the import
Diffstat (limited to 'lib/migrate.php')
-rw-r--r--lib/migrate.php68
1 files changed, 54 insertions, 14 deletions
diff --git a/lib/migrate.php b/lib/migrate.php
index 95da4514fcc..075358c72b7 100644
--- a/lib/migrate.php
+++ b/lib/migrate.php
@@ -30,6 +30,7 @@ class OC_Migrate{
static private $providers=array();
static private $schema=false;
static private $uid=false;
+ static private $database=false;
/**
* register a new migration provider
@@ -108,40 +109,75 @@ class OC_Migrate{
/**
* @breif imports a new user
+ * @param $db string path to migration.db
+ * @param $migrateinfo string path to the migration info json file
* @param $uid optional uid to use
* @return bool if the import succedded
*/
- public static function import( $uid=false ){
-
- self::$uid = $uid;
-
+ public static function import( $db, $migrateinfo, $uid=false ){
+
if(!self::$uid){
OC_Log::write('migration','Tried to import without passing a uid',OC_Log::FATAL);
return false;
exit();
}
- // Connect to the db
- if(!self::connectDB()){
- return false;
+ // Check if the db exists
+ if( file_exists( $db ) ){
+ // Connect to the db
+ if(!self::connectDB( $db )){
+ return false;
+ exit();
+ }
+ } else {
+ OC_Log::write('migration','Migration.db not found at: '.$db, OC_Log::FATAL );
+ return false;
+ exit();
+ }
+
+ // Load the json info
+ if( file_exists( $migrateinfo ) ){
+
+ } else {
+ OC_Log::write( 'migration', 'Migration information file not found at: '.$migrateinfo, OC_Log::FATAL );
+ return false;
+ exit();
}
+ // Process migration info
+ $info = file_get_contents( $migrateinfo );
+ $info = json_decode( $info );
+
+ // Set the user id
+ self::$uid = !$uid : $info['migrateinfo']['uid'] ? $uid;
+
// Create the user
if(!self::createUser($uid, $hash)){
return false;
+ exit();
+ }
+
+ $apps = $info['apps'];
+
+ foreach( self::$providers as $provider){
+ // Is the app in the export?
+ if( array_key_exists( $provider->id, $apps ) ){
+ // Did it succeed?
+ if( $app[$provider->id] ){
+ // Then do the import
+ $provider->import();
+ }
+ }
}
-
- // Now get the list of apps to import from migration.db
- // Then check for migrate.php for these apps
- // If present, run the import function for them.
return true;
}
// @breif connects to migration.db, or creates if not found
+ // @param $db optional path to migration.db, defaults to user data dir
// @return bool whether the operation was successful
- private static function connectDB(){
+ private static function connectDB( $db=null ){
OC_Log::write('migration','connecting to migration.db for user: '.self::$uid,OC_Log::INFO);
// Fail if no user is set
if(!self::$uid){
@@ -152,6 +188,8 @@ class OC_Migrate{
if(!self::$MDB2){
require_once('MDB2.php');
+ self::$database = !is_null( $db ) ? $db : $datadir.'/'.self::$uid.'/migration.db';
+
$datadir = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
// Prepare options array
@@ -164,7 +202,7 @@ class OC_Migrate{
);
$dsn = array(
'phptype' => 'sqlite3',
- 'database' => $datadir.'/'.self::$uid.'/migration.db',
+ 'database' => self::$database,
'mode' => '0644'
);
@@ -392,7 +430,9 @@ class OC_Migrate{
// Create the user
$query = OC_DB::prepare( "INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )" );
$result = $query->execute( array( $uid, $data['hash']));
-
+ if( !$result ){
+ OC_Log::write('migration', 'Failed to create the new user "'.$uid."");
+ }
return $result ? true : false;
}