diff --git a/composer.json b/composer.json index bb4bc03318..42ee543ab9 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "php-di/php-di": "~7.0.6", "phpfastcache/phpfastcache": "~9.2.3", "psr/log": "^2.0 || ^3.0", - "react/promise": "^2.5", + "react/promise": "^3.2", "roave/security-advisories": "dev-master", "robmorgan/phinx": "~0.16.0", "symfony/console": "~6.4", diff --git a/composer.lock b/composer.lock index 57e0eec416..f3c60ac43f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f18ef2410f39c65de8a3b0d37386ced1", + "content-hash": "e7f76b62ed6bb7a98f39d8bcd6557363", "packages": [ { "name": "cakephp/chronos", @@ -3423,23 +3423,24 @@ }, { "name": "react/promise", - "version": "v2.11.0", + "version": "v3.2.0", "source": { "type": "git", "url": "https://github.com/reactphp/promise.git", - "reference": "1a8460931ea36dc5c76838fec5734d55c88c6831" + "reference": "8a164643313c71354582dc850b42b33fa12a4b63" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/1a8460931ea36dc5c76838fec5734d55c88c6831", - "reference": "1a8460931ea36dc5c76838fec5734d55c88c6831", + "url": "https://api.github.com/repos/reactphp/promise/zipball/8a164643313c71354582dc850b42b33fa12a4b63", + "reference": "8a164643313c71354582dc850b42b33fa12a4b63", "shasum": "" }, "require": { - "php": ">=5.4.0" + "php": ">=7.1.0" }, "require-dev": { - "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + "phpstan/phpstan": "1.10.39 || 1.4.10", + "phpunit/phpunit": "^9.6 || ^7.5" }, "type": "library", "autoload": { @@ -3483,7 +3484,7 @@ ], "support": { "issues": "https://github.com/reactphp/promise/issues", - "source": "https://github.com/reactphp/promise/tree/v2.11.0" + "source": "https://github.com/reactphp/promise/tree/v3.2.0" }, "funding": [ { @@ -3491,7 +3492,7 @@ "type": "open_collective" } ], - "time": "2023-11-16T16:16:50+00:00" + "time": "2024-05-24T10:39:05+00:00" }, { "name": "roave/security-advisories", diff --git a/engine/classes/Elgg/Cli/UpgradeCommand.php b/engine/classes/Elgg/Cli/UpgradeCommand.php index c091ff4537..a260e800b9 100644 --- a/engine/classes/Elgg/Cli/UpgradeCommand.php +++ b/engine/classes/Elgg/Cli/UpgradeCommand.php @@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $upgrades = _elgg_services()->upgrades->getPendingUpgrades(false); $job = _elgg_services()->upgrades->run($upgrades); - $job->done( + $job->then( function () { $this->notice(elgg_echo('cli:upgrade:system:upgraded')); }, @@ -99,7 +99,7 @@ function ($errors) use (&$return) { $upgrades = _elgg_services()->upgrades->getPendingUpgrades(true); $job = _elgg_services()->upgrades->run($upgrades); - $job->done( + $job->then( function () { $this->notice(elgg_echo('cli:upgrade:async:upgraded')); }, diff --git a/engine/classes/Elgg/Upgrade/UpgradeController.php b/engine/classes/Elgg/Upgrade/UpgradeController.php index cb1c89dcd1..20cce54bf6 100644 --- a/engine/classes/Elgg/Upgrade/UpgradeController.php +++ b/engine/classes/Elgg/Upgrade/UpgradeController.php @@ -20,11 +20,10 @@ class UpgradeController { * * @param Request $request Request * - * @return ResponseBuilder + * @return null|ResponseBuilder * @throws InternalServerErrorException */ - public function __invoke(Request $request) { - + public function __invoke(Request $request): ?ResponseBuilder { $response = null; $forward_url = $request->getParam('forward', 'admin'); @@ -32,7 +31,7 @@ public function __invoke(Request $request) { $upgrade = _elgg_services()->upgrades->run(); - $upgrade->done( + $upgrade->then( function () use (&$response, $forward_url) { $response = elgg_ok_response('', elgg_echo('upgrade:core'), $forward_url); }, diff --git a/engine/classes/Elgg/UpgradeService.php b/engine/classes/Elgg/UpgradeService.php index 32c355cc4e..81605dd5ef 100644 --- a/engine/classes/Elgg/UpgradeService.php +++ b/engine/classes/Elgg/UpgradeService.php @@ -10,6 +10,7 @@ use Elgg\Upgrade\Locator; use Elgg\Upgrade\Loop; use Elgg\Upgrade\Result; +use React\Promise\PromiseInterface; use function React\Promise\all; use React\Promise\Deferred; use React\Promise\Promise; @@ -67,7 +68,7 @@ protected function up(): Promise { \Elgg\Cache\EventHandlers::disable(); elgg_clear_caches(); - return $resolve(); + return $resolve(true); }); } @@ -79,7 +80,7 @@ protected function up(): Promise { protected function down(): Promise { return new Promise(function ($resolve, $reject) { if (!$this->events->trigger('upgrade', 'system', null)) { - return $reject(); + return $reject(false); } elgg_invalidate_caches(); @@ -88,7 +89,7 @@ protected function down(): Promise { $this->events->triggerAfter('upgrade', 'system', null); - return $resolve(); + return $resolve(true); }); } @@ -97,9 +98,9 @@ protected function down(): Promise { * * @param \ElggUpgrade[] $upgrades Upgrades to run * - * @return Promise + * @return PromiseInterface */ - protected function runUpgrades($upgrades): Promise { + protected function runUpgrades($upgrades): PromiseInterface { $promises = []; foreach ($upgrades as $upgrade) { @@ -120,9 +121,9 @@ protected function runUpgrades($upgrades): Promise { ]); return $reject(new \RuntimeException($msg)); - } else { - return $resolve($result); } + + return $resolve($result); }); } @@ -134,9 +135,9 @@ protected function runUpgrades($upgrades): Promise { * * @param \ElggUpgrade[] $upgrades Upgrades to run * - * @return Promise + * @return PromiseInterface */ - public function run($upgrades = null): Promise { + public function run($upgrades = null): PromiseInterface { // turn off time limit set_time_limit(3600); @@ -156,13 +157,13 @@ public function run($upgrades = null): Promise { $upgrades = $this->getPendingUpgrades(false); } - $this->up()->done( + $this->up()->then( function () use ($resolve, $reject, $upgrades) { all([ $this->runUpgrades($upgrades), - ])->done( + ])->finally( function () use ($resolve, $reject) { - $this->down()->done( + $this->down()->then( function ($result) use ($resolve) { return $resolve($result); }, diff --git a/engine/tests/phpunit/unit/ElggPluginUnitTest.php b/engine/tests/phpunit/unit/ElggPluginUnitTest.php index 8dca8c26fe..fb892d35fe 100644 --- a/engine/tests/phpunit/unit/ElggPluginUnitTest.php +++ b/engine/tests/phpunit/unit/ElggPluginUnitTest.php @@ -243,7 +243,7 @@ public function testUsesBootstrapOnUpgrade() { }; $upgrade = _elgg_services()->upgrades->run(); - $upgrade->done($assert, $fail); + $upgrade->then($assert, $fail); $this->assertEquals(1, $assertions); }