예제 #1
0
 /**
  * save all assets
  * @param PropelPDO $con
  */
 protected function doSave($con = null)
 {
     if (null === $con) {
         $con = $this->getConnection();
     }
     for ($i = 1; $i <= $this->getOption('size'); $i++) {
         if ($file = $this->getValue('file_' . $i)) {
             $asset = new sfAsset();
             $asset->setFolderId($this->getValue('folder_id'));
             $asset->setDescription($file->getOriginalName());
             $asset->setAuthor($this->getOption('author'));
             $asset->setFilename($file->getOriginalName());
             $asset->create($file->getTempName());
             $asset->save();
             $this->assets[] = $asset;
         }
     }
 }
 $sfAssetFolder3->setName('Test_Sub-sub-directory');
 $sfAssetFolder3->save();
 $t->is($sfAssetFolder3->getRelativePath(), $sfAssetFolder2->getRelativePath() . '/' . $sfAssetFolder3->getName(), 'getRelativePath() returns the folder relative path, including its ancestors names');
 $id3 = $sfAssetFolder3->getId();
 # $sfAsset is /root/Test_Directory/Test_Sub-directory/raikkonen.jpg
 $assets_path = dirname(__FILE__) . '/../assets/';
 $test_asset = $assets_path . 'raikkonen.jpg';
 $sfAsset = new sfAsset();
 $sfAsset->setFolder($sfAssetFolder2);
 $sfAsset->create($test_asset, false);
 $sfAsset->save();
 $sf_asset_id = $sfAsset->getId();
 # $sfAsset2 is /root/Test_Directory/Test_Sub-directory/Test_Sub-sub-directory/toto
 $sfAsset2 = new sfAsset();
 $sfAsset2->setFolder($sfAssetFolder3);
 $sfAsset2->setFilename('toto');
 $sfAsset2->create($test_asset, false);
 $sfAsset2->save();
 $sf_asset2_id = $sfAsset2->getId();
 # So now we have:
 # root/
 #   Test_Directory/               sfAssetFolder
 #     Test_Sub-directory/         sfAssetFolder2
 #       Test_Sub-sub-directory/   sfAssetFolder3
 #         toto
 #       raikkonen.jpg
 $t->diag('sfAssetFolder::move()');
 # move $sfAssetFolder2 from /root/Test_Directory/Test_Sub-directory to /root/Test_Sub-directory
 $sfAssetFolder2->move($root);
 $sfAssetFolder2->save();
 # So now we have:
예제 #3
0
<?php

$app = "frontend";
include dirname(__FILE__) . '/../../../../test/bootstrap/functional.php';
$browser = new sfTestBrowser();
$browser->initialize();
$con = Propel::getConnection();
$con->begin();
try {
    $t = new lime_test(5, new lime_output_color());
    $t->diag('sfAssetPeer');
    $con->begin();
    $t->is(sfAssetPeer::retrieveFromUrl(sfAssetFolderPeer::getRoot()->getRelativePath() . '/filename.jpg'), null, 'sfAssetPeer::retrieveFromUrl() returns null when a URL is not found');
    $t->is(sfAssetPeer::exists(sfAssetFolderPeer::getRoot()->getId(), 'filename.jpg'), false, 'sfAssetPeer::exists() returns false when an asset is not found');
    $sfAsset = new sfAsset();
    $sfAsset->setsfAssetFolder(sfAssetFolderPeer::getRoot());
    $sfAsset->setFilename('filename.jpg');
    $sfAsset->save($con);
    $t->is(sfAssetPeer::retrieveFromUrl(sfAssetFolderPeer::getRoot()->getRelativePath() . '/filename.jpg')->getId(), $sfAsset->getId(), 'sfAssetPeer::retrieveFromUrl() finds an asset from its URL');
    $t->is(sfAssetPeer::retrieveFromUrl($sfAsset->getUrl())->getId(), $sfAsset->getId(), 'sfAssetPeer::retrieveFromUrl() finds an asset from the result of `getUrl()`');
    $t->is(sfAssetPeer::exists(sfAssetFolderPeer::getRoot()->getId(), 'filename.jpg'), true, 'sfAssetPeer::exists() returns true when an asset is found');
} catch (Exception $e) {
    echo $e->getMessage();
}
// reset DB
$con->rollback();
예제 #4
0
 public function executeMassUpload()
 {
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $folder = sfAssetFolderPeer::retrieveByPath($this->getRequestParameter('parent_folder'));
         $this->forward404Unless($folder);
         try {
             $nbFiles = 0;
             for ($i = 1; $i <= sfConfig::get('app_sfAssetsLibrary_mass_upload_size', 5); $i++) {
                 if ($filename = $this->getRequest()->getFileName('files[' . $i . ']')) {
                     $asset = new sfAsset();
                     $asset->setsfAssetFolder($folder);
                     $asset->setDescription($filename);
                     try {
                         $asset->setAuthor($this->getUser()->getUsername());
                     } catch (sfException $e) {
                         // no getUsername() method in sfUser, all right: do nothing
                     }
                     $asset->setFilename($filename);
                     $asset->create($this->getRequest()->getFilePath('files[' . $i . ']'));
                     $asset->save();
                     $nbFiles++;
                 }
             }
         } catch (sfAssetException $e) {
             $this->setFlash('warning_message', $e->getMessage());
             $this->setFlash('warning_params', $e->getMessageParams());
             $this->redirectToPath('sfAsset/list?dir=' . $folder->getRelativePath());
         }
         $this->setFlash('notice', 'Files successfully uploaded');
         $this->redirectToPath('sfAsset/list?dir=' . $folder->getRelativePath());
     }
 }
 /**
  * upload many assets
  * @param sfWebRequest $request
  */
 public function executeMassUpload(sfWebRequest $request)
 {
     $this->form = new sfAssetsForm(null, array('size' => sfConfig::get('app_sfAssetsLibrary_mass_upload_size', 5)));
     if ($request->getMethod() == sfRequest::POST) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             $folder = sfAssetFolderPeer::retrieveByPK($this->form->getValue('folder_id'));
             $this->forward404Unless($folder, 'folder not found');
             try {
                 $nbFiles = 0;
                 for ($i = 1; $i <= sfConfig::get('app_sfAssetsLibrary_mass_upload_size', 5); $i++) {
                     if ($file = $this->form->getValue('file_' . $i)) {
                         $asset = new sfAsset();
                         $asset->setsfAssetFolder($folder);
                         $asset->setDescription($file->getOriginalName());
                         try {
                             $asset->setAuthor($this->getUser()->getUsername());
                         } catch (sfException $e) {
                             // no getUsername() method in sfUser, all right: do nothing
                         }
                         $asset->setFilename($file->getOriginalName());
                         $asset->create($file->getTempName());
                         $asset->save();
                         $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $asset)));
                         $nbFiles++;
                     }
                 }
             } catch (sfAssetException $e) {
                 $this->getUser()->setFlash('warning_message', $e->getMessage());
                 $this->getUser()->setFlash('warning_params', $e->getMessageParams());
                 $this->redirectToPath('@sf_asset_library_dir?dir=' . $folder->getRelativePath());
             }
             $this->getUser()->setFlash('notice', 'Files successfully uploaded');
             $this->redirectToPath('@sf_asset_library_dir?dir=' . $folder->getRelativePath());
         }
     }
 }
 $sfAsset = new sfAsset();
 $sfAsset->setsfAssetFolder(sfAssetFolderTable::getRoot());
 $sfAsset->createAsset($test_asset, false);
 $t->is($sfAsset->getFilename(), 'raikkonen.jpg', 'create() gives correct filename');
 $t->is((int) $sfAsset->getFilesize(), 18, 'create() gives correct size');
 $t->ok($sfAsset->isImage(), 'create() gives correct type');
 $t->ok(is_file($sfAsset->getFullPath()), 'create() physically copies asset');
 if ($sfAsset->supportsThumbnails()) {
     $t->ok(is_file($sfAsset->getFullPath('large')), 'create() physically creates thumbnail');
 } else {
     $t->diag('please activate thumbnails support');
 }
 $old_path = $sfAsset->getFullPath();
 $old_thumb_path = $sfAsset->getFullPath('large');
 $sfAsset->save($doctrine_conn);
 $sfAsset->setFilename('raikkonen2.jpg');
 $sfAsset->save($doctrine_conn);
 $t->is($sfAsset->getFilename(), 'raikkonen2.jpg', 'move() changes filename');
 $t->ok(is_file($sfAsset->getFullPath()), 'move() physically moves asset');
 $t->ok(!is_file($old_path), 'move() physically moves asset');
 if ($sfAsset->supportsThumbnails()) {
     $t->ok(is_file($sfAsset->getFullPath('large')), 'move() physically moves thumbnail');
     $t->ok(!is_file($old_thumb_path), 'move() physically moves thumbnail');
 } else {
     $t->diag('please activate thumbnails support');
 }
 $old_path = $sfAsset->getFullPath();
 $old_thumb_path = $sfAsset->getFullPath('large');
 $old_id = $sfAsset->getId();
 $sfAsset->delete();
 $t->ok(!is_file($old_path), 'delete() physically removes asset');