PageRenderTime 73ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/migrate.php

https://github.com/jlgg/simple_trash
PHP | 664 lines | 394 code | 63 blank | 207 comment | 85 complexity | f54dad5cfa5491673b37602e9dc0223c MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Tom Needham
  6. * @copyright 2012 Tom Needham tom@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * provides an interface to migrate users and whole ownclouds
  24. */
  25. class OC_Migrate{
  26. // Array of OC_Migration_Provider objects
  27. static private $providers=array();
  28. // User id of the user to import/export
  29. static private $uid=false;
  30. // Holds the ZipArchive object
  31. static private $zip=false;
  32. // Stores the type of export
  33. static private $exporttype=false;
  34. // Array of temp files to be deleted after zip creation
  35. static private $tmpfiles=array();
  36. // Holds the db object
  37. static private $MDB2=false;
  38. // Schema db object
  39. static private $schema=false;
  40. // Path to the sqlite db
  41. static private $dbpath=false;
  42. // Holds the path to the zip file
  43. static private $zippath=false;
  44. // Holds the OC_Migration_Content object
  45. static private $content=false;
  46. /**
  47. * register a new migration provider
  48. * @param OC_Migrate_Provider $provider
  49. */
  50. public static function registerProvider($provider) {
  51. self::$providers[]=$provider;
  52. }
  53. /**
  54. * @brief finds and loads the providers
  55. */
  56. static private function findProviders() {
  57. // Find the providers
  58. $apps = OC_App::getAllApps();
  59. foreach($apps as $app) {
  60. $path = OC_App::getAppPath($app) . '/appinfo/migrate.php';
  61. if( file_exists( $path ) ) {
  62. include $path;
  63. }
  64. }
  65. }
  66. /**
  67. * @brief exports a user, or owncloud instance
  68. * @param optional $uid string user id of user to export if export type is user, defaults to current
  69. * @param ootional $type string type of export, defualts to user
  70. * @param otional $path string path to zip output folder
  71. * @return false on error, path to zip on success
  72. */
  73. public static function export( $uid=null, $type='user', $path=null ) {
  74. $datadir = OC_Config::getValue( 'datadirectory' );
  75. // Validate export type
  76. $types = array( 'user', 'instance', 'system', 'userfiles' );
  77. if( !in_array( $type, $types ) ) {
  78. OC_Log::write( 'migration', 'Invalid export type', OC_Log::ERROR );
  79. return json_encode( array( 'success' => false ) );
  80. }
  81. self::$exporttype = $type;
  82. // Userid?
  83. if( self::$exporttype == 'user' ) {
  84. // Check user exists
  85. self::$uid = is_null($uid) ? OC_User::getUser() : $uid;
  86. if(!OC_User::userExists(self::$uid)) {
  87. return json_encode( array( 'success' => false) );
  88. }
  89. }
  90. // Calculate zipname
  91. if( self::$exporttype == 'user' ) {
  92. $zipname = 'oc_export_' . self::$uid . '_' . date("y-m-d_H-i-s") . '.zip';
  93. } else {
  94. $zipname = 'oc_export_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '.zip';
  95. }
  96. // Calculate path
  97. if( self::$exporttype == 'user' ) {
  98. self::$zippath = $datadir . '/' . self::$uid . '/' . $zipname;
  99. } else {
  100. if( !is_null( $path ) ) {
  101. // Validate custom path
  102. if( !file_exists( $path ) || !is_writeable( $path ) ) {
  103. OC_Log::write( 'migration', 'Path supplied is invalid.', OC_Log::ERROR );
  104. return json_encode( array( 'success' => false ) );
  105. }
  106. self::$zippath = $path . $zipname;
  107. } else {
  108. // Default path
  109. self::$zippath = get_temp_dir() . '/' . $zipname;
  110. }
  111. }
  112. // Create the zip object
  113. if( !self::createZip() ) {
  114. return json_encode( array( 'success' => false ) );
  115. }
  116. // Do the export
  117. self::findProviders();
  118. $exportdata = array();
  119. switch( self::$exporttype ) {
  120. case 'user':
  121. // Connect to the db
  122. self::$dbpath = $datadir . '/' . self::$uid . '/migration.db';
  123. if( !self::connectDB() ) {
  124. return json_encode( array( 'success' => false ) );
  125. }
  126. self::$content = new OC_Migration_Content( self::$zip, self::$MDB2 );
  127. // Export the app info
  128. $exportdata = self::exportAppData();
  129. // Add the data dir to the zip
  130. self::$content->addDir(OC_User::getHome(self::$uid), true, '/' );
  131. break;
  132. case 'instance':
  133. self::$content = new OC_Migration_Content( self::$zip );
  134. // Creates a zip that is compatable with the import function
  135. $dbfile = tempnam( get_temp_dir(), "owncloud_export_data_" );
  136. OC_DB::getDbStructure( $dbfile, 'MDB2_SCHEMA_DUMP_ALL');
  137. // Now add in *dbname* and *dbprefix*
  138. $dbexport = file_get_contents( $dbfile );
  139. $dbnamestring = "<database>\n\n <name>" . OC_Config::getValue( "dbname", "owncloud" );
  140. $dbtableprefixstring = "<table>\n\n <name>" . OC_Config::getValue( "dbtableprefix", "oc_" );
  141. $dbexport = str_replace( $dbnamestring, "<database>\n\n <name>*dbname*", $dbexport );
  142. $dbexport = str_replace( $dbtableprefixstring, "<table>\n\n <name>*dbprefix*", $dbexport );
  143. // Add the export to the zip
  144. self::$content->addFromString( $dbexport, "dbexport.xml" );
  145. // Add user data
  146. foreach(OC_User::getUsers() as $user) {
  147. self::$content->addDir(OC_User::getHome($user), true, "/userdata/" );
  148. }
  149. break;
  150. case 'userfiles':
  151. self::$content = new OC_Migration_Content( self::$zip );
  152. // Creates a zip with all of the users files
  153. foreach(OC_User::getUsers() as $user) {
  154. self::$content->addDir(OC_User::getHome($user), true, "/" );
  155. }
  156. break;
  157. case 'system':
  158. self::$content = new OC_Migration_Content( self::$zip );
  159. // Creates a zip with the owncloud system files
  160. self::$content->addDir( OC::$SERVERROOT . '/', false, '/');
  161. foreach (array(".git", "3rdparty", "apps", "core", "files", "l10n", "lib", "ocs", "search", "settings", "tests") as $dir) {
  162. self::$content->addDir( OC::$SERVERROOT . '/' . $dir, true, "/");
  163. }
  164. break;
  165. }
  166. if( !$info = self::getExportInfo( $exportdata ) ) {
  167. return json_encode( array( 'success' => false ) );
  168. }
  169. // Add the export info json to the export zip
  170. self::$content->addFromString( $info, 'export_info.json' );
  171. if( !self::$content->finish() ) {
  172. return json_encode( array( 'success' => false ) );
  173. }
  174. return json_encode( array( 'success' => true, 'data' => self::$zippath ) );
  175. }
  176. /**
  177. * @brief imports a user, or owncloud instance
  178. * @param $path string path to zip
  179. * @param optional $type type of import (user or instance)
  180. * @param optional $uid userid of new user
  181. */
  182. public static function import( $path, $type='user', $uid=null ) {
  183. $datadir = OC_Config::getValue( 'datadirectory' );
  184. // Extract the zip
  185. if( !$extractpath = self::extractZip( $path ) ) {
  186. return json_encode( array( 'success' => false ) );
  187. }
  188. // Get export_info.json
  189. $scan = scandir( $extractpath );
  190. // Check for export_info.json
  191. if( !in_array( 'export_info.json', $scan ) ) {
  192. OC_Log::write( 'migration', 'Invalid import file, export_info.json not found', OC_Log::ERROR );
  193. return json_encode( array( 'success' => false ) );
  194. }
  195. $json = json_decode( file_get_contents( $extractpath . 'export_info.json' ) );
  196. if( $json->exporttype != $type ) {
  197. OC_Log::write( 'migration', 'Invalid import file', OC_Log::ERROR );
  198. return json_encode( array( 'success' => false ) );
  199. }
  200. self::$exporttype = $type;
  201. $currentuser = OC_User::getUser();
  202. // Have we got a user if type is user
  203. if( self::$exporttype == 'user' ) {
  204. self::$uid = !is_null($uid) ? $uid : $currentuser;
  205. }
  206. // We need to be an admin if we are not importing our own data
  207. if(($type == 'user' && self::$uid != $currentuser) || $type != 'user' ) {
  208. if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )) {
  209. // Naughty.
  210. OC_Log::write( 'migration', 'Import not permitted.', OC_Log::ERROR );
  211. return json_encode( array( 'success' => false ) );
  212. }
  213. }
  214. // Handle export types
  215. switch( self::$exporttype ) {
  216. case 'user':
  217. // Check user availability
  218. if( !OC_User::userExists( self::$uid ) ) {
  219. OC_Log::write( 'migration', 'User doesn\'t exist', OC_Log::ERROR );
  220. return json_encode( array( 'success' => false ) );
  221. }
  222. // Copy data
  223. $userfolder = $extractpath . $json->exporteduser;
  224. $newuserfolder = $datadir . '/' . self::$uid;
  225. foreach(scandir($userfolder) as $file){
  226. if($file !== '.' && $file !== '..' && is_dir($file)) {
  227. // Then copy the folder over
  228. OC_Helper::copyr($userfolder.'/'.$file, $newuserfolder.'/'.$file);
  229. }
  230. }
  231. // Import user app data
  232. if(file_exists($extractpath . $json->exporteduser . '/migration.db')) {
  233. if( !$appsimported = self::importAppData( $extractpath . $json->exporteduser . '/migration.db', $json, self::$uid ) ) {
  234. return json_encode( array( 'success' => false ) );
  235. }
  236. }
  237. // All done!
  238. if( !self::unlink_r( $extractpath ) ) {
  239. OC_Log::write( 'migration', 'Failed to delete the extracted zip', OC_Log::ERROR );
  240. }
  241. return json_encode( array( 'success' => true, 'data' => $appsimported ) );
  242. break;
  243. case 'instance':
  244. /*
  245. * EXPERIMENTAL
  246. // Check for new data dir and dbexport before doing anything
  247. // TODO
  248. // Delete current data folder.
  249. OC_Log::write( 'migration', "Deleting current data dir", OC_Log::INFO );
  250. if( !self::unlink_r( $datadir, false ) ) {
  251. OC_Log::write( 'migration', 'Failed to delete the current data dir', OC_Log::ERROR );
  252. return json_encode( array( 'success' => false ) );
  253. }
  254. // Copy over data
  255. if( !self::copy_r( $extractpath . 'userdata', $datadir ) ) {
  256. OC_Log::write( 'migration', 'Failed to copy over data directory', OC_Log::ERROR );
  257. return json_encode( array( 'success' => false ) );
  258. }
  259. // Import the db
  260. if( !OC_DB::replaceDB( $extractpath . 'dbexport.xml' ) ) {
  261. return json_encode( array( 'success' => false ) );
  262. }
  263. // Done
  264. return json_encode( array( 'success' => true ) );
  265. */
  266. break;
  267. }
  268. }
  269. /**
  270. * @brief recursively deletes a directory
  271. * @param $dir string path of dir to delete
  272. * $param optional $deleteRootToo bool delete the root directory
  273. * @return bool
  274. */
  275. private static function unlink_r( $dir, $deleteRootToo=true ) {
  276. if( !$dh = @opendir( $dir ) ) {
  277. return false;
  278. }
  279. while (false !== ($obj = readdir($dh))) {
  280. if($obj == '.' || $obj == '..') {
  281. continue;
  282. }
  283. if (!@unlink($dir . '/' . $obj)) {
  284. self::unlink_r($dir.'/'.$obj, true);
  285. }
  286. }
  287. closedir($dh);
  288. if ( $deleteRootToo ) {
  289. @rmdir($dir);
  290. }
  291. return true;
  292. }
  293. /**
  294. * @brief tries to extract the import zip
  295. * @param $path string path to the zip
  296. * @return string path to extract location (with a trailing slash) or false on failure
  297. */
  298. static private function extractZip( $path ) {
  299. self::$zip = new ZipArchive;
  300. // Validate path
  301. if( !file_exists( $path ) ) {
  302. OC_Log::write( 'migration', 'Zip not found', OC_Log::ERROR );
  303. return false;
  304. }
  305. if ( self::$zip->open( $path ) != true ) {
  306. OC_Log::write( 'migration', "Failed to open zip file", OC_Log::ERROR );
  307. return false;
  308. }
  309. $to = get_temp_dir() . '/oc_import_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '/';
  310. if( !self::$zip->extractTo( $to ) ) {
  311. return false;
  312. }
  313. self::$zip->close();
  314. return $to;
  315. }
  316. /**
  317. * @brief connects to a MDB2 database scheme
  318. * @returns bool
  319. */
  320. static private function connectScheme() {
  321. // We need a mdb2 database connection
  322. self::$MDB2->loadModule( 'Manager' );
  323. self::$MDB2->loadModule( 'Reverse' );
  324. // Connect if this did not happen before
  325. if( !self::$schema ) {
  326. require_once 'MDB2/Schema.php';
  327. self::$schema=MDB2_Schema::factory( self::$MDB2 );
  328. }
  329. return true;
  330. }
  331. /**
  332. * @brief creates a migration.db in the users data dir with their app data in
  333. * @return bool whether operation was successfull
  334. */
  335. private static function exportAppData( ) {
  336. $success = true;
  337. $return = array();
  338. // Foreach provider
  339. foreach( self::$providers as $provider ) {
  340. // Check if the app is enabled
  341. if( OC_App::isEnabled( $provider->getID() ) ) {
  342. $success = true;
  343. // Does this app use the database?
  344. if( file_exists( OC_App::getAppPath($provider->getID()).'/appinfo/database.xml' ) ) {
  345. // Create some app tables
  346. $tables = self::createAppTables( $provider->getID() );
  347. if( is_array( $tables ) ) {
  348. // Save the table names
  349. foreach($tables as $table) {
  350. $return['apps'][$provider->getID()]['tables'][] = $table;
  351. }
  352. } else {
  353. // It failed to create the tables
  354. $success = false;
  355. }
  356. }
  357. // Run the export function?
  358. if( $success ) {
  359. // Set the provider properties
  360. $provider->setData( self::$uid, self::$content );
  361. $return['apps'][$provider->getID()]['success'] = $provider->export();
  362. } else {
  363. $return['apps'][$provider->getID()]['success'] = false;
  364. $return['apps'][$provider->getID()]['message'] = 'failed to create the app tables';
  365. }
  366. // Now add some app info the the return array
  367. $appinfo = OC_App::getAppInfo( $provider->getID() );
  368. $return['apps'][$provider->getID()]['version'] = OC_App::getAppVersion($provider->getID());
  369. }
  370. }
  371. return $return;
  372. }
  373. /**
  374. * @brief generates json containing export info, and merges any data supplied
  375. * @param optional $array array of data to include in the returned json
  376. * @return bool
  377. */
  378. static private function getExportInfo( $array=array() ) {
  379. $info = array(
  380. 'ocversion' => OC_Util::getVersion(),
  381. 'exporttime' => time(),
  382. 'exportedby' => OC_User::getUser(),
  383. 'exporttype' => self::$exporttype,
  384. 'exporteduser' => self::$uid
  385. );
  386. if( !is_array( $array ) ) {
  387. OC_Log::write( 'migration', 'Supplied $array was not an array in getExportInfo()', OC_Log::ERROR );
  388. }
  389. // Merge in other data
  390. $info = array_merge( $info, (array)$array );
  391. // Create json
  392. $json = json_encode( $info );
  393. return $json;
  394. }
  395. /**
  396. * @brief connects to migration.db, or creates if not found
  397. * @param $db optional path to migration.db, defaults to user data dir
  398. * @return bool whether the operation was successful
  399. */
  400. static private function connectDB( $path=null ) {
  401. // Has the dbpath been set?
  402. self::$dbpath = !is_null( $path ) ? $path : self::$dbpath;
  403. if( !self::$dbpath ) {
  404. OC_Log::write( 'migration', 'connectDB() was called without dbpath being set', OC_Log::ERROR );
  405. return false;
  406. }
  407. // Already connected
  408. if(!self::$MDB2) {
  409. require_once 'MDB2.php';
  410. $datadir = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
  411. // DB type
  412. if( class_exists( 'SQLite3' ) ) {
  413. $dbtype = 'sqlite3';
  414. } else if( is_callable( 'sqlite_open' ) ) {
  415. $dbtype = 'sqlite';
  416. } else {
  417. OC_Log::write( 'migration', 'SQLite not found', OC_Log::ERROR );
  418. return false;
  419. }
  420. // Prepare options array
  421. $options = array(
  422. 'portability' => MDB2_PORTABILITY_ALL & (!MDB2_PORTABILITY_FIX_CASE),
  423. 'log_line_break' => '<br>',
  424. 'idxname_format' => '%s',
  425. 'debug' => true,
  426. 'quote_identifier' => true
  427. );
  428. $dsn = array(
  429. 'phptype' => $dbtype,
  430. 'database' => self::$dbpath,
  431. 'mode' => '0644'
  432. );
  433. // Try to establish connection
  434. self::$MDB2 = MDB2::factory( $dsn, $options );
  435. // Die if we could not connect
  436. if( PEAR::isError( self::$MDB2 ) ) {
  437. die( self::$MDB2->getMessage() );
  438. OC_Log::write( 'migration', 'Failed to create/connect to migration.db', OC_Log::FATAL );
  439. OC_Log::write( 'migration', self::$MDB2->getUserInfo(), OC_Log::FATAL );
  440. OC_Log::write( 'migration', self::$MDB2->getMessage(), OC_Log::FATAL );
  441. return false;
  442. }
  443. // We always, really always want associative arrays
  444. self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC);
  445. }
  446. return true;
  447. }
  448. /**
  449. * @brief creates the tables in migration.db from an apps database.xml
  450. * @param $appid string id of the app
  451. * @return bool whether the operation was successful
  452. */
  453. static private function createAppTables( $appid ) {
  454. if( !self::connectScheme() ) {
  455. return false;
  456. }
  457. // There is a database.xml file
  458. $content = file_get_contents(OC_App::getAppPath($appid) . '/appinfo/database.xml' );
  459. $file2 = 'static://db_scheme';
  460. // TODO get the relative path to migration.db from the data dir
  461. // For now just cheat
  462. $path = pathinfo( self::$dbpath );
  463. $content = str_replace( '*dbname*', self::$uid.'/migration', $content );
  464. $content = str_replace( '*dbprefix*', '', $content );
  465. $xml = new SimpleXMLElement($content);
  466. foreach($xml->table as $table) {
  467. $tables[] = (string)$table->name;
  468. }
  469. file_put_contents( $file2, $content );
  470. // Try to create tables
  471. $definition = self::$schema->parseDatabaseDefinitionFile( $file2 );
  472. unlink( $file2 );
  473. // Die in case something went wrong
  474. if( $definition instanceof MDB2_Schema_Error ) {
  475. OC_Log::write( 'migration', 'Failed to parse database.xml for: '.$appid, OC_Log::FATAL );
  476. OC_Log::write( 'migration', $definition->getMessage().': '.$definition->getUserInfo(), OC_Log::FATAL );
  477. return false;
  478. }
  479. $definition['overwrite'] = true;
  480. $ret = self::$schema->createDatabase( $definition );
  481. // Die in case something went wrong
  482. if( $ret instanceof MDB2_Error ) {
  483. OC_Log::write( 'migration', 'Failed to create tables for: '.$appid, OC_Log::FATAL );
  484. OC_Log::write( 'migration', $ret->getMessage().': '.$ret->getUserInfo(), OC_Log::FATAL );
  485. return false;
  486. }
  487. return $tables;
  488. }
  489. /**
  490. * @brief tries to create the zip
  491. * @param $path string path to zip destination
  492. * @return bool
  493. */
  494. static private function createZip() {
  495. self::$zip = new ZipArchive;
  496. // Check if properties are set
  497. if( !self::$zippath ) {
  498. OC_Log::write('migration', 'createZip() called but $zip and/or $zippath have not been set', OC_Log::ERROR);
  499. return false;
  500. }
  501. if ( self::$zip->open( self::$zippath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ) !== true ) {
  502. OC_Log::write('migration', 'Failed to create the zip with error: '.self::$zip->getStatusString(), OC_Log::ERROR);
  503. return false;
  504. } else {
  505. return true;
  506. }
  507. }
  508. /**
  509. * @brief returns an array of apps that support migration
  510. * @return array
  511. */
  512. static public function getApps() {
  513. $allapps = OC_App::getAllApps();
  514. foreach($allapps as $app) {
  515. $path = self::getAppPath($app) . '/lib/migrate.php';
  516. if( file_exists( $path ) ) {
  517. $supportsmigration[] = $app;
  518. }
  519. }
  520. return $supportsmigration;
  521. }
  522. /**
  523. * @brief imports a new user
  524. * @param $db string path to migration.db
  525. * @param $info object of migration info
  526. * @param $uid optional uid to use
  527. * @return array of apps with import statuses, or false on failure.
  528. */
  529. public static function importAppData( $db, $info, $uid=null ) {
  530. // Check if the db exists
  531. if( file_exists( $db ) ) {
  532. // Connect to the db
  533. if(!self::connectDB( $db )) {
  534. OC_Log::write('migration', 'Failed to connect to migration.db', OC_Log::ERROR);
  535. return false;
  536. }
  537. } else {
  538. OC_Log::write('migration', 'Migration.db not found at: '.$db, OC_Log::FATAL );
  539. return false;
  540. }
  541. // Find providers
  542. self::findProviders();
  543. // Generate importinfo array
  544. $importinfo = array(
  545. 'olduid' => $info->exporteduser,
  546. 'newuid' => self::$uid
  547. );
  548. foreach( self::$providers as $provider) {
  549. // Is the app in the export?
  550. $id = $provider->getID();
  551. if( isset( $info->apps->$id ) ) {
  552. // Is the app installed
  553. if( !OC_App::isEnabled( $id ) ) {
  554. OC_Log::write( 'migration', 'App: ' . $id . ' is not installed, can\'t import data.', OC_Log::INFO );
  555. $appsstatus[$id] = 'notsupported';
  556. } else {
  557. // Did it succeed on export?
  558. if( $info->apps->$id->success ) {
  559. // Give the provider the content object
  560. if( !self::connectDB( $db ) ) {
  561. return false;
  562. }
  563. $content = new OC_Migration_Content( self::$zip, self::$MDB2 );
  564. $provider->setData( self::$uid, $content, $info );
  565. // Then do the import
  566. if( !$appsstatus[$id] = $provider->import( $info->apps->$id, $importinfo ) ) {
  567. // Failed to import app
  568. OC_Log::write( 'migration', 'Failed to import app data for user: ' . self::$uid . ' for app: ' . $id, OC_Log::ERROR );
  569. }
  570. } else {
  571. // Add to failed list
  572. $appsstatus[$id] = false;
  573. }
  574. }
  575. }
  576. }
  577. return $appsstatus;
  578. }
  579. /*
  580. * @brief creates a new user in the database
  581. * @param $uid string user_id of the user to be created
  582. * @param $hash string hash of the user to be created
  583. * @return bool result of user creation
  584. */
  585. public static function createUser( $uid, $hash ) {
  586. // Check if userid exists
  587. if(OC_User::userExists( $uid )) {
  588. return false;
  589. }
  590. // Create the user
  591. $query = OC_DB::prepare( "INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )" );
  592. $result = $query->execute( array( $uid, $hash));
  593. if( !$result ) {
  594. OC_Log::write('migration', 'Failed to create the new user "'.$uid."");
  595. }
  596. return $result ? true : false;
  597. }
  598. }