|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZNotificationEventFilter class 00004 // 00005 // Created on: <09-May-2003 16:05:40 sp> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file eznotificationeventfilter.php 00032 */ 00033 00034 /*! 00035 \class eZNotificationEventFilter eznotificationeventfilter.php 00036 \brief The class eZNotificationEventFilter does 00037 00038 */ 00039 //include_once( 'kernel/classes/notification/eznotificationevent.php' ); 00040 class eZNotificationEventFilter 00041 { 00042 /*! 00043 Constructor 00044 */ 00045 function eZNotificationEventFilter() 00046 { 00047 } 00048 00049 /*! 00050 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00051 the calls within a db transaction; thus within db->begin and db->commit. 00052 */ 00053 static function process() 00054 { 00055 $eventList = eZNotificationEvent::fetchUnhandledList(); 00056 $availableHandlers = eZNotificationEventFilter::availableHandlers(); 00057 foreach( $eventList as $event ) 00058 { 00059 foreach( $availableHandlers as $handler ) 00060 { 00061 if ( $handler === false ) 00062 { 00063 eZDebug::writeError( "Notification handler does not exist: $handlerKey", 'eZNotificationEventFilter::process()' ); 00064 } 00065 else 00066 { 00067 $handler->handle( $event ); 00068 } 00069 } 00070 $itemCountLeft = eZNotificationCollectionItem::fetchCountForEvent( $event->attribute( 'id' ) ); 00071 if ( $itemCountLeft == 0 ) 00072 { 00073 $event->remove(); 00074 } 00075 else 00076 { 00077 $event->setAttribute( 'status', eZNotificationEvent::STATUS_HANDLED ); 00078 $event->store(); 00079 } 00080 } 00081 eZNotificationCollection::removeEmpty(); 00082 } 00083 00084 static function availableHandlers() 00085 { 00086 //include_once( 'lib/ezutils/classes/ezextension.php' ); 00087 $baseDirectory = eZExtension::baseDirectory(); 00088 $notificationINI = eZINI::instance( 'notification.ini' ); 00089 $availableHandlers = $notificationINI->variable( 'NotificationEventHandlerSettings', 'AvailableNotificationEventTypes' ); 00090 $repositoryDirectories = array(); 00091 $extensionDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'ExtensionDirectories' ); 00092 foreach ( $extensionDirectories as $extensionDirectory ) 00093 { 00094 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/notification/handler'; 00095 if ( file_exists( $extensionPath ) ) 00096 $repositoryDirectories[] = $extensionPath; 00097 } 00098 $handlers = array(); 00099 foreach( $availableHandlers as $handlerString ) 00100 { 00101 $eventHandler = eZNotificationEventFilter::loadHandler( $repositoryDirectories, $handlerString ); 00102 if ( is_object( $eventHandler ) ) 00103 $handlers[$handlerString] = $eventHandler; 00104 } 00105 return $handlers; 00106 } 00107 00108 static function loadHandler( $directories, $handlerString ) 00109 { 00110 $foundHandler = false; 00111 $includeFile = ''; 00112 00113 //include_once( 'lib/ezutils/classes/ezextension.php' ); 00114 $baseDirectory = eZExtension::baseDirectory(); 00115 $notificationINI = eZINI::instance( 'notification.ini' ); 00116 $repositoryDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'RepositoryDirectories' ); 00117 $extensionDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'ExtensionDirectories' ); 00118 foreach ( $extensionDirectories as $extensionDirectory ) 00119 { 00120 $extensionPath = "{$baseDirectory}/{$extensionDirectory}/notification/handler/"; 00121 if ( file_exists( $extensionPath ) ) 00122 $repositoryDirectories[] = $extensionPath; 00123 } 00124 00125 foreach ( $repositoryDirectories as $repositoryDirectory ) 00126 { 00127 $repositoryDirectory = trim( $repositoryDirectory, '/' ); 00128 $includeFile = "{$repositoryDirectory}/{$handlerString}/{$handlerString}handler.php"; 00129 if ( file_exists( $includeFile ) ) 00130 { 00131 $foundHandler = true; 00132 break; 00133 } 00134 } 00135 if ( !$foundHandler ) 00136 { 00137 eZDebug::writeError( "Notification handler does not exist: $handlerString", 'eZNotificationEventFilter::loadHandler()' ); 00138 return false; 00139 } 00140 include_once( $includeFile ); 00141 $className = $handlerString . "handler"; 00142 return new $className(); 00143 } 00144 00145 /*! 00146 \static 00147 Goes through all event handlers and tells them to cleanup. 00148 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00149 the calls within a db transaction; thus within db->begin and db->commit. 00150 */ 00151 static function cleanup() 00152 { 00153 $availableHandlers = eZNotificationEventFilter::availableHandlers(); 00154 00155 $db = eZDB::instance(); 00156 $db->begin(); 00157 foreach( $availableHandlers as $handler ) 00158 { 00159 if ( $handler !== false ) 00160 { 00161 $handler->cleanup(); 00162 } 00163 } 00164 $db->commit(); 00165 } 00166 } 00167 00168 ?>