/**
  * @inheritDoc BaseAssetSourceType::renameSourceFolder()
  *
  * @param AssetFolderModel $folder
  * @param                  $newName
  *
  * @return bool
  */
 protected function renameSourceFolder(AssetFolderModel $folder, $newName)
 {
     $newFullPath = $this->_getPathPrefix() . IOHelper::getParentFolderPath($folder->path) . $newName . '/';
     $this->_prepareForRequests();
     $bucket = $this->getSettings()->bucket;
     $filesToMove = $this->_s3->getBucket($bucket, $this->_getPathPrefix() . $folder->path);
     rsort($filesToMove);
     foreach ($filesToMove as $file) {
         $filePath = mb_substr($file['name'], mb_strlen($this->_getPathPrefix() . $folder->path));
         $this->_s3->copyObject($bucket, $file['name'], $bucket, $newFullPath . $filePath, \S3::ACL_PUBLIC_READ);
         @$this->_s3->deleteObject($bucket, $file['name']);
     }
     return true;
 }
 /**
  * @inheritDoc BaseAssetSourceType::renameSourceFolder()
  *
  * @param AssetFolderModel $folder
  * @param string           $newName
  *
  * @return bool
  */
 protected function renameSourceFolder(AssetFolderModel $folder, $newName)
 {
     $newFullPath = IOHelper::getParentFolderPath($folder->path) . $newName . '/';
     return IOHelper::rename($this->getSourceFileSystemPath() . $folder->path, $this->getSourceFileSystemPath() . $newFullPath);
 }
 /**
  * Rename a folder.
  *
  * @param AssetFolderModel $folder  The assetFolderModel representing the name of the folder to rename.
  * @param string           $newName The new name of the folder.
  *
  * @throws Exception
  * @return AssetOperationResponseModel
  */
 public function renameFolder(AssetFolderModel $folder, $newName)
 {
     $parentFolder = craft()->assets->getFolderById($folder->parentId);
     if (!$parentFolder) {
         throw new Exception(Craft::t("Cannot rename folder “{folder}”!", array('folder' => $folder->name)));
     }
     // Allow this for changing the case
     if (!(StringHelper::toLowerCase($newName) == StringHelper::toLowerCase($folder->name)) && $this->folderExists($parentFolder, $newName)) {
         throw new Exception(Craft::t("Folder “{folder}” already exists there.", array('folder' => $newName)));
     }
     // Try to rename the folder in the source
     if (!$this->renameSourceFolder($folder, $newName)) {
         throw new Exception(Craft::t("Cannot rename folder “{folder}”!", array('folder' => $folder->name)));
     }
     $oldFullPath = $folder->path;
     $newFullPath = IOHelper::getParentFolderPath($folder->path) . $newName . '/';
     // Find all folders with affected fullPaths and update them.
     $folders = craft()->assets->getAllDescendantFolders($folder);
     foreach ($folders as $folderModel) {
         $folderModel->path = preg_replace('#^' . $oldFullPath . '#', $newFullPath, $folderModel->path);
         craft()->assets->storeFolder($folderModel);
     }
     // Now change the affected folder
     $folder->name = $newName;
     $folder->path = $newFullPath;
     craft()->assets->storeFolder($folder);
     // All set, Scotty!
     $response = new AssetOperationResponseModel();
     return $response->setSuccess()->setDataItem('newName', $newName);
 }
 /**
  * @inheritDoc BaseAssetSourceType::renameSourceFolder()
  *
  * @param AssetFolderModel $folder
  * @param string           $newName
  *
  * @return bool
  */
 protected function renameSourceFolder(AssetFolderModel $folder, $newName)
 {
     $newFullPath = $this->_getPathPrefix() . IOHelper::getParentFolderPath($folder->path) . $newName . '/';
     $objectList = $this->_getFileList($this->_getPathPrefix() . $folder->path);
     $filesToMove = array();
     foreach ($objectList as $object) {
         $filesToMove[$object->name] = $object;
     }
     krsort($filesToMove);
     foreach ($filesToMove as $file) {
         $filePath = mb_substr($file->name, mb_strlen($this->_getPathPrefix() . $folder->path));
         $sourceUri = $this->_prepareRequestURI($this->getSettings()->container, $file->name);
         $targetUri = $this->_prepareRequestURI($this->getSettings()->container, $newFullPath . $filePath);
         $this->_copyFile($sourceUri, $targetUri);
         $this->_deleteObject($sourceUri);
     }
     // This may or may not exist.
     $this->_deleteObject($this->_prepareRequestURI($this->getSettings()->container, $this->_getPathPrefix() . rtrim($folder->path, '/')));
     return true;
 }