admin.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * ownCloud - user_migrate
  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. OCP\User::checkAdminUser();
  23. OCP\App::checkAppEnabled('user_migrate');
  24. // Import?
  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', 'admin');
  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', 'admin');
  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', 'admin');
  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', 'admin');
  68. $tmpl->assign('error',$error);
  69. return $tmpl->fetchPage();
  70. }
  71. } else {
  72. // Went swimmingly!
  73. $tmpl = new OCP\Template('user_migrate', 'admin');
  74. return $tmpl->fetchPage();
  75. }
  76. }
  77. } else {
  78. // fill template
  79. $tmpl = new OCP\Template('user_migrate', 'admin');
  80. return $tmpl->fetchPage();
  81. }