Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eznotificationeventfilter.php
Go to the documentation of this file.
1 <?php
16 class eZNotificationEventFilter
17 {
22 static function process()
23 {
24 $limit = 100;
25 $offset = 0;
26 $availableHandlers = eZNotificationEventFilter::availableHandlers();
27 do
28 {
29 $eventList = eZNotificationEvent::fetchUnhandledList( array( 'offset' => $offset, 'length' => $limit ) );
30 foreach( $eventList as $event )
31 {
32 $db = eZDB::instance();
33 $db->begin();
34
35 foreach( $availableHandlers as $handler )
36 {
37 if ( $handler === false )
38 {
39 eZDebug::writeError( "Notification handler does not exist: $handlerKey", __METHOD__ );
40 }
41 else
42 {
43 $handler->handle( $event );
44 }
45 }
46 $itemCountLeft = eZNotificationCollectionItem::fetchCountForEvent( $event->attribute( 'id' ) );
47 if ( $itemCountLeft == 0 )
48 {
49 $event->remove();
50 }
51 else
52 {
53 $event->setAttribute( 'status', eZNotificationEvent::STATUS_HANDLED );
54 $event->store();
55 }
56
57 $db->commit();
58 }
59 eZContentObject::clearCache();
60 } while ( count( $eventList ) == $limit ); // If less than limit, we're on the last iteration
61
62 eZNotificationCollection::removeEmpty();
63 }
64
65 static function availableHandlers()
66 {
67 $baseDirectory = eZExtension::baseDirectory();
68 $notificationINI = eZINI::instance( 'notification.ini' );
69 $availableHandlers = $notificationINI->variable( 'NotificationEventHandlerSettings', 'AvailableNotificationEventTypes' );
70 $repositoryDirectories = array();
71 $extensionDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'ExtensionDirectories' );
72 foreach ( $extensionDirectories as $extensionDirectory )
73 {
74 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/notification/handler';
75 if ( file_exists( $extensionPath ) )
76 $repositoryDirectories[] = $extensionPath;
77 }
78 $handlers = array();
79 foreach( $availableHandlers as $handlerString )
80 {
81 $eventHandler = eZNotificationEventFilter::loadHandler( $repositoryDirectories, $handlerString );
82 if ( is_object( $eventHandler ) )
83 $handlers[$handlerString] = $eventHandler;
84 }
85 return $handlers;
86 }
87
88 static function loadHandler( $directories, $handlerString )
89 {
90 $foundHandler = false;
91 $includeFile = '';
92
93 $baseDirectory = eZExtension::baseDirectory();
94 $notificationINI = eZINI::instance( 'notification.ini' );
95 $repositoryDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'RepositoryDirectories' );
96 $extensionDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'ExtensionDirectories' );
97 foreach ( $extensionDirectories as $extensionDirectory )
98 {
99 $extensionPath = "{$baseDirectory}/{$extensionDirectory}/notification/handler/";
100 if ( file_exists( $extensionPath ) )
101 $repositoryDirectories[] = $extensionPath;
102 }
103
104 foreach ( $repositoryDirectories as $repositoryDirectory )
105 {
106 $repositoryDirectory = trim( $repositoryDirectory, '/' );
107 $includeFile = "{$repositoryDirectory}/{$handlerString}/{$handlerString}handler.php";
108 if ( file_exists( $includeFile ) )
109 {
110 $foundHandler = true;
111 break;
112 }
113 }
114 if ( !$foundHandler )
115 {
116 eZDebug::writeError( "Notification handler does not exist: $handlerString", __METHOD__ );
117 return false;
118 }
119 include_once( $includeFile );
120 $className = $handlerString . "handler";
121 return new $className();
122 }
123
130 static function cleanup()
131 {
132 $availableHandlers = eZNotificationEventFilter::availableHandlers();
133
134 $db = eZDB::instance();
135 $db->begin();
136 foreach( $availableHandlers as $handler )
137 {
138 if ( $handler !== false )
139 {
140 $handler->cleanup();
141 }
142 }
143 $db->commit();
144 }
145 }
146
147 ?>
eZContentObject\clearCache
static clearCache( $idArray=array())
Definition: ezcontentobject.php:284
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZExtension\baseDirectory
static baseDirectory(eZINI|null $siteINI=null)
Definition: ezextension.php:39
eZNotificationCollectionItem\fetchCountForEvent
static fetchCountForEvent( $eventID)
Definition: eznotificationcollectionitem.php:70
eZNotificationCollection\removeEmpty
static removeEmpty()
Definition: eznotificationcollection.php:121
eZNotificationEventFilter
The class eZNotificationEventFilter does.
Definition: eznotificationeventfilter.php:17
eZNotificationEventFilter\loadHandler
static loadHandler( $directories, $handlerString)
Definition: eznotificationeventfilter.php:88
eZNotificationEventFilter\process
static process()
Definition: eznotificationeventfilter.php:22
eZNotificationEventFilter\cleanup
static cleanup()
Definition: eznotificationeventfilter.php:130
eZNotificationEventFilter\availableHandlers
static availableHandlers()
Definition: eznotificationeventfilter.php:65
eZNotificationEvent\STATUS_HANDLED
const STATUS_HANDLED
Definition: eznotificationevent.php:21
eZNotificationEvent\fetchUnhandledList
static fetchUnhandledList( $limit=null)
Definition: eznotificationevent.php:178
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.