1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 21:31:28 +01:00

Fix connection to the database when a password is accidentally provided but none is required

This commit is contained in:
Daniil Gentili 2023-08-14 16:29:04 +02:00
parent 909ed2f238
commit 1b6d7e5a36
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
12 changed files with 39 additions and 20 deletions

View File

@ -699,8 +699,8 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.updatePinnedMessage.html" name="messages.updatePinnedMessage">Pin a message: messages.updatePinnedMessage</a> * <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.updatePinnedMessage.html" name="messages.updatePinnedMessage">Pin a message: messages.updatePinnedMessage</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.updatePinnedForumTopic.html" name="channels.updatePinnedForumTopic">Pin or unpin forum topics: channels.updatePinnedForumTopic</a> * <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.updatePinnedForumTopic.html" name="channels.updatePinnedForumTopic">Pin or unpin forum topics: channels.updatePinnedForumTopic</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.toggleDialogPin.html" name="messages.toggleDialogPin">Pin/unpin a dialog: messages.toggleDialogPin</a> * <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.toggleDialogPin.html" name="messages.toggleDialogPin">Pin/unpin a dialog: messages.toggleDialogPin</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callplay-int-id-danog-madelineproto-localfile-danog-madelineproto-remoteurl-danog-madelineproto-ipc-wrapper-readablestream-string-file-void" name="callPlay">Play file in call: callPlay</a> * <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callplay-int-id-danog-madelineproto-localfile-danog-madelineproto-remoteurl-amp-bytestream-readablestream-file-void" name="callPlay">Play file in call: callPlay</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callplayonhold-int-id-string-localfile-remoteurl-amp-bytestream-readablestream-files-void" name="callPlayOnHold">Play files on hold in call: callPlayOnHold</a> * <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callplayonhold-int-id-localfile-remoteurl-amp-bytestream-readablestream-files-void" name="callPlayOnHold">Play files on hold in call: callPlayOnHold</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.getMessages.html" name="channels.getMessages">Please use the event handler: channels.getMessages</a> * <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.getMessages.html" name="channels.getMessages">Please use the event handler: channels.getMessages</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getHistory.html" name="messages.getHistory">Please use the event handler: messages.getHistory</a> * <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getHistory.html" name="messages.getHistory">Please use the event handler: messages.getHistory</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getMessages.html" name="messages.getMessages">Please use the event handler: messages.getMessages</a> * <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getMessages.html" name="messages.getMessages">Please use the event handler: messages.getMessages</a>

View File

@ -91,7 +91,10 @@
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"danog\\MadelineProto\\": "src" "danog\\MadelineProto\\": "src"
} },
"files": [
"src/polyfill.php"
]
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {

2
docs

@ -1 +1 @@
Subproject commit 3c53d289d2cf28630f61c267067be80d7b80712b Subproject commit 71f5df203c83c7ef7f4454c09966e03a2f6307da

View File

@ -313,7 +313,9 @@ class MyEventHandler extends SimpleEventHandler
$settings = new Settings; $settings = new Settings;
$settings->getLogger()->setLevel(Logger::LEVEL_ULTRA_VERBOSE); $settings->getLogger()->setLevel(Logger::LEVEL_ULTRA_VERBOSE);
// You can also use Redis, MySQL or PostgreSQL // You can also use Redis, MySQL or PostgreSQL.
// Data is migrated automatically.
//
// $settings->setDb((new Redis)->setDatabase(0)->setPassword('pony')); // $settings->setDb((new Redis)->setDatabase(0)->setPassword('pony'));
// $settings->setDb((new Postgres)->setDatabase('MadelineProto')->setUsername('daniil')->setPassword('pony')); // $settings->setDb((new Postgres)->setDatabase('MadelineProto')->setUsername('daniil')->setPassword('pony'));
// $settings->setDb((new Mysql)->setDatabase('MadelineProto')->setUsername('daniil')->setPassword('pony')); // $settings->setDb((new Mysql)->setDatabase('MadelineProto')->setUsername('daniil')->setPassword('pony'));

View File

@ -23,6 +23,7 @@ use danog\MadelineProto\Exception;
use danog\MadelineProto\Logger; use danog\MadelineProto\Logger;
use danog\MadelineProto\Settings\Database\Mysql as DatabaseMysql; use danog\MadelineProto\Settings\Database\Mysql as DatabaseMysql;
use PDO; use PDO;
use PDOException;
use Throwable; use Throwable;
/** /**
@ -58,13 +59,23 @@ final class Mysql
throw Exception::extension('pdo_mysql'); throw Exception::extension('pdo_mysql');
} }
self::$connections[$dbKey] = [ try {
new MysqlConnectionPool($config, $settings->getMaxConnections(), $settings->getIdleTimeout()), $pdo = new PDO(
new PDO(
"mysql:host={$host};port={$port};charset=UTF8", "mysql:host={$host};port={$port};charset=UTF8",
$settings->getUsername(), $settings->getUsername(),
$settings->getPassword(), $settings->getPassword(),
) );
} catch (PDOException $e) {
$config = $config->withPassword(null);
$pdo = new PDO(
"mysql:host={$host};port={$port};charset=UTF8",
$settings->getUsername(),
);
}
self::$connections[$dbKey] = [
new MysqlConnectionPool($config, $settings->getMaxConnections(), $settings->getIdleTimeout()),
$pdo
]; ];
} }
} finally { } finally {

View File

@ -121,5 +121,3 @@ final class MemoryArray extends ArrayIterator implements DbArray
return $this; return $this;
} }
} }
\class_alias(MemoryArray::class, '\\danog\\MadelineProto\\Db\\NullCache\\MemoryArray');

View File

@ -142,5 +142,3 @@ final class MysqlArray extends SqlArray
"); ");
} }
} }
\class_alias(MysqlArray::class, '\\danog\\MadelineProto\\Db\\NullCache\\MysqlArray');

View File

@ -109,5 +109,3 @@ final class PostgresArray extends PostgresArrayBytea
"); ");
} }
} }
\class_alias(PostgresArray::class, '\\danog\\MadelineProto\\Db\\NullCache\\PostgresArray');

View File

@ -127,5 +127,3 @@ class PostgresArrayBytea extends SqlArray
"); ");
} }
} }
\class_alias(PostgresArrayBytea::class, '\\danog\\MadelineProto\\Db\\NullCache\\PostgresArrayBytea');

View File

@ -155,5 +155,3 @@ final class RedisArray extends DriverArray
} }
} }
} }
\class_alias(RedisArray::class, '\\danog\\MadelineProto\\Db\\NullCache\\RedisArray');

View File

@ -242,7 +242,6 @@ final class MinDatabase implements TLCallback
public function clearPeer(int $id): void public function clearPeer(int $id): void
{ {
unset($this->db[$id], $this->pendingDb[$id]); unset($this->db[$id], $this->pendingDb[$id]);
} }
public function __debugInfo() public function __debugInfo()
{ {

14
src/polyfill.php Normal file
View File

@ -0,0 +1,14 @@
<?php declare(strict_types=1);
if (class_exists('\\danog\\MadelineProto\\Db\\NullCache\\MysqlArray')) {
return;
}
use danog\MadelineProto\Db\MysqlArray;
use danog\MadelineProto\Db\PostgresArray;
use danog\MadelineProto\Db\PostgresArrayBytea;
use danog\MadelineProto\Db\RedisArray;
class_alias(MysqlArray::class, '\\danog\\MadelineProto\\Db\\NullCache\\MysqlArray');
class_alias(PostgresArray::class, '\\danog\\MadelineProto\\Db\\NullCache\\PostgresArray');
class_alias(PostgresArrayBytea::class, '\\danog\\MadelineProto\\Db\\NullCache\\PostgresArrayBytea');
class_alias(RedisArray::class, '\\danog\\MadelineProto\\Db\\NullCache\\RedisArray');