Skip to content

Commit 442ae80

Browse files
authored
Merge pull request #6329 from WoltLab/6.3-condition-conditions
Implement user condition types
2 parents 8dfdcd4 + 18b3879 commit 442ae80

File tree

40 files changed

+1562
-128
lines changed

40 files changed

+1562
-128
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('isLegacy'),
1820
]),
1921
];

wcfsetup/install/files/acp/templates/userGroupAssignmentList.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
</nav>
1515
</header>
1616

17+
{if $hasLegacyObjects}
18+
<woltlab-core-notice type="warning">
19+
{lang}wcf.acp.group.assignment.legacyNotice{/lang}
20+
</woltlab-core-notice>
21+
{/if}
22+
1723
<div class="section">
1824
{unsafe:$gridView->render()}
1925
</div>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
isLegacy = ?
15+
WHERE assignmentID = ?";
16+
$statement = WCF::getDB()->prepare($sql);
17+
foreach ($exportedConditions as $assignmentID => $conditionData) {
18+
renameObjectTypes($conditionData);
19+
20+
$statement->execute([
21+
JSON::encode($conditionData),
22+
1,
23+
$assignmentID,
24+
]);
25+
}
26+
27+
/**
28+
* Rename the object types so that the migration functions can handle them.
29+
* @see \wcf\system\condition\provider\UserConditionProvider
30+
*
31+
* @param array<string, mixed> $conditionData
32+
*/
33+
function renameObjectTypes(array &$conditionData): void
34+
{
35+
$objectTypeMap = [
36+
'com.woltlab.wcf.username' => 'com.woltlab.wcf.user.username',
37+
'com.woltlab.wcf.email' => 'com.woltlab.wcf.user.email',
38+
'com.woltlab.wcf.userGroup' => 'com.woltlab.wcf.user.userGroup',
39+
'com.woltlab.wcf.languages' => 'com.woltlab.wcf.user.languages',
40+
'com.woltlab.wcf.registrationDate' => 'com.woltlab.wcf.user.registrationDate',
41+
'com.woltlab.wcf.registrationDateInterval' => 'com.woltlab.wcf.user.registrationDateInterval',
42+
'com.woltlab.wcf.avatar' => 'com.woltlab.wcf.user.avatar',
43+
'com.woltlab.wcf.signature' => 'com.woltlab.wcf.user.signature',
44+
'com.woltlab.wcf.coverPhoto' => 'com.woltlab.wcf.user.coverPhoto',
45+
'com.woltlab.wcf.state' => 'com.woltlab.wcf.user.state',
46+
'com.woltlab.wcf.activityPoints' => 'com.woltlab.wcf.user.activityPoints',
47+
'com.woltlab.wcf.likesReceived' => 'com.woltlab.wcf.user.likesReceived',
48+
// TODO 'com.woltlab.wcf.userOptions'
49+
'com.woltlab.wcf.userTrophyCondition' => 'com.woltlab.wcf.user.trophyCondition',
50+
'com.woltlab.wcf.trophyPoints' => 'com.woltlab.wcf.user.trophyPoints',
51+
];
52+
53+
foreach ($objectTypeMap as $currentName => $newName) {
54+
if (isset($conditionData[$currentName])) {
55+
$conditionData[$newName] = $conditionData[$currentName];
56+
unset($conditionData[$currentName]);
57+
}
58+
}
59+
}

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

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

55
use wcf\data\user\group\assignment\UserGroupAssignment;
66
use wcf\system\exception\IllegalLinkException;
7+
use wcf\system\exception\NamedUserException;
8+
use wcf\system\WCF;
9+
use wcf\util\HtmlString;
710

811
/**
912
* Shows the form to edit an existing automatic user group assignment.
@@ -39,5 +42,11 @@ public function readParameters()
3942
if (!$this->formObject->assignmentID) {
4043
throw new IllegalLinkException();
4144
}
45+
46+
if ($this->formObject->isLegacy) {
47+
throw new NamedUserException(
48+
HtmlString::fromSafeHtml(WCF::getLanguage()->getDynamicVariable('wcf.acp.group.assignment.legacyNotice'))
49+
);
50+
}
4251
}
4352
}

wcfsetup/install/files/lib/acp/page/UserGroupAssignmentListPage.class.php

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

55
use wcf\page\AbstractGridViewPage;
66
use wcf\system\gridView\admin\UserGroupAssignmentGridView;
7+
use wcf\system\WCF;
78

89
/**
910
* Lists the available automatic user group assignments.
@@ -31,4 +32,25 @@ protected function createGridView(): UserGroupAssignmentGridView
3132
{
3233
return new UserGroupAssignmentGridView();
3334
}
35+
36+
#[\Override]
37+
public function assignVariables()
38+
{
39+
parent::assignVariables();
40+
41+
WCF::getTPL()->assign([
42+
'hasLegacyObjects' => $this->hasLegacyObjects(),
43+
]);
44+
}
45+
46+
private function hasLegacyObjects(): bool
47+
{
48+
$sql = "SELECT COUNT(*) AS count
49+
FROM wcf1_user_group_assignment
50+
WHERE isLegacy = ?";
51+
$statement = WCF::getDB()->prepare($sql);
52+
$statement->execute([1]);
53+
54+
return $statement->fetchColumn() > 0;
55+
}
3456
}

wcfsetup/install/files/lib/action/ConditionAddAction.class.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,22 @@ private function getForm(AbstractConditionProvider $provider): Psr15DialogForm
8282
self::class,
8383
WCF::getLanguage()->get('wcf.condition.add')
8484
);
85+
$options = \array_map(
86+
static fn (IConditionType $conditionType) => WCF::getLanguage()->get($conditionType->getLabel()),
87+
$provider->getConditionTypes()
88+
);
89+
$collator = new \Collator(WCF::getLanguage()->getLocale());
90+
\uasort(
91+
$options,
92+
static fn (string $a, string $b) => $collator->compare($a, $b)
93+
);
8594

8695
$form->appendChild(
8796
SingleSelectionFormField::create('conditionType')
8897
->label('wcf.condition.condition')
8998
->filterable()
9099
->required()
91-
->options(
92-
\array_map(
93-
static fn (IConditionType $conditionType) => WCF::getLanguage()->get($conditionType->getLabel()),
94-
$provider->getConditionTypes()
95-
)
96-
)
100+
->options($options)
97101
);
98102

99103
$form->markRequiredFields(false);

wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static function (\wcf\event\worker\RebuildWorkerCollecting $event) {
9797
$event->register(\wcf\system\worker\UnfurlUrlRebuildDataWorker::class, 450);
9898
$event->register(\wcf\system\worker\FileRebuildDataWorker::class, 475);
9999
$event->register(\wcf\system\worker\SitemapRebuildWorker::class, 500);
100+
$event->register(\wcf\system\worker\UserGroupAssignmentRebuildDataWorker::class, 600);
100101
$event->register(\wcf\system\worker\StatDailyRebuildDataWorker::class, 800);
101102
}
102103
);

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 $isLegacy indicates whether the conditions need to be migrated to the new format
2223
*/
2324
class UserGroupAssignment extends DatabaseObject implements IRouteController
2425
{

0 commit comments

Comments
 (0)