. * */ OC_Util::checkAppEnabled('user_migrate'); if (isset($_POST['user_migrate'])) { // Looks like they want to migrate $root = OC::$SERVERROOT . "/"; $user = OC_User::getUser(); $zip = new ZipArchive(); $tempdir = get_temp_dir(); $filename = $tempdir . "/" . $user . "_export_" . date("y-m-d_H-i-s") . ".zip"; OC_Log::write('user_migrate',"Creating user export file at: " . $filename,OC_Log::INFO); if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) { exit("Cannot open <$filename>\n"); } // Does the user want to include their files? if (isset($_POST['user_files'])) { // needs to handle data outside of the default data dir. // adding user files OC_Log::write('user_migrate',"Adding owncloud user files of $user to export",OC_Log::INFO); zipAddDir($root . "data/" . $user, $zip, true, "files/"); } // Does the user want their app data? if (isset($_POST['user_appdata'])) { // 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. // Create migration.db 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); } else { // fill template $tmpl = new OC_Template('user_migrate', 'settings'); return $tmpl->fetchPage(); } function zipAddDir($dir, $zip, $recursive=true, $internalDir='') { $dirname = basename($dir); $zip->addEmptyDir($internalDir . $dirname); $internalDir.=$dirname.='/'; if ($dirhandle = opendir($dir)) { while (false !== ( $file = readdir($dirhandle))) { if (( $file != '.' ) && ( $file != '..' )) { if (is_dir($dir . '/' . $file) && $recursive) { zipAddDir($dir . '/' . $file, $zip, $recursive, $internalDir); } elseif (is_file($dir . '/' . $file)) { $zip->addFile($dir . '/' . $file, $internalDir . $file); } } } closedir($dirhandle); } else { OC_Log::write('admin_export',"Was not able to open directory: " . $dir,OC_Log::ERROR); } }