Index: kernel/application.php
===================================================================
--- kernel/application.php (revision 15246)
+++ kernel/application.php (working copy)
@@ -2031,6 +2031,18 @@
}
/**
+ * Allows to process any type of event
+ *
+ * @param kEvent $event
+ * @return bool
+ * @access public
+ */
+ public function eventImplemented(kEvent $event)
+ {
+ return $this->EventManager->eventImplemented($event);
+ }
+
+ /**
* Registers new class in the factory
*
* @param string $real_class Real name of class as in class declaration
Index: kernel/event_handler.php
===================================================================
--- kernel/event_handler.php (revision 15226)
+++ kernel/event_handler.php (working copy)
@@ -104,10 +104,26 @@
* Executes event, specified in $event variable
*
* @param kEvent $event
+ * @return void
* @access public
*/
public function processEvent(kEvent $event)
{
+ $event_name = $this->getEventMethod($event);
+
+ $this->$event_name($event);
+ }
+
+ /**
+ * Returns method name, that should called to process given event.
+ * When no such method exists and exception is thrown.
+ *
+ * @param kEvent $event
+ * @return string
+ * @throws Exception
+ */
+ public function getEventMethod(kEvent $event)
+ {
$event_name = $event->Name;
if ( array_key_exists($event_name, $this->eventMethods) ) {
@@ -115,11 +131,10 @@
}
if ( method_exists($this, $event_name) ) {
- $this->$event_name($event);
+ return $event_name;
}
- else {
- throw new Exception('Event ' . $event->Name . ' not implemented in class ' . get_class($this) . '');
- }
+
+ throw new Exception('Event "' . $event->Name . '" not implemented in class "' . get_class($this) . '"');
}
/**
Index: kernel/event_manager.php
===================================================================
--- kernel/event_manager.php (revision 15226)
+++ kernel/event_manager.php (working copy)
@@ -272,6 +272,25 @@
}
/**
+ * Checks, that given event is implemented
+ *
+ * @param kEvent $event
+ * @return bool
+ * @access public
+ */
+ public function eventImplemented(kEvent $event)
+ {
+ if ( !$this->verifyEventPrefix($event, true) ) {
+ return false;
+ }
+
+ $event_handler = $this->Application->recallObject($event->Prefix . '_EventHandler');
+ /* @var $event_handler kEventHandler */
+
+ return $event_handler->getEventMethod($event) != '';
+ }
+
+ /**
* Checks if event prefix is valid
*
* @param kEvent $event
@@ -282,10 +301,11 @@
public function verifyEventPrefix($event, $is_fatal = false)
{
if ( !$this->Application->prefixRegistred($event->Prefix) ) {
+ // when "l-cdata" is requested, then load "l", that will clone "l-cdata" unit config
$this->Application->UnitConfigReader->loadConfig($event->Prefix);
if ( !$this->Application->prefixRegistred($event->Prefix) ) {
- $error_msg = 'Prefix ' . $event->Prefix . ' not registred (requested event ' . $event->Name . ')';
+ $error_msg = 'Prefix "' . $event->Prefix . '" not registred (requested event "' . $event->Name . '")';
if ($is_fatal) {
throw new Exception($error_msg);
Index: kernel/utility/event.php
===================================================================
--- kernel/utility/event.php (revision 15226)
+++ kernel/utility/event.php (working copy)
@@ -166,7 +166,7 @@
$this->Name = $regs[3];
}
else {
- throw new Exception('Invalid event string: ' . $params . '. $params should be "prefix[.special]:OnEvent" format');
+ throw new Exception('Invalid event string: "' . $params . '". Should be in "prefix[.special]:OnEvent" format');
}
}
}
Index: kernel/utility/unit_config_reader.php
===================================================================
--- kernel/utility/unit_config_reader.php (revision 15226)
+++ kernel/utility/unit_config_reader.php (working copy)
@@ -791,7 +791,7 @@
function loadConfig($prefix)
{
if ( !isset($this->prefixFiles[$prefix]) ) {
- throw new Exception('Configuration file for prefix ' . $prefix . ' is unknown');
+ throw new Exception('Configuration file for prefix "' . $prefix . '" is unknown');
return ;
}
Index: units/scheduled_tasks/scheduled_task_eh.php
===================================================================
--- units/scheduled_tasks/scheduled_task_eh.php (revision 15165)
+++ units/scheduled_tasks/scheduled_task_eh.php (working copy)
@@ -36,6 +36,34 @@
}
/**
+ * Does custom validation
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnBeforeItemValidate(kEvent $event)
+ {
+ parent::OnBeforeItemValidate($event);
+
+ $object = $event->getObject();
+ /* @var $object kDBItem */
+
+ $event_string = $object->GetDBField('Event');
+
+ if ( !$event_string ) {
+ return;
+ }
+
+ try {
+ $this->Application->eventImplemented(new kEvent($event_string));
+ }
+ catch (Exception $e) {
+ $object->SetError('Event', 'invalid_event', '+' . $e->getMessage());
+ }
+ }
+
+ /**
* [HOOK] Refreshes scheduled task list in database based on cached data from unit configs
*
* @param kEvent $event
Index: units/scheduled_tasks/scheduled_tasks_config.php
===================================================================
--- units/scheduled_tasks/scheduled_tasks_config.php (revision 15165)
+++ units/scheduled_tasks/scheduled_tasks_config.php (working copy)
@@ -115,7 +115,6 @@
),
'Event' => Array (
'type' => 'string', 'max_len' => 255,
- 'formatter' => 'kFormatter', 'regexp' => '/^[a-z-]*[.]{0,1}[a-z-]*:On[A-Za-z0-9]*$/',
'required' => 1, 'not_null' => 1, 'default' => ''
),
'RunInterval' => Array ('type' => 'int', 'required' => 1, 'not_null' => 1, 'default' => 0),