Fixed preset issue
authorMarcel Werk <burntime@woltlab.com>
Sat, 22 Mar 2014 21:36:31 +0000 (22:36 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sat, 22 Mar 2014 21:36:31 +0000 (22:36 +0100)
wcfsetup/install/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php

index 06551cdf2c78c5ed4add0b818435bb85562ffd9b..8021f5bbdfb4cd94f5c4163bc5e2b07c62e42206 100644 (file)
@@ -29,6 +29,12 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
         */
        public $tagName = 'event';
        
+       /**
+        * preset event ids
+        * @var array<integer>
+        */
+       protected $presetEventIDs = array();
+       
        /**
         * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete()
         */
@@ -74,6 +80,37 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
                );
        }
        
+       /**
+        * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::import()
+        */
+       protected function import(array $row, array $data) {
+               $result = parent::import($row, $data);
+               
+               if (empty($row)) {
+                       $this->presetEventIDs[] = $result->eventID;
+               }
+
+               return $result;
+       }
+       
+       /**
+        * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::cleanup()
+        */
+       protected function cleanup() {
+               if (empty($this->presetEventIDs)) return;
+               
+               $sql = "INSERT IGNORE INTO      wcf".WCF_N."_user_notification_event_to_user
+                                               (userID, eventID)
+                       SELECT                  userID, ?
+                       FROM                    wcf".WCF_N."_user";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               WCF::getDB()->beginTransaction();
+               foreach ($this->presetEventIDs as $eventID) {
+                       $statement->execute(array($eventID));
+               }
+               WCF::getDB()->commitTransaction();
+       }
+       
        /**
         * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem()
         */