From 07badc377ebde3b946aca02acd444a85991ff774 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 20 Aug 2013 23:02:29 +0200 Subject: [PATCH] NotificationhistoryQuery, initial commit --- .../Ido/Query/NotificationhistoryQuery.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php new file mode 100644 index 000000000..f2ca2c988 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php @@ -0,0 +1,87 @@ + array( + 'timestamp' => 'UNIX_TIMESTAMP(n.start_time)', + 'raw_timestamp' => 'n.start_time', + 'state_time' => 'n.start_time', + 'object_id' => 'object_id', + 'type' => "('notify')", + 'state' => 'state', + 'state_type' => '(NULL)', + 'output' => null, + 'attempt' => '(NULL)', + 'max_attempts' => '(NULL)', + ) + ); + + protected function joinBaseTables() + { +//"('[' || cndetails.contacts || '] ' || n.output)" + // This is one of the db-specific workarounds that could be abstracted + // in a better way: + switch ($this->ds->getConnection()->getDbType()) { + case 'mysql': + $concat_contacts = "GROUP_CONCAT(c.alias ORDER BY c.alias SEPARATOR ', ')"; + break; + case 'pgsql': + // TODO: Find a way to "ORDER" these: + $concat_contacts = "ARRAY_TO_STRING(ARRAY_AGG(c.alias), ', ')"; + break; + case 'oracle': + // TODO: This is only valid for Oracle >= 11g Release 2. + $concat_contacts = "LISTAGG(c.alias, ', ') WITHIN GROUP (ORDER BY c.alias)"; + // Alternatives: + // + // RTRIM(XMLAGG(XMLELEMENT(e, column_name, ',').EXTRACT('//text()')), + // + // not supported and not documented but works since 10.1, + // however it is NOT always present; + // WM_CONCAT(c.alias) + break; + default: + die('Not yet'); // TODO: Proper Exception + } +$this->columnMap['history']['output'] = "('[' || $concat_contacts || '] ' || n.output)"; +/* + $cndetails = $this->db->select()->from( + array('cn' => $this->prefix . 'contactnotifications'), + array( + 'notification_id' => 'notification_id', + 'cnt' => 'COUNT(*)', + 'contacts' => $concat_contacts + ) + )->join( + array('c' => $this->prefix . 'contacts'), + 'cn.contact_object_id = c.contact_object_id', + array() + )->group('notification_id'); +*/ + $this->baseQuery = $this->db->select()->from( + array('n' => $this->prefix . 'notifications'), + array() + )->join( + array('cn' => $this->prefix . 'contactnotifications'), + 'cn.notification_id = n.notification_id', + array() + )->joinLeft( + array('c' => $this->prefix . 'contacts'), + 'cn.contact_object_id = c.contact_object_id', + array() + )->group('cn.notification_id') + + /*->join( + array('cndetails' => $cndetails), + 'cndetails.notification_id = n.notification_id', + array() + )*/ + ; + + $this->joinedVirtualTables = array('history' => true); + } + +}