HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode/database/migrations/2025_02_27_142000_hydrate_sync.php
<?php

use App\Helpers\BitrixHelper;
use App\Models\BitrixAcSyncSetting;
use App\Services\ActiveCampaignService;
use App\Services\BitrixService;
use Illuminate\Database\Migrations\Migration;

class HydrateSync extends Migration
{

    public function up()
    {
        $bitrixService = app(BitrixService::class);
        $activeCampaignService = app(ActiveCampaignService::class);
        if (!$bitrixService->check()) {
            throw new Exception('Need to fill BITRIX24_HOST, BITRIX24_USER_ID or BITRIX24_TOKEN in .env');
        }

        if (!$bitrixService->syncStatuses()) {
            throw new Exception($bitrixService->lastError);
        }

        if (!$activeCampaignService->check()) {
            throw new Exception('Need to fill ACTIVE_CAMPAIGN_HOST and ACTIVE_CAMPAIGN_TOKEN in .env');
        }

        if (!$activeCampaignService->syncLists()) {
            throw new Exception($activeCampaignService->lastError);
        }

        $listId = getenv('ACTIVE_CAMPAIGN_BITRIX_NOT_ANSWERED_LIST_ID');
        if (!empty($listId)) {
            $bitrixAcSyncSetting = new BitrixAcSyncSetting();
            $bitrixAcSyncSetting->entity_id = 'STATUS';
            $bitrixAcSyncSetting->bitrix_status = BitrixHelper::STATUS_JUNK;
            $bitrixAcSyncSetting->active_campaign_list_id = $listId;
            $bitrixAcSyncSetting->save();
        }
        $listId = getenv('ACTIVE_CAMPAIGN_BITRIX_TOO_EXPENSIVE_LIST_ID');
        if (!empty($listId)) {
            $bitrixAcSyncSetting = new BitrixAcSyncSetting();
            $bitrixAcSyncSetting->entity_id = 'DEAL_STAGE';
            $bitrixAcSyncSetting->bitrix_status = BitrixHelper::DEAL_STAGE_APOLOGY;
            $bitrixAcSyncSetting->active_campaign_list_id = $listId;
            $bitrixAcSyncSetting->save();
        }
        $listId = getenv('ACTIVE_CAMPAIGN_BITRIX_NOT_ANSWERED_DEALS_LIST_ID');
        if (!empty($listId)) {
            $bitrixAcSyncSetting = new BitrixAcSyncSetting();
            $bitrixAcSyncSetting->entity_id = 'DEAL_STAGE';
            $bitrixAcSyncSetting->bitrix_status = BitrixHelper::DEAL_STAGE_NOT_ANSWERED;
            $bitrixAcSyncSetting->active_campaign_list_id = $listId;
            $bitrixAcSyncSetting->save();
        }
        $listId = getenv('ACTIVE_CAMPAIGN_BITRIX_ONBOARDED_CLIENTS_LIST_ID');
        if (!empty($listId)) {
            $bitrixAcSyncSetting = new BitrixAcSyncSetting();
            $bitrixAcSyncSetting->entity_id = 'DEAL_STAGE';
            $bitrixAcSyncSetting->bitrix_status = BitrixHelper::DEAL_STAGE_WON;
            $bitrixAcSyncSetting->active_campaign_list_id = $listId;
            $bitrixAcSyncSetting->with_unsubscribe = false;
            $bitrixAcSyncSetting->save();
        }
    }

    public function down()
    {
    }

}