You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * ownCloud - Core
  4. *
  5. * @author Morris Jobke
  6. * @copyright 2013 Morris Jobke morris.jobke@gmail.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. namespace OCA\Files;
  23. class App {
  24. /**
  25. * @var \OC_L10N
  26. */
  27. private $l10n;
  28. /**
  29. * @var \OC\Files\View
  30. */
  31. private $view;
  32. public function __construct($view, $l10n) {
  33. $this->view = $view;
  34. $this->l10n = $l10n;
  35. }
  36. /**
  37. * rename a file
  38. *
  39. * @param string $dir
  40. * @param string $oldname
  41. * @param string $newname
  42. * @return array
  43. */
  44. public function rename($dir, $oldname, $newname) {
  45. $result = array(
  46. 'success' => false,
  47. 'data' => NULL
  48. );
  49. // rename to non-existing folder is denied
  50. if (!$this->view->file_exists($dir)) {
  51. $result['data'] = array('message' => (string)$this->l10n->t(
  52. 'The target folder has been moved or deleted.',
  53. array($dir)),
  54. 'code' => 'targetnotfound'
  55. );
  56. // rename to existing file is denied
  57. } else if ($this->view->file_exists($dir . '/' . $newname)) {
  58. $result['data'] = array(
  59. 'message' => $this->l10n->t(
  60. "The name %s is already used in the folder %s. Please choose a different name.",
  61. array($newname, $dir))
  62. );
  63. } else if (
  64. // rename to "." is denied
  65. $newname !== '.' and
  66. // THEN try to rename
  67. $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname)
  68. ) {
  69. // successful rename
  70. $meta = $this->view->getFileInfo($dir . '/' . $newname);
  71. $fileinfo = \OCA\Files\Helper::formatFileInfo($meta);
  72. $result['success'] = true;
  73. $result['data'] = $fileinfo;
  74. } else {
  75. // rename failed
  76. $result['data'] = array(
  77. 'message' => $this->l10n->t('%s could not be renamed', array($oldname))
  78. );
  79. }
  80. return $result;
  81. }
  82. }