Added flag to avoid getting updates on deserialization
This commit is contained in:
parent
13277cb015
commit
a6e456b253
9
CHANGELOG.md
Normal file
9
CHANGELOG.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
|
||||
Added `$no_updates` parameter to the deserialize method of `\danog\MadelineProto\Serialization`.
|
||||
|
||||
|
||||
## 1.3.1 Release
|
||||
|
||||
Just check the release changelog :D
|
@ -436,7 +436,7 @@ Note that when you login as a bot, MadelineProto also logins using the [PWRTeleg
|
||||
|
||||
### Storing sessions
|
||||
|
||||
An istance of MadelineProto can be safely serialized or unserialized. To serialize MadelineProto to a file, usage of the `\danog\MadelineProto\Serialization` class is recommended:
|
||||
An istance of MadelineProto can be safely serialized or unserialized. To serialize MadelineProto to a file, you must use the `\danog\MadelineProto\Serialization` class:
|
||||
|
||||
```
|
||||
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
||||
@ -444,7 +444,8 @@ $MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeli
|
||||
\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto);
|
||||
```
|
||||
|
||||
That class serializes only if the `$MadelineProto->API->should_serialize` boolean is set to true.
|
||||
THe deserialize method accepts a second optional parameter, `$no_updates`, that can be set to true to avoid fetching updates on deserialization, and postpone parsing of updates received through the socket until the next deserialization.
|
||||
That class serializes only if the `$MadelineProto->API->should_serialize` boolean is set to true, using [MagicalSerializer](https://github.com/danog/MagicalSerializer).
|
||||
The same operation should be done when serializing to another destination manually, to avoid conflicts with other PHP scripts that are trying to serialize another instance of the class.
|
||||
|
||||
### Exceptions
|
||||
|
@ -440,7 +440,7 @@ Note that when you login as a bot, MadelineProto also logins using the [PWRTeleg
|
||||
|
||||
### Storing sessions
|
||||
|
||||
An istance of MadelineProto can be safely serialized or unserialized. To serialize MadelineProto to a file, usage of the `\danog\MadelineProto\Serialization` class is recommended:
|
||||
An istance of MadelineProto can be safely serialized or unserialized. To serialize MadelineProto to a file, you must use the `\danog\MadelineProto\Serialization` class:
|
||||
|
||||
```
|
||||
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
||||
@ -448,7 +448,8 @@ $MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeli
|
||||
\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto);
|
||||
```
|
||||
|
||||
That class serializes only if the `$MadelineProto->API->should_serialize` boolean is set to true.
|
||||
THe deserialize method accepts a second optional parameter, `$no_updates`, that can be set to true to avoid fetching updates on deserialization, and postpone parsing of updates received through the socket until the next deserialization.
|
||||
That class serializes only if the `$MadelineProto->API->should_serialize` boolean is set to true, using [MagicalSerializer](https://github.com/danog/MagicalSerializer).
|
||||
The same operation should be done when serializing to another destination manually, to avoid conflicts with other PHP scripts that are trying to serialize another instance of the class.
|
||||
|
||||
### Exceptions
|
||||
|
@ -261,7 +261,7 @@ class MTProto extends \Volatile
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
return ['encrypted_layer', 'settings', 'config', 'authorization', 'authorized', 'rsa_keys', 'last_recv', 'dh_config', 'chats', 'last_stored', 'qres', 'pending_updates', 'updates_state', 'got_state', 'channels_state', 'updates', 'updates_key', 'getting_state', 'full_chats', 'msg_ids', 'dialog_params', 'datacenter', 'v', 'constructors', 'td_constructors', 'methods', 'td_methods', 'td_descriptions', 'twoe1984', 'twoe2047', 'twoe2048', 'zero', 'one', 'two', 'three', 'four', 'temp_requested_secret_chats', 'secret_chats', 'calls'];
|
||||
return ['encrypted_layer', 'settings', 'config', 'authorization', 'authorized', 'rsa_keys', 'last_recv', 'dh_config', 'chats', 'last_stored', 'qres', 'pending_updates', 'updates_state', 'got_state', 'channels_state', 'updates', 'updates_key', 'full_chats', 'msg_ids', 'dialog_params', 'datacenter', 'v', 'constructors', 'td_constructors', 'methods', 'td_methods', 'td_descriptions', 'twoe1984', 'twoe2047', 'twoe2048', 'zero', 'one', 'two', 'three', 'four', 'temp_requested_secret_chats', 'secret_chats', 'calls'];
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
@ -298,6 +298,12 @@ class MTProto extends \Volatile
|
||||
$this->authorized = self::LOGGED_IN;
|
||||
}
|
||||
$this->getting_state = false;
|
||||
foreach (debug_backtrace(0) as $trace) {
|
||||
if (isset($trace['function']) && isset($trace['class']) && $trace['function'] === 'deserialize' && $trace['class'] === 'danog\MadelineProto\Serialization') {
|
||||
$this->getting_state = isset($trace['args'][1]) && $trace['args'][1];
|
||||
}
|
||||
}
|
||||
|
||||
$this->reset_session();
|
||||
if (!isset($this->v) || $this->v !== $this->getV()) {
|
||||
\danog\MadelineProto\Logger::log(['Serialization is out of date, reconstructing object!'], Logger::WARNING);
|
||||
@ -320,7 +326,7 @@ class MTProto extends \Volatile
|
||||
if ($this->authorized === self::LOGGED_IN && !$this->authorization['user']['bot']) {
|
||||
$this->get_dialogs();
|
||||
}
|
||||
if ($this->authorized === self::LOGGED_IN && $this->settings['updates']['handle_updates']) {
|
||||
if ($this->authorized === self::LOGGED_IN && $this->settings['updates']['handle_updates'] && !$this->getting_state) {
|
||||
\danog\MadelineProto\Logger::log(['Getting updates after deserialization...'], Logger::NOTICE);
|
||||
$this->get_updates_difference();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class Serialization
|
||||
*
|
||||
* @return API
|
||||
*/
|
||||
public static function deserialize($filename)
|
||||
public static function deserialize($filename, $no_updates = false)
|
||||
{
|
||||
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user