Skip to content

Instantly share code, notes, and snippets.

@peta
Created October 7, 2011 13:30
Show Gist options
  • Save peta/1270276 to your computer and use it in GitHub Desktop.
Save peta/1270276 to your computer and use it in GitHub Desktop.
Fix for CMSMS 1.9.4.3 event propagation system; enable propagation to originator module

By default events in CMS Made Simple are not propagated to their originator modules; while there are eligible reasons for that behaviour, there are just as much against it. For example following DRY or when events are emitted from multiple internal/external (=unknown) points at the same time. By introducing an additional optional parameter, I ensure that existing code won't break while at the same time having the possibility to let events propagate into the originator module when required.

Tested with CMSMS version 1.9.4.3

--- class.events.inc.php
+++ (clipboard)
@@ -99,9 +99,10 @@
* @param string $modulename The name of the module that is sending the event
* @param string $eventname The name of the event
* @param array $params The parameters associated with this event.
+ * @param boolean $exclude_originator Don't propagate event to originator module
* @return void
*/
- static public function SendEvent( $modulename, $eventname, $params = array() )
+ static public function SendEvent( $modulename, $eventname, $params = array(), $exclude_originator = TRUE )
{
global $CMS_INSTALL_PAGE;
if( isset($CMS_INSTALL_PAGE) ) return;
@@ -110,7 +111,7 @@
$usertagops =& $gCms->GetUserTagOperations();
$results = Events::ListEventHandlers($modulename, $eventname);
-
+
if ($results != false)
{
foreach( $results as $row )
@@ -124,7 +125,7 @@
{
// here's a quick check to make sure that we're not calling the module
// DoEvent function for an event originated by the same module.
- if( $row['module_name'] == $modulename )
+ if( TRUE === $exclude_originator AND $row['module_name'] == $modulename )
{
continue;
}
--- class.module.inc.php
+++ (clipboard)
@@ -3368,11 +3368,12 @@
* @final
* @param string The name of the event
* @param array The parameters associated with this event.
+ * @param boolean Don't propagate event to originator module
* @return void
*/
- function SendEvent( $eventname, $params )
+ function SendEvent( $eventname, $params, $exclude_originator = TRUE )
{
- Events::SendEvent($this->GetName(), $eventname, $params);
+ Events::SendEvent($this->GetName(), $eventname, $params, $exclude_originator);
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment