summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-02-03 20:32:06 +0000
committerTom Needham <needham.thomas@gmail.com>2012-02-03 20:32:06 +0000
commit5507db9b15034c73d9a121596da4bf440206f173 (patch)
tree30cf00274e39beacc546c1b4ba51e42b119cefb3
parent6583d30e26d752c5ddccb1e350e075f59b7ba75d (diff)
downloadnextcloud-server-5507db9b15034c73d9a121596da4bf440206f173.tar.gz
nextcloud-server-5507db9b15034c73d9a121596da4bf440206f173.zip
Initial migration code, and basic export for bookmarks
-rw-r--r--apps/admin_export/settings.php7
-rw-r--r--apps/bookmarks/lib/migrate.php18
-rw-r--r--apps/user_migrate/appinfo/app.php26
-rw-r--r--apps/user_migrate/appinfo/info.xml11
-rw-r--r--apps/user_migrate/settings.php95
-rw-r--r--apps/user_migrate/templates/settings.php12
-rw-r--r--lib/migrate.php66
-rw-r--r--lib/migrate/provider.php23
8 files changed, 257 insertions, 1 deletions
diff --git a/apps/admin_export/settings.php b/apps/admin_export/settings.php
index a33c872ccf4..cafd35570c6 100644
--- a/apps/admin_export/settings.php
+++ b/apps/admin_export/settings.php
@@ -5,6 +5,8 @@
*
* @author Thomas Schmidt
* @copyright 2011 Thomas Schmidt tom@opensuse.org
+ * @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
@@ -22,13 +24,15 @@
*/
OC_Util::checkAdminUser();
OC_Util::checkAppEnabled('admin_export');
+
+
if (isset($_POST['admin_export'])) {
$root = OC::$SERVERROOT . "/";
$zip = new ZipArchive();
$filename = get_temp_dir() . "/owncloud_export_" . date("y-m-d_H-i-s") . ".zip";
OC_Log::write('admin_export',"Creating export file at: " . $filename,OC_Log::INFO);
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
- exit("Cannot open <$filename>\n");
+ exit("Cannot open <$filename>\n");
}
if (isset($_POST['owncloud_system'])) {
@@ -49,6 +53,7 @@ if (isset($_POST['admin_export'])) {
}
if (isset($_POST['user_files'])) {
+ // needs to handle data outside of the default data dir.
// adding user files
$zip->addFile($root . '/data/.htaccess', basename($root) . "/data/.htaccess");
$zip->addFile($root . '/data/index.html', basename($root) . "/data/index.html");
diff --git a/apps/bookmarks/lib/migrate.php b/apps/bookmarks/lib/migrate.php
new file mode 100644
index 00000000000..2e6581cd9fa
--- /dev/null
+++ b/apps/bookmarks/lib/migrate.php
@@ -0,0 +1,18 @@
+<?php
+
+class OC_Migrate_Provider_Bookmarks extends OC_Migrate_Provider{
+ $this->appid = 'bookmarks';
+ // Create the xml for the user supplied
+ function export($uid){
+ $xml = '';
+ $query = OC_DB::prepare("SELECT * FROM *PREFIX*bookmarks WHERE *PREFIX*bookmakrs.user_id = ?");
+ $bookmarks = $query->execute($uid);
+ OC_Log::write('user_migrate',print_r($bookmarks));
+ foreach($bookmarks as $bookmark){
+ $xml .= '<bookmark>';
+ $xml .='DATA WILL BE HERE';
+ $xml .= '</bookmark>';
+ }
+ return $xml;
+ }
+}
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>
diff --git a/lib/migrate.php b/lib/migrate.php
new file mode 100644
index 00000000000..8f13d07f468
--- /dev/null
+++ b/lib/migrate.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @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/>.
+ *
+ */
+
+
+/**
+ * provides an interface to all search providers
+ */
+class OC_Migrate{
+ static public $providers=array();
+
+ /**
+ * register a new migration provider
+ * @param OC_Migrate_Provider $provider
+ */
+ public static function registerProvider($provider){
+ self::$providers[]=$provider;
+ }
+
+ /**
+ * export app data for a user
+ * @param string userid
+ * @return string xml of app data
+ */
+ public static function export($uid){
+ $xml = '';
+ foreach(self::$providers as $provider){
+ $xml .= '<app>';
+ $xml .= self::appInfoXML($provider->$appid);
+ $xml .= $provider->export($uid));
+ $xml .= '</app>';
+ }
+ return $xml;
+ }
+
+ /**
+ * generates the app info xml
+ * @param string appid
+ * @return string xml app info
+ */
+ public static function appInfoXML($appid){
+ $info = OC_App::getAppInfo($appid);
+ $xml = '<appinfo>';
+ $zml .= 'INFO HERE';
+ $xml .= '</appinfo>';
+ return $xml;
+ }
+}
diff --git a/lib/migrate/provider.php b/lib/migrate/provider.php
new file mode 100644
index 00000000000..920fde7db39
--- /dev/null
+++ b/lib/migrate/provider.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * provides search functionalty
+ */
+abstract class OC_Migrate_Provider{
+ public function __construct(){
+ OC_Migrate::registerProvider($this);
+ }
+ public static $appid;
+ /**
+ * exports data for apps
+ * @param string $uid
+ * @return string xml data for that app
+ */
+ abstract function export($uid);
+
+ /**
+ * imports data for the app
+ * @param string $query
+ * @return array An array of OC_Search_Result's
+ */
+ abstract function import($data);
+}