Changeset 31444
- Timestamp:
- 11/19/10 04:38:38 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfFilesystemFixturesPlugin/branches/0.1/lib/sfFilesystemFixtures.class.php
r31442 r31444 38 38 * Copies files from the filesystem fixtures directory to their intended locations 39 39 * 40 * @param string $path The path containing the filesystem fixtures 41 * @param string $rootPath The root path (used for recursion) 40 * @param string $path The path containing the filesystem fixtures 41 * @param boolean $overwrite Whether to overwrite files if present 42 * @param string $rootPath The root path (used for recursion) 42 43 */ 43 public function processDirectory($path, $ rootPath = null)44 public function processDirectory($path, $overwrite = null, $rootPath = null) 44 45 { 45 46 if (!is_dir($path)) return; … … 60 61 if (!file_exists($toPath)) mkdir($toPath, 0777, true); 61 62 62 self::processDirectory($fromPath, $ rootPath);63 self::processDirectory($fromPath, $overwrite, $rootPath); 63 64 } 64 65 else 65 66 { 67 if (!$overwrite && file_exists($toPath)) continue; 68 66 69 copy($fromPath, $toPath); 67 70 } plugins/sfFilesystemFixturesPlugin/branches/0.1/lib/task/sfFilesystemFixturesLoadTask.class.php
r31443 r31444 24 24 { 25 25 $this->addOptions(array( 26 new sfCommandOption('overwrite', null, sfCommandOption::PARAMETER_OPTIONAL, 'Overwrite existing files', null), 26 27 new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null), 27 28 new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), … … 43 44 * @see sfTask 44 45 */ 45 protected function execute($arguments = array(), $options = array())46 protected function execute($arguments = null, $options = null) 46 47 { 47 $this->processDirectory(sfConfig::get('sf_data_dir').'/fs_fixtures'); 48 $this->processDirectory(sfConfig::get('sf_data_dir').'/fs_fixtures_'.sfFilesystemFixtures::getInstance()->getEnvironment()); 48 if (null === $options) $options = array(); 49 $options = array_merge(array( 50 'overwrite' => null, 51 ), $options); 52 $options['overwrite'] = $this->translateStringBoolean($options['overwrite']); 53 54 $this->processDirectory(sfConfig::get('sf_data_dir').'/fs_fixtures', $options); 55 $this->processDirectory(sfConfig::get('sf_data_dir').'/fs_fixtures_'.sfFilesystemFixtures::getInstance()->getEnvironment(), $options); 56 } 57 58 /** 59 * Translates a string into the equivalent boolean value 60 * 61 * @param string $value The string value 62 * 63 * @return boolean The boolean equivalent 64 */ 65 protected function translateStringBoolean($value) 66 { 67 if (null === $value || 'null' === $value) return null; 68 69 $falseValues = array( 70 'no', 71 'off', 72 'false', 73 ); 74 75 if (!$value) return false; 76 if (in_array(strtolower($value), $falseValues)) return false; 77 78 return true; 49 79 } 50 80 … … 52 82 * Copies files from the filesystem fixtures directory to their intended locations 53 83 * 54 * @param string $path The path containing the filesystem fixtures 84 * @param string $path The path containing the filesystem fixtures 85 * @param array $options An array of options 55 86 */ 56 protected function processDirectory($path )87 protected function processDirectory($path, array $options) 57 88 { 58 89 if (!is_dir($path)) return; 59 90 if (!$path = realpath($path)) return; 60 91 61 92 $this->logSection('fs-fixtures', 'Loading fs fixtures from "'.$path.'"'); 62 sfFilesystemFixtures::getInstance()->processDirectory($path );93 sfFilesystemFixtures::getInstance()->processDirectory($path, $options['overwrite']); 63 94 } 64 95 }