public function setFilename($filename)
 {
     $filename = sfAssetsLibraryTools::sanitizeName($filename);
     if (sfAssetsLibraryTools::sanitizeName($filename) != $filename) {
         throw new sfAssetException('The filename "%name%" contains incorrect characters. The asset has not be altered.', array('%name%' => $new_filename));
     }
     if (is_null($this->old_locations) && $this->exists()) {
         $this->old_locations = $this->getFilepaths();
     }
     return $this->_set('filename', $filename);
 }
Ejemplo n.º 2
0
 /**
  * Change asset directory and/or name
  *
  * @param sfAssetFolder $newFolder
  * @param string        $newFilename
  */
 public function move(sfAssetFolder $newFolder, $newFilename = null)
 {
     if (sfAssetPeer::exists($newFolder->getId(), $newFilename ? $newFilename : $this->getFilename())) {
         throw new sfAssetException('The target folder "%folder%" already contains an asset named "%name%". The asset has not been moved.', array('%folder%' => $newFolder->getName(), '%name%' => $newFilename ? $newFilename : $this->getFilename()));
     }
     $oldFilepaths = $this->getFilepaths();
     if ($newFilename) {
         if (sfAssetsLibraryTools::sanitizeName($newFilename) != $newFilename) {
             throw new sfAssetException('The filename "%name%" contains incorrect characters. The asset has not be altered.', array('%name%' => $newFilename));
         }
         $this->setFilename($newFilename);
     }
     $this->setFolderId($newFolder->getId());
     $success = true;
     foreach ($oldFilepaths as $type => $filepath) {
         $success = rename($filepath, $this->getFullPath($type)) && $success;
     }
     if (!$success) {
         throw new sfAssetException('Some or all of the file operations failed. It is possible that the moved asset or its thumbnails are missing.');
     }
 }
 /**
  * Change folder name
  *
  * @param string $name
  */
 private function rename()
 {
     if ($this->hasSibling($this->getName())) {
         throw new sfAssetException('The parent folder already contains a folder named "%name%". The folder has not been renamed.', array('%name%' => $this->getName()));
     }
     if (sfAssetsLibraryTools::sanitizeName($this->getName()) != $this->getName()) {
         throw new sfAssetException('The target folder name "%name%" contains incorrect characters. The folder has not be renamed.', array('%name%' => $this->getName()));
     }
     $new_path = $this->getFullPath();
     $old_path = $this->old_path;
     // move its assets
     self::movePhysically($old_path, $new_path);
     if ($this->getNode()->hasChildren()) {
         $children = $this->getNode()->getChildren();
         foreach ($children as $descendant) {
             $descendant->save();
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Change folder name
  *
  * @param string $name
  */
 public function rename($name)
 {
     if ($this->retrieveParent()->hasSubFolder($name)) {
         throw new sfAssetException('The parent folder already contains a folder named "%name%". The folder has not been renamed.', array('%name%' => $name));
     } else {
         if ($name !== $this->getName()) {
             if (sfAssetsLibraryTools::sanitizeName($name) != $name) {
                 throw new sfAssetException('The target folder name "%name%" contains incorrect characters. The folder has not be renamed.', array('%name%' => $name));
             }
             $old_path = $this->getFullPath();
             $this->setName($name);
             $this->save();
             // move its assets
             self::movePhysically($old_path, $this->getFullPath());
             foreach ($this->getDescendants() as $descendant) {
                 $descendant->save();
             }
         }
     }
     // else: nothing to do
 }