Merge pull request #235 from owncloud/fix58
Make rename behavior consistent with files app
This commit is contained in:
		
						commit
						0f5f65b6f4
					
				@ -70,14 +70,19 @@ class DocumentController extends Controller{
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	public static function rename($args){
 | 
			
		||||
		$uid = self::preDispatch();
 | 
			
		||||
		
 | 
			
		||||
		$fileId = intval(@$args['file_id']);
 | 
			
		||||
		$name = @$_POST['name'];
 | 
			
		||||
		$file = new File($fileId);
 | 
			
		||||
		
 | 
			
		||||
		$view = \OC\Files\Filesystem::getView();
 | 
			
		||||
		$path = $view->getPath($fileId);
 | 
			
		||||
		
 | 
			
		||||
		$l = new \OC_L10n('documents');
 | 
			
		||||
 | 
			
		||||
		if (isset($name) && $file->getPermissions() & \OCP\PERMISSION_UPDATE) {
 | 
			
		||||
			if ($file->renameTo($name)) {
 | 
			
		||||
				// TODO: propagate to other clients
 | 
			
		||||
		if (isset($name) && $view->is_file($path) && $view->isUpdatable($path)) {
 | 
			
		||||
			$newPath = dirname($path) . '/' . $name;
 | 
			
		||||
			if ($view->rename($path, $newPath)) {
 | 
			
		||||
				\OCP\JSON::success();
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								lib/file.php
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								lib/file.php
									
									
									
									
									
								
							@ -151,16 +151,6 @@ class File {
 | 
			
		||||
		return $permissions;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Rename this file to the given name
 | 
			
		||||
	 * @param string $newName name to give (without path)
 | 
			
		||||
	 * @return boolean true if rename succeeded, false otherwise
 | 
			
		||||
	 */
 | 
			
		||||
	public function renameTo($newName) {
 | 
			
		||||
		list($owner, $path) = $this->getOwnerViewAndPath();
 | 
			
		||||
		$newPath = dirname($path) . '/' . $newName;
 | 
			
		||||
		return \OC\Files\Filesystem::rename($path, $newPath);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * 
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user