Skip to content

Commit f2e7e53

Browse files
committed
Add migration support for user group assignment conditions
1 parent b23c9da commit f2e7e53

17 files changed

+187
-54
lines changed

com.woltlab.wcf/package.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@
5151
</instructions>
5252

5353
<!--
54-
Required order of the following steps for the update to 6.2:
55-
<instruction type="database" run="standalone">acp/database/update_com.woltlab.wcf_62_step1.php</instruction>
56-
<instruction type="script">acp/update_com.woltlab.wcf_6.2_contactOptions.php</instruction>
57-
<instruction type="database" run="standalone">acp/database/update_com.woltlab.wcf_62_step2.php</instruction>
54+
Required order of the following steps for the update to 6.3:
55+
<instruction type="database" run="standalone">acp/database/update_com.woltlab.wcf_6.3_step1.php</instruction>
56+
<instruction type="script">acp/update_com.woltlab.wcf_6.3_userGroupAssignment.php</instruction>
5857
-->
5958
</package>

wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.3_step1.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
99
*/
1010

11+
use wcf\system\database\table\column\DefaultFalseBooleanDatabaseTableColumn;
1112
use wcf\system\database\table\column\MediumtextDatabaseTableColumn;
1213
use wcf\system\database\table\PartialDatabaseTable;
1314

1415
return [
1516
PartialDatabaseTable::create('wcf1_user_group_assignment')
1617
->columns([
1718
MediumtextDatabaseTableColumn::create('conditions'),
19+
DefaultFalseBooleanDatabaseTableColumn::create('needMigration'),
1820
]),
1921
];
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use wcf\system\condition\ConditionHandler;
4+
use wcf\system\WCF;
5+
use wcf\util\JSON;
6+
7+
$exportedConditions = ConditionHandler::getInstance()->exportConditions("com.woltlab.wcf.condition.userGroupAssignment");
8+
if ($exportedConditions === []) {
9+
return;
10+
}
11+
12+
$sql = "UPDATE wcf1_user_group_assignment
13+
SET conditions = ?,
14+
needMigration = ?
15+
WHERE assignmentID = ?";
16+
$statement = WCF::getDB()->prepare($sql);
17+
foreach ($exportedConditions as $assignmentID => $conditionData) {
18+
$statement->execute([
19+
JSON::encode($conditionData),
20+
1,
21+
$assignmentID,
22+
]);
23+
}

wcfsetup/install/files/lib/acp/form/UserGroupAssignmentEditForm.class.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use wcf\data\user\group\assignment\UserGroupAssignment;
66
use wcf\system\exception\IllegalLinkException;
7+
use wcf\system\user\group\assignment\command\UserGroupAssignmentMigrateCondition;
78

89
/**
910
* Shows the form to edit an existing automatic user group assignment.
@@ -39,5 +40,10 @@ public function readParameters()
3940
if (!$this->formObject->assignmentID) {
4041
throw new IllegalLinkException();
4142
}
43+
44+
if ($this->formObject->needMigration) {
45+
(new UserGroupAssignmentMigrateCondition($this->formObject))();
46+
$this->formObject = new UserGroupAssignment(\intval($_REQUEST['id']));
47+
}
4248
}
4349
}

wcfsetup/install/files/lib/data/user/group/UserGroupEditor.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use wcf\data\DatabaseObjectEditor;
66
use wcf\data\IEditableCachedObject;
7-
use wcf\system\cache\builder\UserGroupAssignmentCacheBuilder;
87
use wcf\system\cache\builder\UserGroupCacheBuilder;
98
use wcf\system\cache\builder\UserGroupPermissionCacheBuilder;
9+
use wcf\system\cache\eager\UserGroupAssignmentCache;
1010
use wcf\system\exception\SystemException;
1111
use wcf\system\user\storage\UserStorageHandler;
1212
use wcf\system\WCF;
@@ -208,7 +208,7 @@ public static function resetCache()
208208
UserGroupPermissionCacheBuilder::getInstance()->reset();
209209

210210
// https://github.com/WoltLab/WCF/issues/4045
211-
UserGroupAssignmentCacheBuilder::getInstance()->reset();
211+
(new UserGroupAssignmentCache())->rebuild();
212212

213213
// Clear cached group assignments.
214214
UserStorageHandler::getInstance()->resetAll('groupIDs');

wcfsetup/install/files/lib/data/user/group/assignment/UserGroupAssignment.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* @property-read string $title title of the automatic user group assignment
2020
* @property-read int $isDisabled is `1` if the user group assignment is disabled and thus not checked for automatic assignments, otherwise `0`
2121
* @property-read string $conditions JSON-encoded string containing the conditions of the automatic user group assignment
22+
* @property-read bool $needMigration indicates whether the conditions need to be migrated to the new format
2223
*/
2324
class UserGroupAssignment extends DatabaseObject implements IRouteController
2425
{

wcfsetup/install/files/lib/data/user/group/assignment/UserGroupAssignmentEditor.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use wcf\data\DatabaseObjectEditor;
66
use wcf\data\IEditableCachedObject;
7-
use wcf\system\cache\builder\UserGroupAssignmentCacheBuilder;
7+
use wcf\system\cache\eager\UserGroupAssignmentCache;
88

99
/**
1010
* Executes user group assignment-related actions.
@@ -29,6 +29,6 @@ class UserGroupAssignmentEditor extends DatabaseObjectEditor implements IEditabl
2929
*/
3030
public static function resetCache()
3131
{
32-
UserGroupAssignmentCacheBuilder::getInstance()->reset();
32+
(new UserGroupAssignmentCache())->rebuild();
3333
}
3434
}

wcfsetup/install/files/lib/system/cache/builder/UserGroupAssignmentCacheBuilder.class.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22

33
namespace wcf\system\cache\builder;
44

5-
use wcf\data\user\group\assignment\UserGroupAssignmentList;
5+
use wcf\system\cache\eager\UserGroupAssignmentCache;
66

77
/**
88
* Caches the enabled automatic user group assignments.
99
*
1010
* @author Matthias Schmidt
1111
* @copyright 2001-2019 WoltLab GmbH
1212
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
*
14+
* @deprecated 6.2 use `UserGroupAssignmentCache` instead
1315
*/
14-
class UserGroupAssignmentCacheBuilder extends AbstractCacheBuilder
16+
final class UserGroupAssignmentCacheBuilder extends AbstractLegacyCacheBuilder
1517
{
16-
/**
17-
* @inheritDoc
18-
*/
19-
protected function rebuild(array $parameters)
18+
#[\Override]
19+
protected function rebuild(array $parameters): array
2020
{
21-
$assignmentList = new UserGroupAssignmentList();
22-
$assignmentList->getConditionBuilder()->add('isDisabled = ?', [0]);
23-
$assignmentList->readObjects();
21+
return (new UserGroupAssignmentCache())->getCache();
22+
}
2423

25-
return $assignmentList->getObjects();
24+
#[\Override]
25+
public function reset(array $parameters = [])
26+
{
27+
(new UserGroupAssignmentCache())->rebuild();
2628
}
2729
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace wcf\system\cache\eager;
4+
5+
use wcf\data\user\group\assignment\UserGroupAssignment;
6+
use wcf\data\user\group\assignment\UserGroupAssignmentList;
7+
use wcf\system\user\group\assignment\command\UserGroupAssignmentMigrateCondition;
8+
9+
/**
10+
* Caches the enabled automatic user group assignments.
11+
*
12+
* @author Olaf Braun
13+
* @copyright 2001-2025 WoltLab GmbH
14+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15+
* @since 6.3
16+
*
17+
* @extends AbstractEagerCache<array<int, UserGroupAssignment>>
18+
*/
19+
final class UserGroupAssignmentCache extends AbstractEagerCache
20+
{
21+
#[\Override]
22+
protected function getCacheData(): array
23+
{
24+
$assignmentList = $this->getUserGroupAssignments();
25+
26+
$migrationDone = false;
27+
foreach ($assignmentList as $assignment) {
28+
if ($assignment->needMigration) {
29+
(new UserGroupAssignmentMigrateCondition($assignment))();
30+
$migrationDone = true;
31+
}
32+
}
33+
34+
if ($migrationDone) {
35+
// Reload the list to ensure that no disabled assignments are included
36+
return $this->getUserGroupAssignments()->getObjects();
37+
} else {
38+
return $assignmentList->getObjects();
39+
}
40+
}
41+
42+
private function getUserGroupAssignments(): UserGroupAssignmentList
43+
{
44+
$assignmentList = new UserGroupAssignmentList();
45+
$assignmentList->getConditionBuilder()->add('isDisabled = ?', [0]);
46+
$assignmentList->readObjects();
47+
48+
return $assignmentList;
49+
}
50+
}

wcfsetup/install/files/lib/system/condition/provider/UserConditionProvider.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct()
4242
new UserInGroupConditionType(),
4343
new UserNotInGroupConditionType(),
4444
new UserLanguageConditionType(),
45-
new class("avatar", 'avatarFileID') extends AbstractUserIsNullConditionType {},
45+
new class("avatar", 'avatarFileID', 'userAvatar', 'com.woltlab.wcf.avatar') extends AbstractUserIsNullConditionType {},
4646
new UserSignatureConditionType(),
4747
new class("coverPhoto", 'coverPhotoFileID') extends AbstractUserIsNullConditionType {},
4848
new class("isBanned", 'banned') extends AbstractUserBooleanConditionType {},

0 commit comments

Comments
 (0)