Fixed Error saving user groups permissions

Warchamp7

Active member
I'm currently testing an upgrade of one of my sites from 1.4 -> 2.0. The upgrade was successful from everything I've checked thus far.

However, I'm running into this issue when trying to save some but not all of my existing user groups, even with no values changed.

This also happens when trying to change the user groups of my own account.

ErrorException: [E_NOTICE] Undefined offset: 10 in src/XF/Permission/Builder.php at line 382
  1. XF::handlePhpError() in src/XF/Permission/Builder.php at line 382
  2. XF\Permission\Builder->pickPermissionPriorityValue() in src/XF/Permission/Builder.php at line 350
  3. XF\Permission\Builder->calculatePermissions() in src/XF/Permission/Builder.php at line 133
  4. XF\Permission\Builder->rebuildCombination() in src/XF/Service/UpdatePermissions.php at line 220
  5. XF\Service\UpdatePermissions->triggerCacheRebuild() in src/XF/Service/UpdatePermissions.php at line117
  6. XF\Service\UpdatePermissions->updatePermissions() in src/XF/Admin/Controller/UserGroup.php at line101
  7. XF\Admin\Controller\UserGroup->XF\Admin\Controller\{closure}() in src/XF/Mvc/FormAction.php at line 159
  8. XF\Mvc\FormAction->run() in src/XF/Admin/Controller/UserGroup.php at line 120
  9. XF\Admin\Controller\UserGroup->actionSave() in src/XF/Mvc/Dispatcher.php at line 249
  10. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
  11. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
  12. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1889
  13. XF\App->run() in src/XF.php at line 328
  14. XF::runApp() in admin.php at line 13
 
Last edited:
I'm not 100% certain, but I suspect you have a permission entry in the database which has perhaps been imported, manually adjusted or set by an add-on (has probably been there since XF1) .

Could you run this query and let us know what is returned?
SQL:
SHOW CREATE TABLE xf_permission;
And for good measure, this one:
SQL:
SELECT * FROM xf_permission WHERE permission_type <> 'flag' AND permission_type <> 'integer';
 
I'm not 100% certain, but I suspect you have a permission entry in the database which has perhaps been imported, manually adjusted or set by an add-on (has probably been there since XF1) .

Could you run this query and let us know what is returned?
SQL:
SHOW CREATE TABLE xf_permission;
And for good measure, this one:
SQL:
SELECT * FROM xf_permission WHERE permission_type <> 'flag' AND permission_type <> 'integer';

SQL:
| xf_permission | CREATE TABLE `xf_permission` (
  `permission_id` varbinary(25) NOT NULL,
  `permission_group_id` varbinary(25) NOT NULL,
  `permission_type` enum('flag','integer') NOT NULL,
  `interface_group_id` varbinary(50) NOT NULL,
  `depend_permission_id` varbinary(25) NOT NULL,
  `display_order` int(10) unsigned NOT NULL,
  `addon_id` varbinary(50) NOT NULL DEFAULT '',
  PRIMARY KEY (`permission_id`,`permission_group_id`),
  KEY `display_order` (`display_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

SQL:
mysql> SELECT * FROM xf_permission WHERE permission_type <> 'flag' AND permission_type <> 'integer';
Empty set (0.00 sec)
 
Well, that doesn't make any sense... I guess I'll need to look at the code again.

Actually, try this:
SQL:
SHOW CREATE TABLE xf_permission_entry;
And:
SQL:
SELECT * FROM xf_permission_entry WHERE permission_value = '10' OR permission_value_int = '10';
 
Well, that doesn't make any sense... I guess I'll need to look at the code again.

Actually, try this:
SQL:
SHOW CREATE TABLE xf_permission_entry;
And:
SQL:
SELECT * FROM xf_permission_entry WHERE permission_value = '10' OR permission_value_int = '10';

SQL:
| xf_permission_entry | CREATE TABLE `xf_permission_entry` (
  `permission_entry_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `user_group_id` int(10) unsigned NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `permission_group_id` varbinary(25) NOT NULL,
  `permission_id` varbinary(25) NOT NULL,
  `permission_value` enum('unset','allow','deny','use_int') NOT NULL,
  `permission_value_int` int(11) NOT NULL,
  PRIMARY KEY (`permission_entry_id`),
  UNIQUE KEY `unique_permission` (`user_group_id`,`user_id`,`permission_group_id`,`permission_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7042 DEFAULT CHARSET=utf8 |

SQL:
mysql> SELECT * FROM xf_permission_entry WHERE permission_value = '10' OR permission_value_int = '10';
+---------------------+---------------+---------+---------------------+--------------------------+------------------+----------------------+
| permission_entry_id | user_group_id | user_id | permission_group_id | permission_id            | permission_value | permission_value_int |
+---------------------+---------------+---------+---------------------+--------------------------+------------------+----------------------+
|                 211 |            10 |       0 | conversation        | maxRecipients            | use_int          |                   10 |
|                 350 |            29 |       0 | conversation        | maxRecipients            | use_int          |                   10 |
|                 414 |            33 |       0 | conversation        | maxRecipients            | use_int          |                   10 |
|                 455 |            36 |       0 | conversation        | maxRecipients            | use_int          |                   10 |
|                 551 |            60 |       0 | conversation        | maxRecipients            | use_int          |                   10 |
|                1971 |             4 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                1972 |             4 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                1974 |             4 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                1975 |             4 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                1998 |             4 |       0 | forum               | joinSocialForum          | use_int          |                   10 |
|                2001 |             4 |       0 | forum               | createSocialForum        | use_int          |                   10 |
|                2057 |            36 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2058 |            36 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2059 |            36 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2060 |            36 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2069 |            24 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2070 |            24 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2072 |            24 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2073 |            24 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2134 |            97 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2135 |            97 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2137 |            97 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2138 |            97 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2168 |            30 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2169 |            30 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2170 |            30 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2171 |            30 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2212 |            13 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2213 |            13 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2214 |            13 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2215 |            13 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2276 |            58 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2277 |            58 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2279 |            58 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2280 |            58 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2320 |            14 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2321 |            14 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2322 |            14 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2323 |            14 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2332 |            37 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2333 |            37 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2334 |            37 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2335 |            37 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2431 |            60 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2432 |            60 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2433 |            60 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2434 |            60 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2442 |            33 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2443 |            33 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2444 |            33 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2445 |            33 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2464 |            10 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2465 |            10 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2467 |            10 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2468 |            10 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                2497 |            10 |       0 | forum               | createSocialForum        | use_int          |                   10 |
|                2558 |             5 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                2559 |             5 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                2561 |             5 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                2562 |             5 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                3550 |             2 |       0 | forum               | joinSocialForum          | use_int          |                   10 |
|                3582 |            29 |       0 | general             | maxSecondarySocialForums | use_int          |                   10 |
|                3588 |            10 |       0 | general             | maxSecondarySocialForums | use_int          |                   10 |
|                3609 |            24 |       0 | general             | SigRestrict_lineCount    | use_int          |                   10 |
|                4253 |             4 |       0 | forum               | maxSocialForums          | use_int          |                   10 |
|                4264 |             2 |       0 | forum               | maxSocialForums          | use_int          |                   10 |
|                6473 |           128 |       0 | general             | SigRestrict_imgCount     | use_int          |                   10 |
|                6474 |           128 |       0 | general             | SigRestrict_urlCount     | use_int          |                   10 |
|                6475 |           128 |       0 | general             | SigRestrict_emailCount   | use_int          |                   10 |
|                6476 |           128 |       0 | general             | SigRestrict_mediaCount   | use_int          |                   10 |
|                6477 |           128 |       0 | general             | SigRestrict_lineCount    | use_int          |                   10 |
+---------------------+---------------+---------+---------------------+--------------------------+------------------+----------------------+
71 rows in set (0.01 sec)
 
Last one, then if I'm none the wiser after that, we'll get you to submit a ticket :)
SQL:
SELECT p.permission_group_id, p.permission_id, p.permission_type, pe.permission_value
FROM xf_permission_entry AS pe
LEFT JOIN xf_permission AS p ON
    (pe.permission_id = p.permission_id)
WHERE pe.permission_value_int = '10';
 
Last one, then if I'm none the wiser after that, we'll get you to submit a ticket :)
SQL:
SELECT p.permission_group_id, p.permission_id, p.permission_type, pe.permission_value
FROM xf_permission_entry AS pe
LEFT JOIN xf_permission AS p ON
    (pe.permission_id = p.permission_id)
WHERE pe.permission_value_int = '10';

SQL:
+---------------------+--------------------------+-----------------+------------------+
| permission_group_id | permission_id            | permission_type | permission_value |
+---------------------+--------------------------+-----------------+------------------+
| conversation        | maxRecipients            | integer         | use_int          |
| conversation        | maxRecipients            | integer         | use_int          |
| conversation        | maxRecipients            | integer         | use_int          |
| conversation        | maxRecipients            | integer         | use_int          |
| conversation        | maxRecipients            | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| forum               | joinSocialForum          | flag            | use_int          |
| forum               | createSocialForum        | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| forum               | createSocialForum        | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| forum               | joinSocialForum          | flag            | use_int          |
| general             | maxSecondarySocialForums | integer         | use_int          |
| general             | maxSecondarySocialForums | integer         | use_int          |
| general             | SigRestrict_lineCount    | integer         | use_int          |
| forum               | maxSocialForums          | integer         | use_int          |
| forum               | maxSocialForums          | integer         | use_int          |
| general             | SigRestrict_imgCount     | integer         | use_int          |
| general             | SigRestrict_urlCount     | integer         | use_int          |
| general             | SigRestrict_emailCount   | integer         | use_int          |
| general             | SigRestrict_mediaCount   | integer         | use_int          |
| general             | SigRestrict_lineCount    | integer         | use_int          |
+---------------------+--------------------------+-----------------+------------------+

I spy something that looks off
 
I spy something that looks off
Indeed :)

It looks like my hunch was mostly correct, though I was trying to prove it with the wrong logic. It looks like the joinSocialForum permission is set as a flag permission, which is generally deny, allow, etc. values. But in this case they have use_int which is exclusively used by integer permissions.
SQL:
UPDATE xf_permission
SET permission_type = 'integer'
WHERE permission_id = 'joinSocialForum'
Assuming they are supposed to be integers, rather than a flag, that should solve the problem. Though I'd recommend reporting this to the author of the add-on, even if it's not yet available in XF2, so they can figure out what caused that in the first place.

You should still report it to them, but I'm tempted to make this slightly more robust against faulty data such as this so I'll move this to bugs and give it some thought.
 
Back
Top Bottom