Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 93 additions & 13 deletions lib/task/tools/atomPluginsTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,72 @@ public function execute($arguments = [], $options = [])

switch ($arguments['action']) {
case 'add':
$plugins[] = $arguments['plugin'];

// Save changes
$setting->setValue(serialize(array_unique($plugins)), ['sourceCulture' => true]);
$setting->save();
$this->addPlugin($arguments['plugin'], $plugins);
$this->savePlugins($setting, $plugins);

break;

case 'delete':
if (false !== $key = array_search($arguments['plugin'], $plugins)) {
unset($plugins[$key]);
} else {
throw new sfException('Plugin could not be found.');
$this->deletePlugin($arguments['plugin'], $plugins);
$this->savePlugins($setting, $plugins);

break;

case 'set-theme':
$themePlugins = [];
$configuration = ProjectConfiguration::getActive();
$pluginPaths = $configuration->getAllPluginPaths();

// Get list of theme plugins
foreach (sfPluginAdminPluginConfiguration::$pluginNames as $name) {
unset($pluginPaths[$name]);
}

// Save changes
$setting->setValue(serialize(array_unique($plugins)), ['sourceCulture' => true]);
$setting->save();
foreach ($pluginPaths as $name => $path) {
$className = $name.'Configuration';
if (sfConfig::get('sf_plugins_dir') == substr($path, 0, strlen(sfConfig::get('sf_plugins_dir'))) && is_readable($classPath = $path.'/config/'.$className.'.class.php')) {
$this->installPluginAssets($name, $path);

require_once $classPath;

$class = new $className($configuration);

// Build a list of themes
if (isset($class::$summary) && 1 === preg_match('/theme/i', $class::$summary)) {
$themePlugins[] = $name;
}
}
}

// Get current theme plugin
$currentTheme = null;
$criteria = new Criteria();
$criteria->add(QubitSetting::NAME, 'plugins');
if (1 == count($query = QubitSetting::get($criteria))) {
$setting = $query[0];

foreach (unserialize($setting->getValue(['sourceCulture' => true])) as $plugin) {
if (in_array($plugin, $themePlugins)) {
$currentTheme = $plugin;

break;
}
}
}

// Check if the new plugin is a theme plugin
if (in_array($arguments['plugin'], $themePlugins)) {
// Delete current theme plugin
$this->deletePlugin($currentTheme, $plugins);

// Add new theme plugin
$this->addPlugin($arguments['plugin'], $plugins);

// Save new plugins array
$this->savePlugins($setting, $plugins);
} else {
throw new sfException(sprintf('%s is not a theme plugin.', $arguments['plugin']));
}

break;

Expand All @@ -76,10 +124,21 @@ public function execute($arguments = [], $options = [])
}
}

// Copied from sfPluginPublishAssetsTask
protected function installPluginAssets($name, $path)
{
$webDir = $path.'/web';

if (is_dir($webDir)) {
$filesystem = new sfFilesystem();
$filesystem->relativeSymlink($webDir, sfConfig::get('sf_web_dir').'/'.$name, true);
}
}

protected function configure()
{
$this->addArguments([
new sfCommandArgument('action', sfCommandArgument::REQUIRED, 'The action (add, delete or list).'),
new sfCommandArgument('action', sfCommandArgument::REQUIRED, 'The action (add, delete, set-theme or list).'),
new sfCommandArgument('plugin', sfCommandArgument::OPTIONAL, 'The plugin name.'),
]);

Expand All @@ -98,7 +157,28 @@ protected function configure()
Manage AtoM plugins stored in the database. Examples:
- symfony atom-plugins add arFoobarPlugin
- symfony atom-plugins delete arFoobarPlugin
- symfony atom-plugins set-theme arFoobarPlugin
- symfony atom-plugins list
EOF;
}

private function deletePlugin($plugin, &$plugins)
{
if (false !== $key = array_search($plugin, $plugins)) {
unset($plugins[$key]);
} else {
throw new sfException('Plugin could not be found.');
}
}

private function addPlugin($plugin, &$plugins)
{
$plugins[] = $plugin;
}

private function savePlugins($setting, &$plugins)
{
$setting->setValue(serialize(array_unique($plugins)), ['sourceCulture' => true]);
$setting->save();
}
}
Loading