Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.

Commit

Permalink
Errors JSON normalization in move action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyco committed Dec 19, 2012
1 parent 70f71af commit 3ee99bb
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions classes/Kohana/Controller/Filebrowser.php
Expand Up @@ -280,7 +280,7 @@ public function action_rename()
* returns JSON `{ok: true}`.
*
* If something's wrong,
* returns JSON `{errors: {filename: <error message>}}`.
* returns JSON `{error: <error message>}`.
*/
public function action_move()
{
Expand All @@ -299,30 +299,33 @@ public function action_move()
if ( ! is_file($from_dir.$file))
{
return $this->response->json(array(
'errors' => array(__('Desired file :file doesn\'t exist', array(':file' => $file)))
'error' => __('Desired file :file doesn\'t exist', array(':file' => $file))
));
}

if (is_file($to_dir.$file))
{
return $this->response->json(array(
'errors' => array(__('File :file already exists in target directory', array(':file' => $file)))
'error' => __('File :file already exists in target directory', array(':file' => $file))
));
}

// If everything's ok
try
if ($from_dir.$file != $to_dir.$file)
{
// Try to rename a file
rename($from_dir.$file, $to_dir.$file);
}
catch (Exception $e)
{
// If something's wrong,
// return error message
return $this->response->json(array(
'error' => array($e->getMessage())
));
// If everything's ok
try
{
// Try to rename a file
rename($from_dir.$file, $to_dir.$file);
}
catch (Exception $e)
{
// If something's wrong,
// return error message
return $this->response->json(array(
'error' => $e->getMessage()
));
}
}

return $this->response->ok();
Expand Down

0 comments on commit 3ee99bb

Please sign in to comment.