Normalize csv in package installation plugins
authorMatthias Schmidt <gravatronics@live.com>
Tue, 20 Jun 2017 17:18:30 +0000 (19:18 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 20 Jun 2017 17:18:30 +0000 (19:18 +0200)
See #2311

wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/TemplateListenerPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/UserProfileMenuPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/util/StringUtil.class.php

index ed0d92b6b79201307ca0412f66ea324df1d7ad9f..eb6a89e7ef0194d9eb4780c06ff700f65581c6ef 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\system\package\plugin;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Abstract implementation of a package installation plugin for menu items.
@@ -42,9 +43,9 @@ abstract class AbstractMenuPackageInstallationPlugin extends AbstractXMLPackageI
                        'menuItem' => $data['attributes']['name'],
                        'menuItemController' => isset($data['elements']['controller']) ? $data['elements']['controller'] : '',
                        'menuItemLink' => isset($data['elements']['link']) ? $data['elements']['link'] : '',
-                       'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '',
+                       'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '',
                        'parentMenuItem' => isset($data['elements']['parent']) ? $data['elements']['parent'] : '',
-                       'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '',
+                       'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '',
                        'showOrder' => $showOrder
                ];
        }
index bc6680eb5274a00b22189036980f08279546426b..578129ecc05663b0852bc9287d089bf17b9aff15 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\system\package\plugin;
 use wcf\data\package\Package;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Abstract implementation of a package installation plugin for options.
@@ -120,9 +121,9 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag
                        // build data block with defaults
                        $data = [
                                'categoryName' => $element->getAttribute('name'),
-                               'options' => isset($data['options']) ? $data['options'] : '',
+                               'options' => isset($data['options']) ? StringUtil::normalizeCsv($data['options']) : '',
                                'parentCategoryName' => isset($data['parent']) ? $data['parent'] : '',
-                               'permissions' => isset($data['permissions']) ? $data['permissions'] : '',
+                               'permissions' => isset($data['permissions']) ? StringUtil::normalizeCsv($data['permissions']) : '',
                                'showOrder' => isset($data['showorder']) ? intval($data['showorder']) : null
                        ];
                        
index 005fe77042616ef02f7c4fc34f62c0ca0c92d398..a21133432ddefd83a503befb13f6ec29ae56960a 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\cronjob\Cronjob;
 use wcf\data\cronjob\CronjobEditor;
 use wcf\system\WCF;
 use wcf\util\CronjobUtil;
+use wcf\util\StringUtil;
 
 /**
  * Installs, updates and deletes cronjobs.
@@ -76,7 +77,7 @@ class CronjobPackageInstallationPlugin extends AbstractXMLPackageInstallationPlu
                        'cronjobName' => isset($data['attributes']['name']) ? $data['attributes']['name'] : '',
                        'description' => isset($data['elements']['description']) ? $data['elements']['description'] : '',
                        'isDisabled' => isset($data['elements']['isdisabled']) ? intval($data['elements']['isdisabled']) : 0,
-                       'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '',
+                       'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '',
                        'startDom' => $data['elements']['startdom'],
                        'startDow' => $data['elements']['startdow'],
                        'startHour' => $data['elements']['starthour'],
index 5e9d9783068b9bd5e5a9a6307927f1f24468aa41..3a73d9a942f0a678953fa6b272bc1270d7c55904 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\event\listener\EventListener;
 use wcf\data\event\listener\EventListenerEditor;
 use wcf\system\cache\builder\EventListenerCacheBuilder;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Installs, updates and deletes event listeners.
@@ -73,13 +74,13 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat
                return [
                        'environment' => isset($data['elements']['environment']) ? $data['elements']['environment'] : 'user',
                        'eventClassName' => $data['elements']['eventclassname'],
-                       'eventName' => $data['elements']['eventname'],
+                       'eventName' => StringUtil::normalizeCsv($data['elements']['eventname']),
                        'inherit' => isset($data['elements']['inherit']) ? intval($data['elements']['inherit']) : 0,
                        'listenerClassName' => $data['elements']['listenerclassname'],
                        'listenerName' => isset($data['attributes']['name']) ? $data['attributes']['name'] : '',
                        'niceValue' => $nice,
-                       'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '',
-                       'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''
+                       'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '',
+                       'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : ''
                ];
        }
        
index 75efcbd7a74c665f870083d3d32fb86be72c5679..44feafe3aee7b3882c33bf418fbb50765223bde2 100644 (file)
@@ -5,6 +5,7 @@ use wcf\data\option\OptionEditor;
 use wcf\data\package\Package;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Installs, updates and deletes options.
@@ -40,13 +41,13 @@ class OptionPackageInstallationPlugin extends AbstractOptionPackageInstallationP
                if (isset($option['optiontype'])) $optionType = $option['optiontype'];
                if (isset($option['defaultvalue'])) $defaultValue = WCF::getLanguage()->get($option['defaultvalue']);
                if (isset($option['validationpattern'])) $validationPattern = $option['validationpattern'];
-               if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions'];
+               if (isset($option['enableoptions'])) $enableOptions = StringUtil::normalizeCsv($option['enableoptions']);
                if (isset($option['showorder'])) $showOrder = intval($option['showorder']);
                if (isset($option['hidden'])) $hidden = intval($option['hidden']);
                $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName');
                if (isset($option['selectoptions'])) $selectOptions = $option['selectoptions'];
-               if (isset($option['permissions'])) $permissions = $option['permissions'];
-               if (isset($option['options'])) $options = $option['options'];
+               if (isset($option['permissions'])) $permissions = StringUtil::normalizeCsv($option['permissions']);
+               if (isset($option['options'])) $options = StringUtil::normalizeCsv($option['options']);
                if (isset($option['supporti18n'])) $supportI18n = $option['supporti18n'];
                if (isset($option['requirei18n'])) $requireI18n = $option['requirei18n'];
                
index 3994472ffd2ece12635b3ef255a8675f84211f00..d424c53da5a9295c95c547b958814e7d3e6cb5ae 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\system\package\plugin;
 use wcf\data\template\listener\TemplateListenerEditor;
 use wcf\system\cache\builder\TemplateListenerCodeCacheBuilder;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Installs, updates and deletes template listeners.
@@ -57,8 +58,8 @@ class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstal
                        'eventName' => $data['elements']['eventname'],
                        'niceValue' => $niceValue,
                        'name' => $data['attributes']['name'],
-                       'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '',
-                       'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '',
+                       'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '',
+                       'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '',
                        'templateCode' => $data['elements']['templatecode'],
                        'templateName' => $data['elements']['templatename']
                ];
index d3d5cde6663752c34f88696b12caff50aca57f27..3d173dd672e095319165d69a9ca9cabad7bd795a 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\user\group\option\UserGroupOption;
 use wcf\data\user\group\option\UserGroupOptionEditor;
 use wcf\data\user\group\UserGroup;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Installs, updates and deletes user group options.
@@ -50,9 +51,9 @@ class UserGroupOptionPackageInstallationPlugin extends AbstractOptionPackageInst
                if (isset($option['validationpattern'])) $validationPattern = $option['validationpattern'];
                if (!empty($option['showorder'])) $showOrder = intval($option['showorder']);
                $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName');
-               if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions'];
-               if (isset($option['permissions'])) $permissions = $option['permissions'];
-               if (isset($option['options'])) $options = $option['options'];
+               if (isset($option['enableoptions'])) $enableOptions = StringUtil::normalizeCsv($option['enableoptions']);
+               if (isset($option['permissions'])) $permissions = StringUtil::normalizeCsv($option['permissions']);
+               if (isset($option['options'])) $options = StringUtil::normalizeCsv($option['options']);
                if (isset($option['usersonly'])) $usersOnly = $option['usersonly'];
                
                // collect additional tags and their values
index 7c7277dcc54db60a4a891ae75add06577833aa07..9f130c8e4a6e9ad02b8adae67299775da71f8c74 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\user\notification\event\UserNotificationEvent;
 use wcf\data\user\notification\event\UserNotificationEventEditor;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Installs, updates and deletes user notification events.
@@ -66,8 +67,8 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
                        'eventName' => $data['elements']['name'],
                        'className' => $data['elements']['classname'],
                        'objectTypeID' => $this->getObjectTypeID($data['elements']['objecttype']),
-                       'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '',
-                       'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '',
+                       'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '',
+                       'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '',
                        'preset' => !empty($data['elements']['preset']) ? 1 : 0,
                        'presetMailNotificationType' => $presetMailNotificationType
                ];
index cb31e0c156ee8048a66910c97c57363b430ee95f..588ce951e6f629bf1cef896aa95372b3db1965ec 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\user\option\UserOption;
 use wcf\data\user\option\UserOptionEditor;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Installs, updates and deletes user options.
@@ -80,11 +81,11 @@ class UserOptionPackageInstallationPlugin extends AbstractOptionPackageInstallat
                if (isset($option['showorder'])) $showOrder = intval($option['showorder']);
                if (isset($option['outputclass'])) $outputClass = $option['outputclass'];
                if (isset($option['selectoptions'])) $selectOptions = $option['selectoptions'];
-               if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions'];
+               if (isset($option['enableoptions'])) $enableOptions = StringUtil::normalizeCsv($option['enableoptions']);
                if (isset($option['isdisabled'])) $isDisabled = intval($option['isdisabled']);
                $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName');
-               if (isset($option['permissions'])) $permissions = $option['permissions'];
-               if (isset($option['options'])) $options = $option['options'];
+               if (isset($option['permissions'])) $permissions = StringUtil::normalizeCsv($option['permissions']);
+               if (isset($option['options'])) $options = StringUtil::normalizeCsv($option['options']);
                
                // collect additional tags and their values
                $additionalData = [];
index efd52e7bb6d16ad3221d0de04a7120672299c027..e81c49c83c0ce8f21c1fb2a73e4f133f46c29b7b 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\system\package\plugin;
 use wcf\data\user\profile\menu\item\UserProfileMenuItemEditor;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Installs, updates and deletes user profile menu items.
@@ -54,8 +55,8 @@ class UserProfileMenuPackageInstallationPlugin extends AbstractXMLPackageInstall
                // merge values and default values
                return [
                        'menuItem' => $data['attributes']['name'],
-                       'options' => isset($data['elements']['options']) ? $data['elements']['options'] : '',
-                       'permissions' => isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '',
+                       'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '',
+                       'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '',
                        'showOrder' => $showOrder,
                        'className' => $data['elements']['classname']
                ];
index 5beea22275ba4e20ff653e5cf6b7aa51d60489f0..4b80e6e3fc4b8ac958412fe82bd62770dbe741e2 100644 (file)
@@ -764,6 +764,19 @@ final class StringUtil {
                return self::formatNumeric($number) . $unitPrefix;
        }
        
+       /**
+        * Normalizes a string representing comma-separated values by making sure
+        * that the separator is just a comma, not a combination of whitespace and
+        * a comma.
+        * 
+        * @param       string          $string
+        * @return      string
+        * @since       3.1
+        */
+       public static function normalizeCsv($string) {
+               return implode(',', ArrayUtil::trim(explode(',', $string)));
+       }
+       
        /**
         * Forbid creation of StringUtil objects.
         */