Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Psr\Http\Message\ResponseInterface;
use wcf\acp\page\PackageListPage;
use wcf\action\AbstractSecureAction;
use wcf\data\application\ApplicationAction;
use wcf\command\application\MarkApplicationAsTainted;
use wcf\data\package\installation\queue\PackageInstallationQueue;
use wcf\data\package\installation\queue\PackageInstallationQueueEditor;
use wcf\data\package\Package;
use wcf\system\application\ApplicationHandler;
use wcf\system\exception\IllegalLinkException;
use wcf\system\package\PackageUninstallationDispatcher;
use wcf\system\request\LinkHandler;
Expand Down Expand Up @@ -116,8 +117,10 @@ protected function stepPrepare(): ResponseInterface

// mark package as tainted if it is an app
if ($package->isApplication) {
$applicationAction = new ApplicationAction([$package->packageID], 'markAsTainted');
$applicationAction->executeAction();
$application = ApplicationHandler::getInstance()->getApplicationByID($package->packageID);
\assert($application !== null);

(new MarkApplicationAsTainted($application))();
}

$this->installation->nodeBuilder->purgeNodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use wcf\data\page\PageNodeTree;
use wcf\form\AbstractForm;
use wcf\system\application\ApplicationHandler;
use wcf\system\cache\builder\ApplicationCacheBuilder;
use wcf\system\cache\builder\PageCacheBuilder;
use wcf\system\cache\builder\RoutingCacheBuilder;
use wcf\system\cache\eager\ApplicationCache;
use wcf\system\exception\UserInputException;
use wcf\system\Regex;
use wcf\system\style\StyleHandler;
Expand Down Expand Up @@ -188,7 +188,7 @@ public function save()
ApplicationHandler::rebuild();

// Reset caches to reflect the new landing pages.
ApplicationCacheBuilder::getInstance()->reset();
(new ApplicationCache())->rebuild();
PageCacheBuilder::getInstance()->reset();
RoutingCacheBuilder::getInstance()->reset();
StyleHandler::resetStylesheets();
Expand Down
6 changes: 2 additions & 4 deletions wcfsetup/install/files/lib/acp/form/RescueModeForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace wcf\acp\form;

use Laminas\Diactoros\Response\RedirectResponse;
use wcf\command\application\SynchronizeCookieDomain;
use wcf\data\application\Application;
use wcf\data\application\ApplicationAction;
use wcf\data\application\ApplicationEditor;
use wcf\data\application\ApplicationList;
use wcf\data\user\authentication\failure\UserAuthenticationFailure;
Expand Down Expand Up @@ -333,9 +333,7 @@ public function save()
]);
}

// rebuild cookie domain and paths
$applicationAction = new ApplicationAction([], 'rebuild');
$applicationAction->executeAction();
(new SynchronizeCookieDomain())();

// reload currently active application to avoid outdated cache data
$application = ApplicationHandler::getInstance()->getActiveApplication();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace wcf\command\application;

use wcf\data\application\Application;
use wcf\data\application\ApplicationEditor;
use wcf\system\cache\eager\ApplicationCache;

/**
* Marking an application as tainted prevents it from being loaded during its
* uninstallation. This MUST NOT be called outside of an active uninstallation.
*
* @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 MarkApplicationAsTainted
{
public function __construct(
public readonly Application $application
) {}

public function __invoke(): void
{
$applicationEditor = new ApplicationEditor($this->application);
$applicationEditor->update(['isTainted' => 1]);

(new ApplicationCache())->rebuild();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace wcf\data\application;

use wcf\command\application\MarkApplicationAsTainted;
use wcf\command\application\SynchronizeCookieDomain;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\system\cache\builder\ApplicationCacheBuilder;
use wcf\system\language\LanguageFactory;
use wcf\system\Regex;
use wcf\system\WCF;

/**
* Executes application-related actions.
Expand All @@ -24,61 +22,27 @@ class ApplicationAction extends AbstractDatabaseObjectAction
*/
protected $className = ApplicationEditor::class;

/**
* application editor object
* @var ApplicationEditor
*/
public $applicationEditor;

/**
* Assigns a list of applications to a group and computes cookie domain.
*
* @return void
*
* @deprecated 6.3 use `SynchronizeCookieDomain`
*/
public function rebuild()
{
if (empty($this->objects)) {
$this->readObjects();
}

$sql = "UPDATE wcf1_application
SET cookieDomain = ?
WHERE packageID = ?";
$statement = WCF::getDB()->prepare($sql);

// calculate cookie domain
$regex = new Regex(':[0-9]+');
WCF::getDB()->beginTransaction();
foreach ($this->getObjects() 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();

// rebuild templates
LanguageFactory::getInstance()->deleteLanguageCache();

// reset application cache
ApplicationCacheBuilder::getInstance()->reset();
(new SynchronizeCookieDomain())();
}

/**
* Marks an application as tainted, prevents loading it during uninstallation.
*
* @return void
*
* @deprecated 6.3 use `MarkApplicationAsTainted`
*/
public function markAsTainted()
{
$applicationEditor = $this->getSingleObject();
$applicationEditor->update(['isTainted' => 1]);

ApplicationCacheBuilder::getInstance()->reset();
(new MarkApplicationAsTainted($this->getSingleObject()->getDecoratedObject()))();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use wcf\data\DatabaseObjectEditor;
use wcf\data\IEditableCachedObject;
use wcf\system\cache\builder\ApplicationCacheBuilder;
use wcf\system\cache\eager\ApplicationCache;

/**
* Provides functions to edit applications.
Expand All @@ -29,6 +29,6 @@ class ApplicationEditor extends DatabaseObjectEditor implements IEditableCachedO
*/
public static function resetCache()
{
ApplicationCacheBuilder::getInstance()->reset();
(new ApplicationCache())->rebuild();
}
}
4 changes: 2 additions & 2 deletions wcfsetup/install/files/lib/data/page/Page.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use wcf\data\user\User;
use wcf\system\acl\simple\SimpleAclResolver;
use wcf\system\application\ApplicationHandler;
use wcf\system\cache\builder\ApplicationCacheBuilder;
use wcf\system\cache\builder\RoutingCacheBuilder;
use wcf\system\cache\eager\ApplicationCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\SystemException;
use wcf\system\language\LanguageFactory;
Expand Down Expand Up @@ -297,7 +297,7 @@ public function setAsLandingPage()
WCF::getDB()->commitTransaction();

// reset caches to reflect new landing page
ApplicationCacheBuilder::getInstance()->reset();
(new ApplicationCache())->rebuild();
RoutingCacheBuilder::getInstance()->reset();
}

Expand Down
Loading