Development

Changeset 31444

You must first sign up to be able to contribute.

Changeset 31444

Show
Ignore:
Timestamp:
11/19/10 04:38:38 (3 years ago)
Author:
ezzatron
Message:

[sfFilesystemFixturesPlugin] do not overwrite files by default

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfFilesystemFixturesPlugin/branches/0.1/lib/sfFilesystemFixtures.class.php

    r31442 r31444  
    3838  * Copies files from the filesystem fixtures directory to their intended locations 
    3939  *  
    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) 
    4243  */ 
    43   public function processDirectory($path, $rootPath = null) 
     44  public function processDirectory($path, $overwrite = null, $rootPath = null) 
    4445  { 
    4546    if (!is_dir($path)) return; 
     
    6061        if (!file_exists($toPath)) mkdir($toPath, 0777, true); 
    6162         
    62         self::processDirectory($fromPath, $rootPath); 
     63        self::processDirectory($fromPath, $overwrite, $rootPath); 
    6364      } 
    6465      else 
    6566      { 
     67        if (!$overwrite && file_exists($toPath)) continue; 
     68         
    6669        copy($fromPath, $toPath); 
    6770      } 
  • plugins/sfFilesystemFixturesPlugin/branches/0.1/lib/task/sfFilesystemFixturesLoadTask.class.php

    r31443 r31444  
    2424  { 
    2525    $this->addOptions(array( 
     26      new sfCommandOption('overwrite', null, sfCommandOption::PARAMETER_OPTIONAL, 'Overwrite existing files', null), 
    2627      new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null), 
    2728      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), 
     
    4344  * @see sfTask 
    4445  */ 
    45   protected function execute($arguments = array(), $options = array()
     46  protected function execute($arguments = null, $options = null
    4647  { 
    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; 
    4979  } 
    5080   
     
    5282  * Copies files from the filesystem fixtures directory to their intended locations 
    5383  *  
    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 
    5586  */ 
    56   protected function processDirectory($path
     87  protected function processDirectory($path, array $options
    5788  { 
    5889    if (!is_dir($path)) return; 
    5990    if (!$path = realpath($path)) return; 
    60      
     91 
    6192    $this->logSection('fs-fixtures', 'Loading fs fixtures from "'.$path.'"'); 
    62     sfFilesystemFixtures::getInstance()->processDirectory($path); 
     93    sfFilesystemFixtures::getInstance()->processDirectory($path, $options['overwrite']); 
    6394  } 
    6495}