/
mikopbx
/
ModuleBeelinePbx
Обзор
Документация
Войти
/
mikopbx
/
ModuleBeelinePbx
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
master
Setup/PbxExtensionSetup.php
78 строк
3 KB
boffart
Инициализация модуля ModuleBeelinePbx
08 июл 2026, 17:11
08 июл 2026, 17:11
1cc4e1a
Код
Авторство
О чём код?
<?php /* * MikoPBX - free phone system for small business * Copyright © 2017-2024 Alexey Portnov and Nikolay Beketov * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. * If not, see <https://www.gnu.org/licenses/>. */ namespace Modules\ModuleBeelinePbx\Setup; use DateTimeImmutable; use MikoPBX\Modules\Setup\PbxExtensionSetupBase; use Modules\ModuleBeelinePbx\Models\ModuleBeelinePbx; /** * Установщик/деинсталлятор модуля. * * @package Modules\ModuleBeelinePbx\Setup */ class PbxExtensionSetup extends PbxExtensionSetupBase { /** * Создаёт структуру БД по аннотациям моделей, регистрирует модуль и пункт сайдбара. * * @return bool результат установки */ public function installDB(): bool { $result = $this->createSettingsTableByModelsAnnotations(); if ($result) { $result = $this->registerNewModule(); } if ($result) { $result = $this->addToSidebar(); } if ($result) { $this->rewindOffsetForRecovery(); } return $result; } /** * При обновлении модуля откатывает offset на 2 месяца назад для восстановления * возможно потерянных прошлой версией звонков/записей. Повторная синхронизация * безопасна: CallHistory обновляется по UNIQUEID, дубликаты не создаются. */ private function rewindOffsetForRecovery(): void { try { $settings = ModuleBeelinePbx::findFirst(); if (!$settings || empty($settings->offset)) { return; } $newOffset = (new DateTimeImmutable('-2 months'))->format('Y-m-d\TH:i:s'); if ($settings->offset > $newOffset) { $settings->offset = $newOffset; $settings->save(); } } catch (\Throwable $e) { // Невозможность сдвинуть offset не должна ломать установку модуля. } } }