/** * Saves modified object data to the datastore. * If object is saved without left/right values, set them as undefined (0) * * @param PropelPDO Connection to use. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * May be unreliable with parent/children/brother changes * @throws PropelException */ public function save(PropelPDO $con = null) { $left = $this->getLeftValue(); $right = $this->getRightValue(); if (empty($left) || empty($right)) { $root = sfAssetFolderPeer::retrieveRoot($this->getScopeIdValue(), $con); sfAssetFolderPeer::insertAsLastChildOf($this, $root, $con); } return parent::save($con); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); if (sfAssetFolderPeer::retrieveRoot()) { throw new sfException('The asset library already has a root'); } $this->logSection('asset', sprintf('Creating root node at %s...', sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media')), null, 'COMMENT'); $folder = new sfAssetFolder(); $folder->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media')); sfAssetFolderPeer::createRoot($folder); $folder->save(); $this->logSection('asset', 'Root Node Created', null, 'INFO'); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); if (!($rootFolder = sfAssetFolderPeer::retrieveRoot())) { $task = new sfAssetCreateRootTask($this->dispatcher, $this->formatter); $task->setCommandApplication($this->commandApplication); $taskOption = array('--env=' . $options['env'], '--connection=' . $options['connection']); if ($options['application']) { $taskOption[] = '--application=' . $options['application']; } $ret = $task->run(array(), $taskOption); $rootFolder = sfAssetFolderPeer::retrieveRoot(); } $this->logSection('asset', sprintf('Comparing files from %s with assets stored in the database...', $arguments['dirname']), null, 'COMMENT'); try { $rootFolder->synchronizeWith($arguments['dirname'], $options['verbose'], $options['removeOrphanAssets'], $options['removeOrphanFolders']); } catch (sfAssetException $e) { throw new sfException(strtr($e->getMessage(), $e->getMessageParams())); } $this->logSection('asset', 'Synchronization complete', null, 'INFO'); }
/** * Delete root node * * @param PropelPDO $con Connection to use. * @return boolean Deletion status */ public static function deleteRoot($scopeId = null, PropelPDO $con = null) { if (!self::SCOPE_COL) { $scopeId = null; } $root = sfAssetFolderPeer::retrieveRoot($scopeId, $con); if (sfAssetFolderPeer::getNumberOfChildren($root) == 1) { return sfAssetFolderPeer::deleteNode($root, $con); } else { return false; } }
$app = 'frontend'; include dirname(__FILE__) . '/../../../../test/bootstrap/functional.php'; include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php'; $databaseManager = new sfDatabaseManager($configuration); $con = Propel::getConnection(); $con->beginTransaction(); try { // prepare test environment sfAssetFolderPeer::doDeleteAll(); sfAssetPeer::doDeleteAll(); sfConfig::set('app_sfAssetsLibrary_upload_dir', 'mediaTEST'); $f = new sfAssetFolder(); $f->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir')); sfAssetFolderPeer::createRoot($f); $f->save(); $t = new lime_test(5, array('options' => new lime_output_color(), 'error_reporting' => true)); $t->diag('sfAssetPeer'); $t->is(sfAssetPeer::retrieveFromUrl(sfAssetFolderPeer::retrieveRoot()->getRelativePath() . '/filename.jpg'), null, 'sfAssetPeer::retrieveFromUrl() returns null when a URL is not found'); $t->is(sfAssetPeer::exists(sfAssetFolderPeer::retrieveRoot()->getId(), 'filename.jpg'), false, 'sfAssetPeer::exists() returns false when an asset is not found'); $sfAsset = new sfAsset(); $sfAsset->setFolder(sfAssetFolderPeer::retrieveRoot()); $sfAsset->setFilename('filename.jpg'); $sfAsset->save($con); $t->is(sfAssetPeer::retrieveFromUrl(sfAssetFolderPeer::retrieveRoot()->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::retrieveRoot()->getId(), 'filename.jpg'), true, 'sfAssetPeer::exists() returns true when an asset is found'); } catch (Exception $e) { echo $e->getMessage(); } // reset DB $con->rollBack();