diff options
author | Tom Needham <needham.thomas@gmail.com> | 2012-02-03 20:32:06 +0000 |
---|---|---|
committer | Tom Needham <needham.thomas@gmail.com> | 2012-02-03 20:32:06 +0000 |
commit | 5507db9b15034c73d9a121596da4bf440206f173 (patch) | |
tree | 30cf00274e39beacc546c1b4ba51e42b119cefb3 /apps/user_migrate | |
parent | 6583d30e26d752c5ddccb1e350e075f59b7ba75d (diff) | |
download | nextcloud-server-5507db9b15034c73d9a121596da4bf440206f173.tar.gz nextcloud-server-5507db9b15034c73d9a121596da4bf440206f173.zip |
Initial migration code, and basic export for bookmarks
Diffstat (limited to 'apps/user_migrate')
-rw-r--r-- | apps/user_migrate/appinfo/app.php | 26 | ||||
-rw-r--r-- | apps/user_migrate/appinfo/info.xml | 11 | ||||
-rw-r--r-- | apps/user_migrate/settings.php | 95 | ||||
-rw-r--r-- | apps/user_migrate/templates/settings.php | 12 |
4 files changed, 144 insertions, 0 deletions
diff --git a/apps/user_migrate/appinfo/app.php b/apps/user_migrate/appinfo/app.php new file mode 100644 index 00000000000..4a795a54741 --- /dev/null +++ b/apps/user_migrate/appinfo/app.php @@ -0,0 +1,26 @@ +<?php + +/** +* ownCloud - user_migrate +* +* @author Tom Needham +* @copyright 2012 Tom Needham tom@owncloud.com +* +* 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/>. +* +*/ + +OC_APP::registerPersonal('user_migrate','settings'); + +?>
\ No newline at end of file diff --git a/apps/user_migrate/appinfo/info.xml b/apps/user_migrate/appinfo/info.xml new file mode 100644 index 00000000000..6abcb4af92c --- /dev/null +++ b/apps/user_migrate/appinfo/info.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<info> + <id>user_migrate</id> + <name>User Account Migration</name> + <description>Migrate your user accounts</description> + <version>0.1</version> + <licence>AGPL</licence> + <author>Tom Needham</author> + <require>2</require> + <default_enable/> +</info> diff --git a/apps/user_migrate/settings.php b/apps/user_migrate/settings.php new file mode 100644 index 00000000000..fbf190e37d0 --- /dev/null +++ b/apps/user_migrate/settings.php @@ -0,0 +1,95 @@ +<?php + +/** + * ownCloud - user_migrate + * + * @author Tom Needham + * @copyright 2012 Tom Needham tom@owncloud.com + * + * 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/>. + * + */ +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(); + $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",OC_Log::INFO); + // Call to OC_Migrate for the xml file. + $appdatafile = $tempdir . "/appdata.xml"; + $fh = fopen($appdatafile, 'w'); + $appdata = OC_Migrate::export(OC_User::getUser()); + fwrite($fh, $appdata); + $zip->addFile($appdatafile, "appdata.xml"); + fclose($fh); + } + + $zip->close(); + + header("Content-Type: application/zip"); + header("Content-Disposition: attachment; filename=" . basename($filename)); + header("Content-Length: " . filesize($filename)); + @ob_end_clean(); + 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); + } +} diff --git a/apps/user_migrate/templates/settings.php b/apps/user_migrate/templates/settings.php new file mode 100644 index 00000000000..ece8f70e064 --- /dev/null +++ b/apps/user_migrate/templates/settings.php @@ -0,0 +1,12 @@ +<form id="export" action="#" method="post"> + <fieldset class="personalblock"> + <legend><strong><?php echo $l->t('Export your user account');?></strong></legend> + <p><?php echo $l->t('This will create a compressed file that contains the data of owncloud account. + Please choose which components should be included:');?> + </p> + <p><input type="checkbox" id="user_files" name="user_files" value="true"><label for="user_files"><?php echo $l->t('Files');?></label><br/> + <input type="checkbox" id="user_appdata" name="user_appdata" value="true"><label for="owncloud_system"><?php echo $l->t('User app data');?></label><br/> + </p> + <input type="submit" name="user_migrate" value="Export" /> + </fieldset> +</form> |