settings.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * ownCloud - user_migrate
  4. *
  5. * @author Thomas Schmidt
  6. * @copyright 2011 Thomas Schmidt tom@opensuse.org
  7. * @author Tom Needham
  8. * @copyright 2012 Tom Needham tom@owncloud.com
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public
  21. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. OCP\App::checkAppEnabled('user_migrate');
  25. if (isset($_POST['user_import'])) {
  26. $root = OC::$SERVERROOT . "/";
  27. $importname = "owncloud_import_" . date("y-m-d_H-i-s");
  28. // Save data dir for later
  29. $datadir = OCP\Config::getSystemValue( 'datadirectory' );
  30. // Copy the uploaded file
  31. $from = $_FILES['owncloud_import']['tmp_name'];
  32. $to = get_temp_dir().'/'.$importname.'.zip';
  33. if( !move_uploaded_file( $from, $to ) ){
  34. $error = array('error'=>'Failed to move the uploaded file','hint'=>'Try checking the permissions of the '.get_temp_dir().' dir.');
  35. OCP\Util::writeLog( 'user_migrate', "Failed to copy the uploaded file", OCP\Util::ERROR );
  36. $tmpl = new OCP\Template('user_migrate', 'settings');
  37. $tmpl->assign('error',$error);
  38. //return $tmpl->fetchPage();
  39. }
  40. $response = json_decode( OC_Migrate::import( $to, 'user' ) );
  41. if( !$response->success ){
  42. $error = array('error'=>'There was an error while importing the user!','hint'=>'Please check the logs for a more detailed explaination');
  43. $tmpl = new OCP\Template('user_migrate', 'settings');
  44. $tmpl->assign('error',$error);
  45. //return $tmpl->fetchPage();
  46. } else {
  47. // Check import status
  48. foreach( $response->data as $app => $status ){
  49. if( $status != 'true' ){
  50. // It failed for some reason
  51. if( $status == 'notsupported' ){
  52. $notsupported[] = $app;
  53. } else if( !$status ){
  54. $failed[] = $app;
  55. }
  56. }
  57. }
  58. // Any problems?
  59. if( isset( $notsupported ) || isset( $failed ) ){
  60. if( count( $failed ) > 0 ){
  61. $error = array('error'=>'Some app data failed to import','hint'=>'App data for: '.implode(', ', $failed).' failed to import.');
  62. $tmpl = new OCP\Template('user_migrate', 'settings');
  63. $tmpl->assign('error',$error);
  64. //return $tmpl->fetchPage();
  65. } else if( count( $notsupported ) > 0 ){
  66. $error = array('error'=>'Some app data could not be imported, as the apps are not installed on this instance','hint'=>'App data for: '.implode(', ', $notsupported).' failed to import as they were not found. Please install the apps and try again');
  67. $tmpl = new OCP\Template('user_migrate', 'settings');
  68. $tmpl->assign('error',$error);
  69. //return $tmpl->fetchPage();
  70. }
  71. } else {
  72. // Went swimmingly!
  73. $tmpl = new OCP\Template('user_migrate', 'settings');
  74. //return $tmpl->fetchPage();
  75. }
  76. }
  77. } else {
  78. // fill template
  79. $tmpl = new OCP\Template('user_migrate', 'settings');
  80. return $tmpl->fetchPage();
  81. }