#!/usr/bin/env php
<?php

/**
 * Use as follows:
 * $ queue -s <queue_gateway_id> -n <number of messages to be sent>
 *
 * E.g. to send 15 messages of source queue gateway ID 2, do this:
 *
 * $ queue -s 2 -n 15
 */

define('TL_MODE', 'FE');
define('TL_SCRIPT', 'system/modules/notification_center/bin/queue');

if (file_exists(__DIR__ . '/../../../initialize.php')) {
    // Regular way
    require_once(__DIR__ . '/../../../initialize.php');
} elseif (file_exists(__DIR__ . '/../../../../../system/initialize.php')) {
    // Try composer location in Contao 3 (see #77)
    require_once(__DIR__ . '/../../../../../system/initialize.php');
} elseif (file_exists(__DIR__ . '/../../../../system/initialize.php')) {
    // Try composer location in Contao 4 (see #120)
    require_once(__DIR__ . '/../../../../system/initialize.php');
} else {
    throw new \RuntimeException('Contao initialize.php not found');
}

/** @var \NotificationCenter\Queue\QueueManager $queueManager */
$queueManager = $GLOBALS['NOTIFICATION_CENTER']['QUEUE_MANAGER'];
$queueManager->sendFromQueue($argv[2], $argv[4]);
