diff --git a/includes/VersioncontrolBackend.php b/includes/VersioncontrolBackend.php index 2070939..0934ae5 100644 --- a/includes/VersioncontrolBackend.php +++ b/includes/VersioncontrolBackend.php @@ -105,6 +105,7 @@ abstract class VersioncontrolBackend { 'committer_mapper' => 'VersioncontrolUserMapperInterface', 'author_mapper' => 'VersioncontrolUserMapperInterface', 'auth_handler' => 'VersioncontrolAuthHandlerInterface', + 'event_processor' => 'VersioncontrolSynchronizationEventProcessorInterface', ), ); diff --git a/includes/VersioncontrolRepository.php b/includes/VersioncontrolRepository.php index 352301e..d70816c 100644 --- a/includes/VersioncontrolRepository.php +++ b/includes/VersioncontrolRepository.php @@ -105,6 +105,9 @@ abstract class VersioncontrolRepository implements VersioncontrolEntityInterface /** * An array of plugin instances (instanciated plugin objects). * + * There is one plugin per plugin slot in most cases. For now only + * event_processor has multiple plugins associated. + * * @var array */ protected $pluginInstances = array(); @@ -1049,6 +1052,38 @@ abstract class VersioncontrolRepository implements VersioncontrolEntityInterface } /** + * Returns the event processor plugin object that this repository is + * configured to use. + * + * @return array(VersioncontrolSynchronizationEventProcessorInterface) + */ + public function getEventProcessors() { + if (!isset($this->pluginInstances['event_processor'])) { + $processors = array(); + // Potentially several plugins on the slot, so do it manually. + ctools_include('plugins'); + + if (!$plugins = ctools_get_plugins('versioncontrol', 'event_processor')) { + return array(); + } + + foreach ($plugins as $plugin) { + $class_name = ctools_plugin_get_class($plugin, 'handler'); + if (!class_exists($class_name)) { + throw new Exception("Plugin slot 'event_processor' of type 'event_processor' contains an invalid class name in handler slot 'handler', named '$class_name' class", E_WARNING); + } + $plugin_object = new $class_name(); + $this->getBackend()->verifyPluginInterface($this, 'event_processor', $plugin_object); + $plugin_object->setRepository($this); + $processors = $plugin_object; + } + $this->pluginInstances['event_processor'] = $processors; + } + + return $this->pluginInstances['event_processor']; + } + + /** * Convenience method to lock the repository in preparation for a * synchronization run. * diff --git a/includes/interfaces.inc b/includes/interfaces.inc index 91c4886..3fae24d 100644 --- a/includes/interfaces.inc +++ b/includes/interfaces.inc @@ -488,6 +488,12 @@ interface VersioncontrolSynchronizationEventProcessorInterface { * was executed correctly or not. */ public function process(VersioncontrolEvent $event); + + /** + * Set the repository object to be used by this plugin object. + */ + public function setRepository(VersioncontrolRepository $repository); + } /** diff --git a/includes/plugins/event_processor/VersioncontrolEventProcessorNone.inc b/includes/plugins/event_processor/VersioncontrolEventProcessorNone.inc index 8c2e4ec..0695694 100644 --- a/includes/plugins/event_processor/VersioncontrolEventProcessorNone.inc +++ b/includes/plugins/event_processor/VersioncontrolEventProcessorNone.inc @@ -12,11 +12,22 @@ class VersioncontrolEventProcessorNone implements VersioncontrolSynchronizationE const BEHAVIOR_B = 2; /** + * Associated repository. + * + * @var VersioncontrolRepository + */ + protected $repository; + + /** * This plugin is an example that does nothing. */ public function process(VersioncontrolEvent $event) { } + public function setRepository(VersioncontrolRepository $repository) { + $this->repository = $repository; + } + public function buildForm(&$form, &$form_state) { $form['behavior'] = array( '#type' => 'select', diff --git a/versioncontrol.admin.inc b/versioncontrol.admin.inc index 0413138..cdb640b 100644 --- a/versioncontrol.admin.inc +++ b/versioncontrol.admin.inc @@ -330,16 +330,6 @@ function versioncontrol_admin_settings_plugins($form, &$form_state) { '#default_value' => variable_get($variable, ''), ); } - // @fixme Actually do what is needed. - foreach (ctools_get_plugins('versioncontrol', 'event_processor') as $machine_name => $plugin) { - dpm($plugin); - //$variable = 'versioncontrol_repository_' . $vcs . '_base_url_' . $machine_name; - //$form['versioncontrol_plugins_' . $vcs]['webviewer_url_handler'][$variable] = array( - //'#type' => 'textfield', - //'#title' => t('Default base URL for %plugin_name', array('%plugin_name' => $plugin['title'])), - //'#default_value' => variable_get($variable, ''), - //); - } } $form['submit'] = array( @@ -555,6 +545,28 @@ function versioncontrol_admin_repository_edit($form, &$form_state, $repository, '#options' => versioncontrol_webviewer_url_handlers_get_names($form['#vcs']), ); + $form['event_processor'] = array( + '#type' => 'fieldset', + '#title' => t('Event processor'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#weight' => 7, + ); + if ($repository_exists) { + $default_event_processors = $repository->plugins['webviewer_url_handler']; + } + else { + $default_event_processors = versioncontrol_event_processor_get_default_plugins($form['#vcs']); + } + $form['event_processor']['processor'] = array( + '#type' => 'select', + '#multiple' => TRUE, + '#title' => t('Processors'), + '#description' => t('Which event processors will be used by this repository.'), + '#default_value' => $default_event_processors, + '#options' => versioncontrol_event_processor_get_names($form['#vcs']), + ); + $form['submit'] = array( '#type' => 'submit', '#value' => t('Save repository'), diff --git a/versioncontrol.module b/versioncontrol.module index d595d69..f65375b 100644 --- a/versioncontrol.module +++ b/versioncontrol.module @@ -537,6 +537,9 @@ function versioncontrol_ctools_plugin_type() { 'repomgr' => array( 'classes' => array('worker'), ), + 'event_processor' => array( + 'classes' => array('handler'), + ), ); } @@ -670,6 +673,36 @@ function versioncontrol_webviewer_url_handlers_get_default_plugin($vcs) { } /** + * Retrieves the default 'event_processor' plugins. + * + * @param string $vcs + * Version Control System machine name as defined by + * hook_versioncontrol_backends(). + * + * @return array + * A list of plugin machine names. It can be empty. + */ +function versioncontrol_event_processor_get_default_plugins($vcs) { + $default_event_processors = array(); + ctools_include('plugins'); + $default_event_processors = variable_get('versioncontrol_repository_plugin_default_event_processor', array()); + $valid_plugins = array(); + foreach (ctools_get_plugins('versioncontrol', 'event_processor') as $name => $plugin) { + if ($plugin['vcs'] == $vcs) { + $valid_plugins[] = $name; + } + } + asort($valid_plugins); + + foreach ($default_event_processors as $key => $default_event_processor) { + if (!in_array($default_event_processor, $valid_plugins)) { + unset($default_event_processors[$key]); + } + } + return $default_event_processors; +} + +/** * Helper function for handling plugin settings. */ function versioncontrol_plugins_get_information() {