<commit_before><?php
/**
 * ownCloud
 *
 * @author <NAME>
 * @copyright 2012 <NAME> <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


/**
 * provides an interface to all search providers
 */
class OC_Migrate{
	
	// Holds the db object
	static private $MDB2=false;
	// Array of OC_Migration_Provider objects
	static private $providers=array();
	// Schema db object
	static private $schema=false;
	// User id of the user to import/export
	static private $uid=false;
	// Path to the sqlite db
	static private $dbpath=false;
	
	/**
	 * register a new migration provider
	 * @param OC_Migrate_Provider $provider
	 */
	public static function registerProvider($provider){
		self::$providers[]=$provider;
	}
	
	/**
	 * @breif creates a migration.db in the users data dir with their app data in
	 * @param @uid string userid of the user to export for
	 * @return bool whether operation was successfull
	 */
	public static function export( $uid ){

		// Only export database users, otherwise we get chaos
		if(!OC_User_Database::userExists( $uid )){
			return false;	
		}
		
		self::$uid = $uid;
		
		if(empty(self::$uid)){
			OC_Log::write('migration','Invalid uid passed',OC_Log::FATAL);
			return false;
			exit();	
		}
		
		self::connectDB();
		$ok = true;
		$return = array();
		
		// Find the providers
		$apps = OC_App::getAllApps();
		
		foreach($apps as $app){
			$path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php';
			if( file_exists( $path ) ){
				include( $path );	
			}	
		}
		
		// Foreach provider
		foreach( self::$providers as $provider ){
			$failed = false;
			
			// Does this app use the database?
			if(file_exists(OC::$SERVERROOT.'/apps/'.$provider->id.'/appinfo/database.xml')){
				// Create some app tables
				$tables = self::createAppTables( $provider->id );
				if( is_array( $tables ) ){
					// Save the table names
					foreach($tables as $table){
						$return['app'][$provider->id]['tables'][] = $table;	
					}	
				} else {
					// It failed to create the tables
					$failed = true;
				}	
			}
			
			// Run the import function?
			if( !$failed ){
				$return['app'][$provider->id]['success'] = $provider->export( $uid );	
			} else {
				$return['app'][$provider->id]['success'] = false;	
				$return['app'][$provider->id]['message'] = 'failed to create the app tables';	
			}
			
			// Now add some app info the the return array
			$appinfo = OC_App::getAppInfo( $provider->id );
			$return['app'][$provider->id]['version'] = $appinfo['version'];
			
		}

		
		// Add some general info to the return array
		$return['migrateinfo']['uid'] = $uid;
		$return['migrateinfo']['ocversion'] = OC_Util::getVersionString();
		
		return $return;
		
	}
	
	/**
	* @breif returns an array of apps that support migration
	* @return array
	*/
	static public function getApps(){
		$allapps = OC_App::getAllApps();
		foreach($allapps as $app){
			$path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php';
			if( file_exists( $path ) ){
				$supportsmigration[] = $app;
			}	
		}
		reutrn $supportsmigration;	
	}
	
	/**
	* @breif imports a new user
	* @param $db string path to migration.db
	* @param $migrateinfo array of migration ino
	* @param $uid optional uid to use
	* @return bool if the import succedded
	*/
	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();	
		}
		
		// 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();
		}
		<commit_msg>typo :/<commit_after><?php
/**
 * ownCloud
 *
 * @author <NAME>
 * @copyright 2012 <NAME> <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


/**
 * provides an interface to all search providers
 */
class OC_Migrate{
	
	// Holds the db object
	static private $MDB2=false;
	// Array of OC_Migration_Provider objects
	static private $providers=array();
	// Schema db object
	static private $schema=false;
	// User id of the user to import/export
	static private $uid=false;
	// Path to the sqlite db
	static private $dbpath=false;
	
	/**
	 * register a new migration provider
	 * @param OC_Migrate_Provider $provider
	 */
	public static function registerProvider($provider){
		self::$providers[]=$provider;
	}
	
	/**
	 * @breif creates a migration.db in the users data dir with their app data in
	 * @param @uid string userid of the user to export for
	 * @return bool whether operation was successfull
	 */
	public static function export( $uid ){

		// Only export database users, otherwise we get chaos
		if(!OC_User_Database::userExists( $uid )){
			return false;	
		}
		
		self::$uid = $uid;
		
		if(empty(self::$uid)){
			OC_Log::write('migration','Invalid uid passed',OC_Log::FATAL);
			return false;
			exit();	
		}
		
		self::connectDB();
		$ok = true;
		$return = array();
		
		// Find the providers
		$apps = OC_App::getAllApps();
		
		foreach($apps as $app){
			$path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php';
			if( file_exists( $path ) ){
				include( $path );	
			}	
		}
		
		// Foreach provider
		foreach( self::$providers as $provider ){
			$failed = false;
			
			// Does this app use the database?
			if(file_exists(OC::$SERVERROOT.'/apps/'.$provider->id.'/appinfo/database.xml')){
				// Create some app tables
				$tables = self::createAppTables( $provider->id );
				if( is_array( $tables ) ){
					// Save the table names
					foreach($tables as $table){
						$return['app'][$provider->id]['tables'][] = $table;	
					}	
				} else {
					// It failed to create the tables
					$failed = true;
				}	
			}
			
			// Run the import function?
			if( !$failed ){
				$return['app'][$provider->id]['success'] = $provider->export( $uid );	
			} else {
				$return['app'][$provider->id]['success'] = false;	
				$return['app'][$provider->id]['message'] = 'failed to create the app tables';	
			}
			
			// Now add some app info the the return array
			$appinfo = OC_App::getAppInfo( $provider->id );
			$return['app'][$provider->id]['version'] = $appinfo['version'];
			
		}

		
		// Add some general info to the return array
		$return['migrateinfo']['uid'] = $uid;
		$return['migrateinfo']['ocversion'] = OC_Util::getVersionString();
		
		return $return;
		
	}
	
	/**
	* @breif returns an array of apps that support migration
	* @return array
	*/
	static public function getApps(){
		$allapps = OC_App::getAllApps();
		foreach($allapps as $app){
			$path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php';
			if( file_exists( $path ) ){
				$supportsmigration[] = $app;
			}	
		}
		return $supportsmigration;	
	}
	
	/**
	* @breif imports a new user
	* @param $db string path to migration.db
	* @param $migrateinfo array of migration ino
	* @param $uid optional uid to use
	* @return bool if the import succedded
	*/
	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();	
		}
		
		// 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();
		}
		
{'fraction_non_alphanumeric': 0.14233409610983982, 'fraction_numerical': 0.0013729977116704805, 'mean_word_length': 3.168335717691941, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4284410', 'n_tokens_mistral': 3206, 'n_tokens_neox': 2768, 'n_words': 887}