| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
require_once(dirname(__FILE__).'/sfPluginBaseTask.class.php'); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class sfPluginPublishAssetsTask extends sfPluginBaseTask |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
* @see sfTask |
|---|
| 25 |
*/ |
|---|
| 26 |
protected function configure() |
|---|
| 27 |
{ |
|---|
| 28 |
$this->addArguments(array( |
|---|
| 29 |
new sfCommandArgument('plugins', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'Publish this plugin\'s assets'), |
|---|
| 30 |
)); |
|---|
| 31 |
|
|---|
| 32 |
$this->addOptions(array( |
|---|
| 33 |
new sfCommandOption('core-only', '', sfCommandOption::PARAMETER_NONE, 'If set only core plugins will publish their assets'), |
|---|
| 34 |
)); |
|---|
| 35 |
|
|---|
| 36 |
$this->aliases = array(); |
|---|
| 37 |
$this->namespace = 'plugin'; |
|---|
| 38 |
$this->name = 'publish-assets'; |
|---|
| 39 |
|
|---|
| 40 |
$this->briefDescription = 'Publishes web assets for all plugins'; |
|---|
| 41 |
|
|---|
| 42 |
$this->detailedDescription = <<<EOF |
|---|
| 43 |
The [plugin:publish-assets|INFO] task will publish web assets from all plugins. |
|---|
| 44 |
|
|---|
| 45 |
[./symfony plugin:publish-assets|INFO] |
|---|
| 46 |
|
|---|
| 47 |
In fact this will send the [plugin.post_install|INFO] event to each plugin. |
|---|
| 48 |
|
|---|
| 49 |
You can specify which plugin or plugins should install their assets by passing |
|---|
| 50 |
those plugins' names as arguments: |
|---|
| 51 |
|
|---|
| 52 |
[./symfony plugin:publish-assets sfDoctrinePlugin|INFO] |
|---|
| 53 |
EOF; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
* @see sfTask |
|---|
| 58 |
*/ |
|---|
| 59 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 60 |
{ |
|---|
| 61 |
$enabledPlugins = $this->configuration->getPlugins(); |
|---|
| 62 |
|
|---|
| 63 |
if ($diff = array_diff($arguments['plugins'], $enabledPlugins)) |
|---|
| 64 |
{ |
|---|
| 65 |
throw new InvalidArgumentException('Plugin(s) not found: '.join(', ', $diff)); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
if ($options['core-only']) |
|---|
| 69 |
{ |
|---|
| 70 |
$corePlugins = sfFinder::type('dir')->relative()->maxdepth(0)->in($this->configuration->getSymfonyLibDir().'/plugins'); |
|---|
| 71 |
$arguments['plugins'] = array_unique(array_merge($arguments['plugins'], array_intersect($enabledPlugins, $corePlugins))); |
|---|
| 72 |
} |
|---|
| 73 |
else if (!count($arguments['plugins'])) |
|---|
| 74 |
{ |
|---|
| 75 |
$arguments['plugins'] = $enabledPlugins; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
foreach ($arguments['plugins'] as $plugin) |
|---|
| 79 |
{ |
|---|
| 80 |
$pluginConfiguration = $this->configuration->getPluginConfiguration($plugin); |
|---|
| 81 |
|
|---|
| 82 |
$this->logSection('plugin', 'Configuring plugin - '.$plugin); |
|---|
| 83 |
$this->installPluginAssets($plugin, $pluginConfiguration->getRootDir()); |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
* Installs web content for a plugin. |
|---|
| 89 |
* |
|---|
| 90 |
* @param string $plugin The plugin name |
|---|
| 91 |
* @param string $dir The plugin directory |
|---|
| 92 |
*/ |
|---|
| 93 |
protected function installPluginAssets($plugin, $dir) |
|---|
| 94 |
{ |
|---|
| 95 |
$webDir = $dir.DIRECTORY_SEPARATOR.'web'; |
|---|
| 96 |
|
|---|
| 97 |
if (is_dir($webDir)) |
|---|
| 98 |
{ |
|---|
| 99 |
$this->getFilesystem()->relativeSymlink($webDir, sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$plugin, true); |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|