Development

/plugins/sfFilesystemFixturesPlugin/branches/0.1/lib/task/sfFilesystemFixturesCleanTask.class.php

You must first sign up to be able to contribute.

root/plugins/sfFilesystemFixturesPlugin/branches/0.1/lib/task/sfFilesystemFixturesCleanTask.class.php

Revision 31447, 2.4 kB (checked in by ezzatron, 3 years ago)

[sfFilesystemFixturesPlugin] added method and task to clean existing fixtures

Line 
1 <?php
2
3 /*
4  * This file is part of the sfFilesystemFixturesPlugin package.
5  * (c) 2010 Erin Millard <emwebdev@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12 * Removes existing filesystem fixture data.
13 *
14 * @package  sfFilesystemFixturesPlugin
15 * @author   Erin Millard <emwebdev@gmail.com>
16 * @version  $Id$
17 */
18 class sfFilesystemFixturesCleanTask extends sfFilesystemFixturesBaseTask
19 {
20   /**
21   * @see sfTask
22   */
23   protected function configure()
24   {
25     $this->addOptions(array(
26       new sfCommandOption('remove-dirs', null, sfCommandOption::PARAMETER_OPTIONAL, 'Remove directories if empty', null),
27       new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null),
28       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
29     ));
30
31     $this->namespace = 'fs-fixtures';
32     $this->name = 'clean';
33     $this->briefDescription = 'Removes existing filesystem fixture data';
34     $this->detailedDescription = <<<EOF
35 The [fs-fixtures:clean|INFO] task removes existing filesystem fixture data:
36
37   [./symfony fs-fixtures:clean|INFO]
38
39 Fixtures from the environment-specific directory will also be removed if present.
40 EOF;
41   }
42
43   /**
44   * @see sfTask
45   */
46   protected function execute($arguments = null, $options = null)
47   {
48     if (null === $options) $options = array();
49     $options = array_merge(array(
50       'remove-dirs' => null,
51     ), $options);
52     $options['remove-dirs'] = $this->translateStringBoolean($options['remove-dirs']);
53
54     $this->cleanDirectory(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fs_fixtures', $options);
55     $this->cleanDirectory(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fs_fixtures_'.sfFilesystemFixtures::getInstance()->getEnvironment(), $options);
56   }
57  
58   /**
59   * Removes files from the filesystem that would be placed there by the filesystem fixtures system
60   *
61   * @param  string  $path     The path containing the filesystem fixtures
62   * @param  array   $options  An array of options
63   */
64   protected function cleanDirectory($path, array $options)
65   {
66     if (!is_dir($path)) return;
67     if (!$path = realpath($path)) return;
68
69     $this->logSection('fs-fixtures', 'Cleaning fs fixtures from "'.$path.'"');
70     sfFilesystemFixtures::getInstance()->cleanDirectory($path, $options['remove-dirs']);
71   }
72 }
Note: See TracBrowser for help on using the browser.