- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/tools/correction.php
- Класс: BitrixImOpenLinesToolsCorrection
- Вызов: Correction::restoreChatSessionId
static function restoreChatSessionId(bool $correction = true, int $limit = 0): array
{
$status = Session::STATUS_CLOSE;
$sql = "
SELECT
s.ID,
s.CONFIG_ID,
s.USER_ID,
s.SOURCE,
s.CHAT_ID,
s.USER_CODE,
c.ENTITY_DATA_1 as SESS_DATA
FROM
b_imopenlines_session s
INNER JOIN b_im_chat c
ON s.CHAT_ID = c.ID
WHERE
s.CLOSED != 'Y'
AND s.SPAM != 'Y'
AND s.STATUS < {$status}
AND SUBSTRING_INDEX(SUBSTRING_INDEX(c.ENTITY_DATA_1, '|', 6), '|', -1) = '0'
";
if ($limit > 0)
{
$sql .= " LIMIT {$limit}";
}
$result = [];
$res = Application::getConnection()->query($sql);
while ($row = $res->fetch())
{
if ($correction)
{
$fieldData = explode("|", $row['SESS_DATA']);
if ((int)$fieldData[5] == 0)
{
$session = new BitrixImOpenLinesSession($row);
$resultSessionStart = $session->load(array_merge($row, ['SKIP_CREATE' => 'Y']));
if ($resultSessionStart)
{
$updateRes = $session->getChat()->updateFieldData([
BitrixImOpenLinesChat::FIELD_SESSION => [
'ID' => $session->getData('ID')
]
]);
if ($updateRes->isSuccess())
{
$result[] = (int)$row['ID'];
}
}
}
}
else
{
$result[] = (int)$row['ID'];
}
}
return $result;
}