| 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->addOptions(array( |
|---|
| 29 |
new sfCommandOption('core-only', '', sfCommandOption::PARAMETER_NONE, 'If set only core plugins will publish their assets'), |
|---|
| 30 |
new sfCommandOption('symfony-lib-dir', '', sfCommandOption::PARAMETER_REQUIRED, 'The symfony lib dir'), |
|---|
| 31 |
)); |
|---|
| 32 |
|
|---|
| 33 |
$this->aliases = array(); |
|---|
| 34 |
$this->namespace = 'plugin'; |
|---|
| 35 |
$this->name = 'publish-assets'; |
|---|
| 36 |
|
|---|
| 37 |
$this->briefDescription = 'Publishes web assets for all plugins'; |
|---|
| 38 |
|
|---|
| 39 |
$this->detailedDescription = <<<EOF |
|---|
| 40 |
The [plugin:publish-assets|INFO] task will publish web assets from all plugins. |
|---|
| 41 |
|
|---|
| 42 |
[./symfony plugin:publish-assets|INFO] |
|---|
| 43 |
|
|---|
| 44 |
In fact this will send the [plugin.post_install|INFO] event to each plugin. |
|---|
| 45 |
|
|---|
| 46 |
EOF; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
* @see sfTask |
|---|
| 51 |
*/ |
|---|
| 52 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 53 |
{ |
|---|
| 54 |
$plugins = $this->configuration->getPlugins(); |
|---|
| 55 |
|
|---|
| 56 |
foreach ($this->configuration->getAllPluginPaths() as $pluginName => $pluginPath) |
|---|
| 57 |
{ |
|---|
| 58 |
if (!in_array($pluginName, $plugins) || ($options['core-only'] && dirname($pluginPath) != $this->configuration->getSymfonyLibDir().'/plugins')) |
|---|
| 59 |
{ |
|---|
| 60 |
continue; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
$this->logSection('plugin', 'Configuring plugin - '.$pluginName); |
|---|
| 64 |
$this->installPluginAssets($pluginName, $pluginPath); |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
* Installs web content for a plugin. |
|---|
| 70 |
* |
|---|
| 71 |
* @param string $plugin The plugin name |
|---|
| 72 |
* @param string $dir The plugin directory |
|---|
| 73 |
*/ |
|---|
| 74 |
protected function installPluginAssets($plugin, $dir) |
|---|
| 75 |
{ |
|---|
| 76 |
$webDir = $dir.DIRECTORY_SEPARATOR.'web'; |
|---|
| 77 |
|
|---|
| 78 |
if (is_dir($webDir)) |
|---|
| 79 |
{ |
|---|
| 80 |
$filesystem = new sfFilesystem(); |
|---|
| 81 |
$filesystem->relativeSymlink($webDir, sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$plugin, true); |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|