Merge pull request #16718 from owncloud/files-catchajaxexceptions
Catch exceptions in files ajax calls
This commit is contained in:
commit
ccbb1cce3c
|
@ -54,10 +54,15 @@ $success = true;
|
|||
|
||||
//Now delete
|
||||
foreach ($files as $file) {
|
||||
if (\OC\Files\Filesystem::file_exists($dir . '/' . $file) &&
|
||||
!(\OC\Files\Filesystem::isDeletable($dir . '/' . $file) &&
|
||||
\OC\Files\Filesystem::unlink($dir . '/' . $file))
|
||||
) {
|
||||
try {
|
||||
if (\OC\Files\Filesystem::file_exists($dir . '/' . $file) &&
|
||||
!(\OC\Files\Filesystem::isDeletable($dir . '/' . $file) &&
|
||||
\OC\Files\Filesystem::unlink($dir . '/' . $file))
|
||||
) {
|
||||
$filesWithError .= $file . "\n";
|
||||
$success = false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$filesWithError .= $file . "\n";
|
||||
$success = false;
|
||||
}
|
||||
|
|
|
@ -78,10 +78,21 @@ $templateManager = OC_Helper::getFileTemplateManager();
|
|||
$mimeType = OC_Helper::getMimetypeDetector()->detectPath($target);
|
||||
$content = $templateManager->getTemplate($mimeType);
|
||||
|
||||
if($content) {
|
||||
$success = \OC\Files\Filesystem::file_put_contents($target, $content);
|
||||
} else {
|
||||
$success = \OC\Files\Filesystem::touch($target);
|
||||
try {
|
||||
if($content) {
|
||||
$success = \OC\Files\Filesystem::file_put_contents($target, $content);
|
||||
} else {
|
||||
$success = \OC\Files\Filesystem::touch($target);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$result = [
|
||||
'success' => false,
|
||||
'data' => [
|
||||
'message' => $e->getMessage()
|
||||
]
|
||||
];
|
||||
OCP\JSON::error($result);
|
||||
exit();
|
||||
}
|
||||
|
||||
if($success) {
|
||||
|
|
|
@ -74,15 +74,26 @@ if (\OC\Files\Filesystem::file_exists($target)) {
|
|||
exit();
|
||||
}
|
||||
|
||||
if(\OC\Files\Filesystem::mkdir($target)) {
|
||||
if ( $dir !== '/') {
|
||||
$path = $dir.'/'.$folderName;
|
||||
} else {
|
||||
$path = '/'.$folderName;
|
||||
try {
|
||||
if(\OC\Files\Filesystem::mkdir($target)) {
|
||||
if ( $dir !== '/') {
|
||||
$path = $dir.'/'.$folderName;
|
||||
} else {
|
||||
$path = '/'.$folderName;
|
||||
}
|
||||
$meta = \OC\Files\Filesystem::getFileInfo($path);
|
||||
$meta['type'] = 'dir'; // missing ?!
|
||||
OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
|
||||
exit();
|
||||
}
|
||||
$meta = \OC\Files\Filesystem::getFileInfo($path);
|
||||
$meta['type'] = 'dir'; // missing ?!
|
||||
OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
|
||||
} catch (\Exception $e) {
|
||||
$result = [
|
||||
'success' => false,
|
||||
'data' => [
|
||||
'message' => $e->getMessage()
|
||||
]
|
||||
];
|
||||
OCP\JSON::error($result);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,15 +29,26 @@ OCP\JSON::checkLoggedIn();
|
|||
OCP\JSON::callCheck();
|
||||
\OC::$server->getSession()->close();
|
||||
|
||||
$l10n = \OC::$server->getL10N('files');
|
||||
|
||||
$files = new \OCA\Files\App(
|
||||
\OC\Files\Filesystem::getView(),
|
||||
\OC::$server->getL10N('files')
|
||||
);
|
||||
$result = $files->rename(
|
||||
isset($_GET['dir']) ? (string)$_GET['dir'] : '',
|
||||
isset($_GET['file']) ? (string)$_GET['file'] : '',
|
||||
isset($_GET['newname']) ? (string)$_GET['newname'] : ''
|
||||
);
|
||||
try {
|
||||
$result = $files->rename(
|
||||
isset($_GET['dir']) ? (string)$_GET['dir'] : '',
|
||||
isset($_GET['file']) ? (string)$_GET['file'] : '',
|
||||
isset($_GET['newname']) ? (string)$_GET['newname'] : ''
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$result = [
|
||||
'success' => false,
|
||||
'data' => [
|
||||
'message' => $e->getMessage()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
if($result['success'] === true){
|
||||
OCP\JSON::success(['data' => $result['data']]);
|
||||
|
|
Loading…
Reference in New Issue