-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathSynchronizeCookieDomain.class.php
More file actions
64 lines (54 loc) · 1.68 KB
/
SynchronizeCookieDomain.class.php
File metadata and controls
64 lines (54 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace wcf\command\application;
use wcf\data\application\Application;
use wcf\data\application\ApplicationList;
use wcf\system\cache\eager\ApplicationCache;
use wcf\system\language\LanguageFactory;
use wcf\system\Regex;
use wcf\system\WCF;
/**
* Synchronizes the cookie domain for all installed apps.
*
* @author Olaf Braun
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
*/
final class SynchronizeCookieDomain
{
public function __invoke(): void
{
$sql = "UPDATE wcf1_application
SET cookieDomain = ?
WHERE packageID = ?";
$statement = WCF::getDB()->prepare($sql);
$regex = new Regex(':[0-9]+');
WCF::getDB()->beginTransaction();
foreach ($this->getApplications() as $application) {
$domainName = $application->domainName;
if (\str_ends_with($regex->replace($domainName, ''), $application->cookieDomain)) {
$domainName = $application->cookieDomain;
}
$statement->execute([
$domainName,
$application->packageID,
]);
}
WCF::getDB()->commitTransaction();
$this->resetCache();
}
/**
* @return Application[]
*/
private function getApplications(): array
{
$applicationList = new ApplicationList();
$applicationList->readObjects();
return $applicationList->getObjects();
}
private function resetCache(): void
{
LanguageFactory::getInstance()->deleteLanguageCache();
(new ApplicationCache())->rebuild();
}
}