Compare commits

..

No commits in common. "2.0.1" and "stable" have entirely different histories.

3 changed files with 45 additions and 48 deletions

View File

@ -25,7 +25,7 @@ use ArangoDBClient\Document as _document,
class account class account
{ {
/** /**
* Инициализация * Инициализировать
* *
* @param _connection $session Сессия соединения с базой данных * @param _connection $session Сессия соединения с базой данных
* @param int $id Идентификатор ВКонтакте * @param int $id Идентификатор ВКонтакте
@ -43,7 +43,7 @@ class account
collection::init($session, longpoll::COLLECTION_ACCOUNTS); collection::init($session, longpoll::COLLECTION_ACCOUNTS);
} }
// Поиск аккаунта // Поиск
if ($account = static::search($session, $id)); if ($account = static::search($session, $id));
else if ($account = document::write($session, longpoll::COLLECTION_ACCOUNTS, ['id' => $id]) and $journal) else if ($account = document::write($session, longpoll::COLLECTION_ACCOUNTS, ['id' => $id]) and $journal)
journal::init($session, $account)->write('create', [ journal::init($session, $account)->write('create', [
@ -62,13 +62,12 @@ class account
] ]
]); ]);
// Поиск
// Поиск аккаунта
return static::search($session, $id); return static::search($session, $id);
} }
/** /**
* Найти аккаунт * Найти
* *
* @param _connection $session Сессия соединения с базой данных * @param _connection $session Сессия соединения с базой данных
* @param int $id Идентификатор ВКонтакте * @param int $id Идентификатор ВКонтакте

View File

@ -36,57 +36,55 @@ class chat
*/ */
public static function init(_connection $session, int $id, bool $journal = true, bool $create = true): ?_document public static function init(_connection $session, int $id, bool $journal = true, bool $create = true): ?_document
{ {
// Инициализация коллекции
$collection = longpoll::COLLECTION_CHATS;
if ($create) { if ($create) {
// Запрошено создание коллекций в случае их отсутствия // Запрошено создание коллекций в случае их отсутствия
// Создание коллекции // Создание коллекции
collection::init($session, $collection); collection::init($session, longpoll::COLLECTION_CHATS);
} }
if ($account = collection::search($session, <<<AQL // Поиск
FOR x IN $collection if ($chat = static::search($session, $id));
FILTER x.id == "$id" else if ($chat = document::write($session, longpoll::COLLECTION_CHATS, ['id' => $id]) and $journal)
LIMIT 1 journal::init($session, $chat)->write('create', [
RETURN x
AQL)) {
// Найден аккаунт
return $account;
}
if ($account = document::write($session, $collection, ['id' => $id])) {
// Аккаунт записан
// Журналирование
if ($journal && journal::init($session, $account)->write('create', [
'changes' => [ 'changes' => [
'new' => collection::search($session, <<<AQL 'new' => collection::search($session, sprintf(
FOR x IN $collection <<<'AQL'
FILTER x._id == "$account" FOR x IN %s
FILTER x._id == "%s"
LIMIT 1 LIMIT 1
RETURN x RETURN x
AQL), AQL,
longpoll::COLLECTION_CHATS,
$chat
)),
'old' => null 'old' => null
] ]
])) { ]);
// Записаны данные в журнал
}
if ($account = collection::search($session, <<<AQL // Поиск
FOR x IN $collection return static::search($session, $id);
FILTER x.id == "$id" }
LIMIT 1
RETURN x
AQL)) {
// Найден аккаунт
return $account; /**
} * Найти в базе данных
} *
* @param _connection $session Сессия соединения с базой данных
return null; * @param int $id Идентификатор ВКонтакте
*
* @return ?_document Инстанция документа
*/
public static function search(_connection $session, int $id): ?_document
{
return collection::search($session, sprintf(
<<<'AQL'
FOR x IN %s
FILTER x.id == %u
LIMIT 1
RETURN x
AQL,
longpoll::COLLECTION_CHATS,
$id
));
} }
} }

View File

@ -33,7 +33,7 @@ class group
collection::init($session, longpoll::COLLECTION_GROUPS); collection::init($session, longpoll::COLLECTION_GROUPS);
} }
// Поиск группы // Поиск
if ($group = static::search($session, $id)); if ($group = static::search($session, $id));
else if ($group = document::write($session, longpoll::COLLECTION_GROUPS, ['id' => $id]) and $journal) else if ($group = document::write($session, longpoll::COLLECTION_GROUPS, ['id' => $id]) and $journal)
journal::init($session, $group)->write('create', [ journal::init($session, $group)->write('create', [
@ -53,12 +53,12 @@ class group
]); ]);
// Поиск группы // Поиск
return static::search($session, $id); return static::search($session, $id);
} }
/** /**
* Найти группу * Найти в базе данных
* *
* @param _connection $session Сессия соединения с базой данных * @param _connection $session Сессия соединения с базой данных
* @param int $id Идентификатор ВКонтакте * @param int $id Идентификатор ВКонтакте
@ -70,7 +70,7 @@ class group
return collection::search($session, sprintf( return collection::search($session, sprintf(
<<<'AQL' <<<'AQL'
FOR x IN %s FOR x IN %s
FILTER x.id == %u FILTER x.id == %d
LIMIT 1 LIMIT 1
RETURN x RETURN x
AQL, AQL,