HEX
Server: Apache
System: Linux server3230.server-vps.com 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64
User: lzgqnjwu (1002)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/lzgqnjwu/sites/bot.sgt.com.ua/console/commands/BroadcastController.php
<?php

namespace console\commands;

use console\services\BroadcastEnqueueService;
use yii\console\Controller;
use yii\console\ExitCode;

/**
 * Розсилка: постановка повідомлень у Redis-чергу (broadcast_id = bot_tasks.id).
 */
class BroadcastController extends Controller
{
    /** @var int ID bot_tasks (те саме, що broadcast_id у ТЗ) */
    public $broadcastId;

    public function options($actionID)
    {
        return array_merge(parent::options($actionID), $actionID === 'send' ? ['broadcastId'] : []);
    }

    public function optionAliases()
    {
        return array_merge(parent::optionAliases(), ['b' => 'broadcastId']);
    }

    /**
     * Поставити в чергу всі очікуючі рядки sender_scedules для задачі.
     * Приклад: php yii broadcast/send --broadcast-id=123
     * Або: php yii broadcast/send 123
     */
    public function actionSend($broadcast_id = null): int
    {
        $id = (int) ($broadcast_id ?? $this->broadcastId);
        if ($id <= 0) {
            $this->stderr("Usage: php yii broadcast/send --broadcast-id=ID  (або позиційний ID)\n");
            return ExitCode::USAGE;
        }
        $n = BroadcastEnqueueService::enqueueForBroadcast($id);
        $this->stdout("Enqueued jobs: {$n}\n");

        return ExitCode::OK;
    }
}