Exemplo n.º 1
0
 public function addsfAsset(sfAsset $l)
 {
     $this->collsfAssets[] = $l;
     $l->setsfAssetFolder($this);
 }
 $sfAssetFolder3->insertAsFirstChildOf($sfAssetFolder2);
 $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->setsfAssetFolder($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->setsfAssetFolder($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();
Exemplo n.º 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();
Exemplo n.º 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());
         }
     }
 }
 $t->is($sfAsset->getFullPath(), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getFullPath() returns the complete asset path on the disk');
 $t->is($sfAsset->getFullPath('small'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail/small_filename.jpg', 'getFullPath(\'small\') returns the complete small thumbnail path on the disk');
 $t->is($sfAsset->getFullPath('large'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail/large_filename.jpg', 'getFullPath(\'large\') returns the complete large thumbnail path on the disk');
 $t->diag('sfAsset::getUrl()');
 $t->is($sfAsset->getUrl(), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getUrl() returns the asset URL');
 $t->is($sfAsset->getUrl('small'), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail/small_filename.jpg', 'getUrl(\'small\') returns the small thumbnail url');
 $t->is($sfAsset->getUrl('large'), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail/large_filename.jpg', 'getUrl(\'large\') returns the large thumbnail url');
 $t->diag('sfAsset::create()');
 $assets_path = dirname(__FILE__) . '/../assets/';
 $test_asset = $assets_path . 'raikkonen.jpg';
 $folder1 = new sfAssetFolder();
 $folder1->insertAsFirstChildOf($root);
 $folder1->setName('Test_Directory');
 $folder1->save();
 $asset1 = new sfAsset();
 $asset1->setsfAssetFolder($folder1);
 $asset1->create($test_asset, false);
 $t->is($asset1->getFilename(), 'raikkonen.jpg', 'create() sets the object filename according to the given asset');
 $t->is($asset1->getFilesize(), 18, 'create() sets the object filesize according to the given asset');
 $t->ok($asset1->isImage(), 'create() sets the object type according to the given asset');
 $t->is($asset1->getUrl(), $folder1->getUrl() . DIRECTORY_SEPARATOR . $asset1->getFilename(), 'create() sets the object url according to the given asset and folder object');
 $t->ok(is_file($asset1->getFullPath()), 'create() physically copies asset');
 $t->ok(is_file($asset1->getFullPath('large')), 'create() physically creates thumbnail');
 $t->diag('sfAsset::move()');
 $old_path = $asset1->getFullPath();
 $old_thumb_path = $asset1->getFullPath('large');
 $asset1->move($root, 'raikkonen2.jpg');
 $t->is($asset1->getFilename(), 'raikkonen2.jpg', 'move() changes filename');
 $t->is($asset1->getUrl(), $root->getUrl() . DIRECTORY_SEPARATOR . $asset1->getFilename(), 'move() changes the object url according to the new folder');
 $t->ok(is_file($asset1->getFullPath()), 'move() physically moves asset to the new location');
 $t->ok(!is_file($old_path), 'move() physically removes asset from the previous location');
include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
$folderProvider = new sfAssetsFolderProvider();
$assetProvider = new sfAssetsProvider();
$databaseManager = new sfDatabaseManager($configuration);
$con = Propel::getConnection();
$con->beginTransaction();
try {
    // prepare test environment
    $folderProvider->doDeleteAll();
    $assetProvider->doDeleteAll();
    sfConfig::set('app_sfAssetsLibrary_upload_dir', 'medias');
    $f = new sfAssetFolder();
    $f->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir'));
    sfAssetFolderPeer::createRoot($f);
    $f->save();
    $t = new lime_test(5, new lime_output_color());
    $t->diag('sfAssetPeer');
    $t->is($assetProvider->retrieveFromUrl(sfAssetFolderPeer::retrieveRoot()->getRelativePath() . '/filename.jpg'), null, '$assetProvider->retrieveFromUrl() returns null when a URL is not found');
    $t->is($assetProvider->exists(sfAssetFolderPeer::retrieveRoot()->getId(), 'filename.jpg'), false, '$assetProvider->exists() returns false when an asset is not found');
    $sfAsset = new sfAsset();
    $sfAsset->setsfAssetFolder(sfAssetFolderPeer::retrieveRoot());
    $sfAsset->setFilename('filename.jpg');
    $sfAsset->save($con);
    $t->is($assetProvider->retrieveFromUrl(sfAssetFolderPeer::retrieveRoot()->getRelativePath() . '/filename.jpg')->getId(), $sfAsset->getId(), '$assetProvider->retrieveFromUrl() finds an asset from its URL');
    $t->is($assetProvider->retrieveFromUrl($sfAsset->getUrl())->getId(), $sfAsset->getId(), '$assetProvider->retrieveFromUrl() finds an asset from the result of `getUrl()`');
    $t->is($assetProvider->exists(sfAssetFolderPeer::retrieveRoot()->getId(), 'filename.jpg'), true, '$assetProvider->exists() returns true when an asset is found');
} catch (Exception $e) {
    echo $e->getMessage();
}
// reset DB
$con->rollBack();
 $sfAsset = new sfAsset();
 $sfAsset->setsfAssetFolder(sfAssetFolderTable::getRoot());
 $t->isa_ok($sfAsset->getsfAssetFolder(), 'sfAssetFolder', 'sfAsset can have root as folder');
 $sfAsset->setFilename('filename.jpg');
 $t->is($sfAsset->getRelativePath(), sfConfig::get('app_sfDoctrineAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getRelativePath() gives correct result');
 sfConfig::set('sf_web_dir', '/tmp');
 sfConfig::set('app_sfDoctrineAssetsLibrary_upload_dir', 'media');
 $t->is($sfAsset->getFullPath(), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfDoctrineAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getFullPath() gives complete path');
 $t->is($sfAsset->getFullPath('large'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfDoctrineAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'thumbnail/large_filename.jpg', 'getFullPath() gives correct thumbnail path');
 $t->is($sfAsset->getUrl(), DIRECTORY_SEPARATOR . sfConfig::get('app_sfDoctrineAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getUrl() gives correct url');
 $t->is($sfAsset->getUrl('small'), DIRECTORY_SEPARATOR . sfConfig::get('app_sfDoctrineAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'thumbnail/small_filename.jpg', 'getUrl() gives correct thumbnail url');
 $assets_path = dirname(__FILE__) . '/../assets/';
 $test_asset = $assets_path . 'raikkonen.jpg';
 $t->ok(is_file($test_asset), 'test asset found');
 $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);