Fix issues with user notification event PIP GUI
authorMatthias Schmidt <gravatronics@live.com>
Sat, 13 Oct 2018 12:51:00 +0000 (14:51 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 13 Oct 2018 12:51:00 +0000 (14:51 +0200)
See #2545

wcfsetup/install/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php

index 3491295bd0d66f902f9708ad134a5bc70c9a0b7a..693f220fd4f89ee175aa5b2d279de1be36558c76 100644 (file)
@@ -185,16 +185,17 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
                $dataContainer = $form->getNodeById('data');
                
                $dataContainer->appendChildren([
-                       TextFormField::create('name')
-                               ->label('wcf.acp.pip.userNotificationEvent.name')
-                               ->description('wcf.acp.pip.userNotificationEvent.name.description')
+                       TextFormField::create('eventName')
+                               ->objectProperty('name')
+                               ->label('wcf.acp.pip.userNotificationEvent.eventName')
+                               ->description('wcf.acp.pip.userNotificationEvent.eventName.description')
                                ->required()
                                ->addValidator(new FormFieldValidator('format', function(TextFormField $formField) {
                                        if (!preg_match('~^[a-z][A-z]+$~', $formField->getValue())) {
                                                $formField->addValidationError(
                                                        new FormFieldValidationError(
                                                                'format',
-                                                               'wcf.acp.pip.userNotificationEvent.name.error.format'
+                                                               'wcf.acp.pip.userNotificationEvent.eventName.error.format'
                                                        )
                                                );
                                        }
@@ -218,11 +219,18 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
                                // validate the uniqueness of the `name` field after knowing that the selected object type is valid
                                ->addValidator(new FormFieldValidator('nameUniqueness', function(SingleSelectionFormField $formField) {
                                        /** @var TextFormField $nameField */
-                                       $nameField = $formField->getDocument()->getNodeById('name');
+                                       $nameField = $formField->getDocument()->getNodeById('eventName');
                                        
-                                       if ($formField->getDocument()->getFormMode() === IFormDocument::FORM_MODE_CREATE || $this->editedEntry->getAttribute('name') !== $nameField->getSaveValue()) {
+                                       if (
+                                               $formField->getDocument()->getFormMode() === IFormDocument::FORM_MODE_CREATE ||
+                                               $this->editedEntry->getElementsByTagName('name')->item(0)->nodeValue !== $nameField->getSaveValue() ||
+                                               $this->editedEntry->getElementsByTagName('objecttype')->item(0)->nodeValue !== $formField->getSaveValue()
+                                       ) {
                                                $eventList = new UserNotificationEventList();
                                                $eventList->getConditionBuilder()->add('user_notification_event.eventName = ?', [$nameField->getSaveValue()]);
+                                               $eventList->getConditionBuilder()->add('user_notification_event.objectTypeID = ?', [
+                                                       ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.notification.objectType', $formField->getSaveValue())
+                                               ]);
                                                $eventList->getConditionBuilder()->add(
                                                        'user_notification_event.objectTypeID = ?',
                                                        [ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.notification.objectType', $formField->getSaveValue())->objectTypeID]
@@ -232,7 +240,7 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
                                                        $nameField->addValidationError(
                                                                new FormFieldValidationError(
                                                                        'notUnique',
-                                                                       'wcf.acp.pip.userNotificationEvent.name.error.notUnique'
+                                                                       'wcf.acp.pip.userNotificationEvent.eventName.error.notUnique'
                                                                )
                                                        );
                                                }
@@ -282,12 +290,19 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
        protected function getElementData(\DOMElement $element, $saveData = false) {
                $data = [
                        'className' => $element->getElementsByTagName('classname')->item(0)->nodeValue,
-                       'objectTypeID' => $this->getObjectTypeID($element->getElementsByTagName('objecttype')->item(0)->nodeValue),
                        'eventName' => $element->getElementsByTagName('name')->item(0)->nodeValue,
                        'packageID' => $this->installation->getPackage()->packageID,
                        'preset' => 0
                ];
                
+               $objectType = $element->getElementsByTagName('objecttype')->item(0)->nodeValue;
+               if ($saveData) {
+                       $data['objectTypeID'] = $this->getObjectTypeID($objectType);
+               }
+               else {
+                       $data['objectType'] = $objectType;
+               }
+               
                $options = $element->getElementsByTagName('options')->item(0);
                if ($options) {
                        $data['options'] = StringUtil::normalizeCsv($options->nodeValue);
@@ -328,7 +343,7 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
         */
        protected function setEntryListKeys(IDevtoolsPipEntryList $entryList) {
                $entryList->setKeys([
-                       'name' => 'wcf.acp.pip.userNotificationEvent.name',
+                       'eventName' => 'wcf.acp.pip.userNotificationEvent.eventName',
                        'className' => 'wcf.acp.pip.userNotificationEvent.className'
                ]);
        }