mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-23 06:13:54 +01:00
Merge pull request #1014 from danog/db_settings_fix
Fix: Don`t connect to previous instance of same db.
This commit is contained in:
commit
fc55944349
@ -48,7 +48,7 @@ interface DbArray extends DbType, \ArrayAccess, \Countable
|
|||||||
*
|
*
|
||||||
* @psalm-param T $value
|
* @psalm-param T $value
|
||||||
*
|
*
|
||||||
* @return void
|
* @return Promise
|
||||||
*/
|
*/
|
||||||
public function offsetSet($index, $value);
|
public function offsetSet($index, $value);
|
||||||
/**
|
/**
|
||||||
|
@ -84,12 +84,8 @@ abstract class DriverArray implements DbArray
|
|||||||
*/
|
*/
|
||||||
public static function getInstance(string $table, $previous, $settings): Promise
|
public static function getInstance(string $table, $previous, $settings): Promise
|
||||||
{
|
{
|
||||||
if ($previous && \get_class($previous) === static::class && $previous->getTable() === $table) {
|
|
||||||
$instance = &$previous;
|
|
||||||
} else {
|
|
||||||
$instance = new static();
|
$instance = new static();
|
||||||
$instance->setTable($table);
|
$instance->setTable($table);
|
||||||
}
|
|
||||||
|
|
||||||
/** @psalm-suppress UndefinedPropertyAssignment */
|
/** @psalm-suppress UndefinedPropertyAssignment */
|
||||||
$instance->dbSettings = $settings;
|
$instance->dbSettings = $settings;
|
||||||
@ -101,7 +97,7 @@ abstract class DriverArray implements DbArray
|
|||||||
yield from $instance->initConnection($settings);
|
yield from $instance->initConnection($settings);
|
||||||
yield from $instance->prepareTable();
|
yield from $instance->prepareTable();
|
||||||
|
|
||||||
if ($instance !== $previous) {
|
if (static::getClassName($previous) !== static::getClassName($instance)) {
|
||||||
if ($previous instanceof DriverArray) {
|
if ($previous instanceof DriverArray) {
|
||||||
yield from $previous->initStartup();
|
yield from $previous->initStartup();
|
||||||
}
|
}
|
||||||
@ -125,7 +121,7 @@ abstract class DriverArray implements DbArray
|
|||||||
*/
|
*/
|
||||||
protected static function renameTmpTable(self $new, $old): \Generator
|
protected static function renameTmpTable(self $new, $old): \Generator
|
||||||
{
|
{
|
||||||
if ($old && \str_replace('NullCache\\', '', \get_class($old)) === \str_replace('NullCache\\', '', \get_class($new)) && $old->getTable()) {
|
if ($old instanceof SqlArray && $old->getTable()) {
|
||||||
if (
|
if (
|
||||||
$old->getTable() !== $new->getTable() &&
|
$old->getTable() !== $new->getTable() &&
|
||||||
\mb_strpos($new->getTable(), 'tmp') !== 0
|
\mb_strpos($new->getTable(), 'tmp') !== 0
|
||||||
@ -146,10 +142,7 @@ abstract class DriverArray implements DbArray
|
|||||||
*/
|
*/
|
||||||
protected static function migrateDataToDb(self $new, $old): \Generator
|
protected static function migrateDataToDb(self $new, $old): \Generator
|
||||||
{
|
{
|
||||||
if (!empty($old) && !$old instanceof static) {
|
if (!empty($old) && static::getClassName($old) !== static::getClassName($new)) {
|
||||||
if (\str_replace('NullCache\\', '', \get_class($old)) === \str_replace('NullCache\\', '', \get_class($new))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Logger::log('Converting '.\get_class($old).' to '.\get_class($new), Logger::ERROR);
|
Logger::log('Converting '.\get_class($old).' to '.\get_class($new), Logger::ERROR);
|
||||||
|
|
||||||
if (!$old instanceof DbArray) {
|
if (!$old instanceof DbArray) {
|
||||||
@ -217,4 +210,15 @@ abstract class DriverArray implements DbArray
|
|||||||
{
|
{
|
||||||
throw new \RuntimeException('Native isset not support promises. Use isset method');
|
throw new \RuntimeException('Native isset not support promises. Use isset method');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function getClassName($instance): ?string
|
||||||
|
{
|
||||||
|
if ($instance === null) {
|
||||||
|
return null;
|
||||||
|
} elseif (is_array($instance)) {
|
||||||
|
return 'Array';
|
||||||
|
} else {
|
||||||
|
return \str_replace('NullCache\\', '', \get_class($instance));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user