diff --git a/apps/bookmarks/lib/migrate.php b/apps/bookmarks/lib/migrate.php index 7d8ad8bfc5..9493f2cae8 100644 --- a/apps/bookmarks/lib/migrate.php +++ b/apps/bookmarks/lib/migrate.php @@ -11,10 +11,10 @@ class OC_Migrate_Provider_Bookmarks extends OC_Migrate_Provider{ 'idcol'=>'id' ); $ids = OC_Migrate::copyRows( $options ); - + $ids = array('1'); $options = array( 'table'=>'bookmarks_tags', - 'matchcol'=>'id', + 'matchcol'=>'bookmark_id', 'matchval'=>$ids ); diff --git a/apps/user_migrate/settings.php b/apps/user_migrate/settings.php index ed08abe79d..c35d46b351 100644 --- a/apps/user_migrate/settings.php +++ b/apps/user_migrate/settings.php @@ -25,7 +25,6 @@ OC_Util::checkAppEnabled('user_migrate'); if (isset($_POST['user_migrate'])) { // Looks like they want to migrate - $errors = array(); $root = OC::$SERVERROOT . "/"; $user = OC_User::getUser(); $zip = new ZipArchive(); @@ -49,21 +48,21 @@ if (isset($_POST['user_migrate'])) { // adding owncloud system files OC_Log::write('user_migrate',"Adding app data to user export file",OC_Log::INFO); // Call to OC_Migrate for the xml file. - $appdatafile = $tempdir . "/userexport.json"; - $appdata = OC_Migrate::export(OC_User::getUser()); - file_put_contents($appdatafile, $appdata); - $zip->addFile($appdatafile, "userexport.json"); + // Create migration.db + var_dump(OC_Migrate::export(OC_User::getUser())); + // Add export db to zip + $zip->addFile($root.'data/'.$user.'/migration.db', "migration.db"); } $zip->close(); - header("Content-Type: application/zip"); - header("Content-Disposition: attachment; filename=" . basename($filename)); - header("Content-Length: " . filesize($filename)); - readfile($filename); - unlink($filename); + //header("Content-Type: application/zip"); + //header("Content-Disposition: attachment; filename=" . basename($filename)); + //header("Content-Length: " . filesize($filename)); + //readfile($filename); + //unlink($filename); } else { // fill template diff --git a/lib/migrate.php b/lib/migrate.php index b09626d11b..a0d702b4e2 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -29,6 +29,7 @@ class OC_Migrate{ static private $MDB2=false; static private $providers=array(); static private $schema=false; + static private $uid=false; /** * register a new migration provider @@ -49,17 +50,27 @@ class OC_Migrate{ if(!OC_User_Database::userExists( $uid )){ return false; } - + + self::$uid = $uid; + self::connectDB(); + $ok = true; + $return = array(); + // Foreach provider - foreach( $providers as $provider ){ - - self::createAppTables( $provider->id ); - // Run the export function - $provider->export( $uid ); - + foreach( self::$providers as $provider ){ + // Check for database.xml + if(file_exists(OC::$SERVERROOT.'/apps/'.$provider->id.'/appinfo/database.xml')){ + if(!self::createAppTables( $provider->id )){ + $ok = false; + OC_Log::write('migration','failed to create migration tables for: '.$provider->id,OC_Log::INFO); + } + } + if($ok){ + $return[$provider->id]['success'] = $provider->export( $uid ); + } } - return true; + return $return; } @@ -86,7 +97,7 @@ class OC_Migrate{ // Then check for migrate.php for these apps // If present, run the import function for them. - return treu; + return true; } @@ -98,7 +109,7 @@ class OC_Migrate{ if(!self::$MDB2){ require_once('MDB2.php'); - $datadir = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" ); + $datadir = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); // Prepare options array $options = array( @@ -109,22 +120,22 @@ class OC_Migrate{ 'quote_identifier' => true ); $dsn = array( - 'phptype' => 'sqlite', + 'phptype' => 'sqlite3', 'database' => $datadir.'/'.self::$uid.'/migration.db', 'mode' => '0644' ); // Try to establish connection self::$MDB2 = MDB2::factory( $dsn, $options ); - // Die if we could not connect if( PEAR::isError( self::$MDB2 )){ + die(self::$MDB2->getMessage()); OC_Log::write('migration', 'Failed to create migration.db',OC_Log::FATAL); OC_Log::write('migration',self::$MDB2->getUserInfo(),OC_Log::FATAL); OC_Log::write('migration',self::$MDB2->getMessage(),OC_Log::FATAL); return false; + } else { } - // We always, really always want associative arrays self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC); } @@ -149,7 +160,7 @@ class OC_Migrate{ OC_Log::write('migration',$entry,OC_Log::FATAL); return false; } else { - return true; + return $query; } } @@ -160,7 +171,6 @@ class OC_Migrate{ private static function processQuery( $query ){ self::connectDB(); - $type = 'sqlite'; $prefix = ''; $query = str_replace( '`', '\'', $query ); @@ -184,6 +194,12 @@ class OC_Migrate{ // Need to include 'where' in the query? if( array_key_exists( 'matchval', $options ) && array_key_exists( 'matchcol', $options ) ){ + + // If only one matchval, create an array + if(!is_array($options['matchval'])){ + $options['matchval'] = array( $options['matchval'] ); + } + foreach( $options['matchval'] as $matchval ){ // Run the query for this match value (where x = y value) $query = OC_DB::prepare( "SELECT * FROM *PREFIX*" . $options['table'] . " WHERE " . $options['matchcol'] . " LIKE ?" ); @@ -209,7 +225,7 @@ class OC_Migrate{ // @param $options array of copyRows options // @return void private static function insertData( $data, $options ){ - while( $data = $result->fetchRow() ){ + while( $row = $data->fetchRow() ){ // Now save all this to the migration.db foreach($row as $field=>$value){ $fields[] = $field; @@ -217,14 +233,18 @@ class OC_Migrate{ } // Generate some sql - $sql = "INSERT INTO `*PREFIX*" . $options['table'] . '` ( `'; + $sql = "INSERT INTO `" . $options['table'] . '` ( `'; $fieldssql = implode( '`, `', $fields ); $sql .= $fieldssql . "` ) VALUES( "; - $valuessql = substr( str_repeat( '?, ', count( $fields ) ),0,-1 ); + $valuessql = substr( str_repeat( '?, ', count( $fields ) ),0,-2 ); $sql .= $valuessql . " )"; // Make the query $query = self::prepare( $sql ); - $query->execute( $values ); + if(!$query){ + OC_Log::write('migration','Invalid sql produced: '.$sql,OC_Log::FATAL); + } else { + $query->execute( $values ); + } } } @@ -232,10 +252,12 @@ class OC_Migrate{ // @param $appid string id of the app // @return bool whether the operation was successful private static function createAppTables( $appid ){ - $file = OC::$SERVERROOT.'/apps/'.$appid.'appinfo/database.xml'; + $file = OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/database.xml'; if(file_exists( $file )){ - self::connectScheme(); + if(!self::connectScheme()){ + return false; + } // There is a database.xml file $content = file_get_contents( $file );