From f9fc6d8370e12ef767693099a1e8c790d7aba0f0 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 27 Aug 2023 11:04:18 +0200 Subject: [PATCH] Always run updateSettings if settings are passed to constructor --- composer.json | 2 +- docs | 2 +- examples/plugins/Danogentili/OnlinePlugin.php | 8 ++++++++ psalm.xml | 2 ++ src/API.php | 3 +++ src/DataCenter.php | 8 ++++---- src/Wrappers/Start.php | 4 ---- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index f5875f7a9..7e568e8cc 100644 --- a/composer.json +++ b/composer.json @@ -123,7 +123,7 @@ "test-php56": "tests/test-conversion.sh 5", "cs": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v --diff --dry-run", "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v --diff", - "psalm": "psalm.phar --no-cache", + "psalm": "psalm --no-cache", "docs": "php tools/build_docs.php", "docs-fix": "tools/fix_docs.sh", "test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit --coverage-text", diff --git a/docs b/docs index f855706e1..099e46477 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit f855706e1b65ce6b4c5a6babed5928a138d10f56 +Subproject commit 099e464774b3001f8bb54d9dd0ce61875ad5fceb diff --git a/examples/plugins/Danogentili/OnlinePlugin.php b/examples/plugins/Danogentili/OnlinePlugin.php index 909bfbec4..ee95068fd 100644 --- a/examples/plugins/Danogentili/OnlinePlugin.php +++ b/examples/plugins/Danogentili/OnlinePlugin.php @@ -13,6 +13,14 @@ final class OnlinePlugin extends PluginEventHandler { private bool $isOnline = true; + /** + * Returns a list of names for properties that will be automatically saved to the session database (MySQL/postgres/redis if configured, the session file otherwise). + */ + public function __sleep(): array + { + return ['isOnline']; + } + public function setOnline(bool $online): void { $this->isOnline = $online; diff --git a/psalm.xml b/psalm.xml index f0503b560..62b683c10 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,6 +2,8 @@ connectToMadelineProto($settings)) { + if (!$settings instanceof SettingsEmpty) { + EventLoop::queue($this->updateSettings(...), $settings); + } return; // OK } diff --git a/src/DataCenter.php b/src/DataCenter.php index bcdc2f901..90a76697a 100644 --- a/src/DataCenter.php +++ b/src/DataCenter.php @@ -282,10 +282,6 @@ final class DataCenter */ public function generateContexts(int $dc_number, ?ConnectContext $context = null): array { - if (!isset($this->dclist[$test][$ipv6][$dc_number])) { - return []; - } - $ctxs = []; $combos = []; $test = $this->settings->getTestMode() ? 'test' : 'main'; @@ -326,6 +322,10 @@ final class DataCenter } $combos[] = $default; + if (!isset($this->dclist[$test][$ipv6][$dc_number])) { + return []; + } + $only = $this->dclist[$test][$ipv6][$dc_number]['tcpo_only']; if ($only || isset($this->dclist[$test][$ipv6][$dc_number]['secret'])) { $extra = isset($this->dclist[$test][$ipv6][$dc_number]['secret']) ? ['secret' => $this->dclist[$test][$ipv6][$dc_number]['secret']] : []; diff --git a/src/Wrappers/Start.php b/src/Wrappers/Start.php index 8be67a6d4..c10633610 100644 --- a/src/Wrappers/Start.php +++ b/src/Wrappers/Start.php @@ -29,7 +29,6 @@ use danog\MadelineProto\Lang; use danog\MadelineProto\MTProto; use danog\MadelineProto\RPCErrorException; use danog\MadelineProto\Settings; -use danog\MadelineProto\TL\Types\LoginQrCode; use danog\MadelineProto\Tools; use const PHP_SAPI; @@ -58,7 +57,6 @@ trait Start if ($this->getAuthorization() === API::NOT_LOGGED_IN) { $stdout = getStdout(); do { - /** @var ?LoginQrCode */ $qr = $this->qrLogin(); if (!$qr) { $this->serialize(); @@ -218,13 +216,11 @@ trait Start } elseif (isset($_GET['waitQrCodeOrLogin']) || isset($_GET['getQrCode'])) { \header('Content-type: application/json'); try { - /** @var ?LoginQrCode */ $qr = $this->qrLogin(); if (isset($_GET['waitQrCodeOrLogin'])) { $qr = $qr?->waitForLoginOrQrCodeExpiration(Tools::getTimeoutCancellation(5.0)); } } catch (CancelledException) { - /** @var ?LoginQrCode */ $qr = $this->qrLogin(); } if ($qr) {