getApplication(); $services = $application->getServiceManager(); $manager = $services->get('queue'); $events = $manager->getEventManager(); $events->attach( 'task.change', // this attaches us only to task.change events function ($event) use ($services) { // a lot of events come through. we need to make sure this is actually an activity event $model = $event->getParam('activity'); if (!$model instanceof Activity) { return; } // get the description, and see if this has a block of JSON in it from Commons $desc = ''; if( preg_match('/(.*?)(^{.*$)/sm', $model->get('description'), $pieces) == 0 ) { $desc = $model->get('description'); } else { $desc = $pieces[1]; $raw_json = $pieces[2]; $action = 'commented in Commons on'; $target = 'some file'; // parse the JSON, if it is legal $json = json_decode($raw_json); if( json != NULL && $json->{'commentText'} != NULL ) { $target = $json->{'fileRevisionLocation'}->{'path'}; $space = $json->{'fileRevisionLocation'}->{'spaceId'}; $type = $json->{'fileRevisionLocation'}->{'pathType'}; $model->set('link', 'http://commons.qa.perforce.com:1999/ui/file-details/space/'.$space.'/'.$type."/".$target[0]."?spaceName=".urlencode($json->{'fileRevisionLocation'}->{'spaceName'}).'&rev='.$json->{'fileRevisionLocation'}->{'revision'}); } else if( json != NULL && $json->{'changeType'} != NULL && $json->{'changeType'} == 'RENAME_SPACE' ) { $action = 'renamed'; $target = 'a space in Commons'; $model->set('link', 'http://commons.qa.perforce.com:1999/ui/space/'); } else if( json != NULL && $json->{'changeType'} != NULL && $json->{'changeType'} == 'CREATE_SPACE' ) { $action = 'created'; $target = 'a space in Commons'; $model->set('link', 'http://commons.qa.perforce.com:1999/ui/space/'); } else { return; } $model->set('action', $action); $model->set('target', $target); } // $model->set('description', $desc); }, // set our priority, -90 puts us right before the end, but before the activity is published -90 ); } // loads up our config file. all modules should have this method. public function getConfig() { return include __DIR__ . '/config/module.config.php'; } // makes sure our module is automatically loaded. otherwise the user would // explicitly install our module in the application public function getAutoloaderConfig() { return array( 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } }