/** * Fix old 1.x usergroups-based permissions to 2.x access-levels in lists and in tabs * * @param \CB\Database\Table\TabTable|\CB\Database\Table\ListTable $loaderTabOrList * @param string $titleIfCreate Title for newly created access levels if needed (e.g. 'CB Tab access') * @return void * * @throws \RuntimeException */ private function convertUserGroupsToViewAccessLevels($loaderTabOrList, $titleIfCreate) { $loaderTabOrList->getDbo()->setQuery('SELECT * FROM ' . $loaderTabOrList->getDbo()->NameQuote($loaderTabOrList->getTableName())); $allTabsOrLists = $loaderTabOrList->loadTrueObjects(); foreach ($allTabsOrLists as $tabOrList) { if (isset($tabOrList->useraccessgroupid)) { if ((int) $tabOrList->useraccessgroupid == 0) { // Already converted or new in 2.x+: continue; } $alreadyConvertedButNotZeroed = (int) $tabOrList->useraccessgroupid == -2 && $tabOrList->viewaccesslevel; if ((int) $tabOrList->viewaccesslevel <= 1 && !$alreadyConvertedButNotZeroed) { // Still database default: Convert: $tabOrList->viewaccesslevel = Application::CmsPermissions()->convertOldGroupToViewAccessLevel($tabOrList->useraccessgroupid, $titleIfCreate); } // Always set to 0 after conversion: $tabOrList->useraccessgroupid = 0; $tabOrList->store(); } } }