Skip to content

Commit

Permalink
feat(composer): updated react/promise to v3.2 to support PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Dec 17, 2024
1 parent ab40d96 commit 8197ad5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 10 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions engine/classes/Elgg/Cli/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
},
Expand Down Expand Up @@ -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'));
},
Expand Down
7 changes: 3 additions & 4 deletions engine/classes/Elgg/Upgrade/UpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ 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');
$forward_url = elgg_normalize_site_url($forward_url);

$upgrade = _elgg_services()->upgrades->run();

$upgrade->done(
$upgrade->then(
function () use (&$response, $forward_url) {
$response = elgg_ok_response('', elgg_echo('upgrade:core'), $forward_url);
},
Expand Down
25 changes: 13 additions & 12 deletions engine/classes/Elgg/UpgradeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected function up(): Promise {
\Elgg\Cache\EventHandlers::disable();
elgg_clear_caches();

return $resolve();
return $resolve(true);
});
}

Expand All @@ -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();
Expand All @@ -88,7 +89,7 @@ protected function down(): Promise {

$this->events->triggerAfter('upgrade', 'system', null);

return $resolve();
return $resolve(true);
});
}

Expand All @@ -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) {
Expand All @@ -120,9 +121,9 @@ protected function runUpgrades($upgrades): Promise {
]);

return $reject(new \RuntimeException($msg));
} else {
return $resolve($result);
}

return $resolve($result);
});
}

Expand All @@ -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);

Expand All @@ -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);
},
Expand Down
2 changes: 1 addition & 1 deletion engine/tests/phpunit/unit/ElggPluginUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function testUsesBootstrapOnUpgrade() {
};

$upgrade = _elgg_services()->upgrades->run();
$upgrade->done($assert, $fail);
$upgrade->then($assert, $fail);

$this->assertEquals(1, $assertions);
}
Expand Down

0 comments on commit 8197ad5

Please sign in to comment.