<commit_before><?php

namespace Rhubarb\Scaffolds\Communications\Custard;

use Rhubarb\Custard\Command\CustardCommand;
use Rhubarb\Scaffolds\Communications\Models\Communication;
use Rhubarb\Scaffolds\Communications\Processors\CommunicationProcessor;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SendCommunicationsCommand extends CustardCommand
{
    protected function configure()
    {
        $this->setName('communication:send-unsent')
            ->setDescription('Sends unsent Communications to the their relevant recipients')
            ->addArgument('communicationID', InputArgument::OPTIONAL, 'The id of the communication you wish to send');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        parent::execute($input, $output);

        $communicationID = $input->getArgument('communicationID');

        if (isset($communicationID)) {
            $communication = new Communication($communicationID);
            CommunicationProcessor::sendCommunication($communication);
        } else {
            $unsentCommunicationsArray = Communication::findUnsentCommunications();
            foreach ($unsentCommunicationsArray as $communication) {
                CommunicationProcessor::sendCommunication($communication);
            }
        }
    }
}<commit_msg>Added option to send a finite number of back logged items<commit_after><?php

namespace Rhubarb\Scaffolds\Communications\Custard;

use Rhubarb\Custard\Command\CustardCommand;
use Rhubarb\Scaffolds\Communications\Models\Communication;
use Rhubarb\Scaffolds\Communications\Processors\CommunicationProcessor;
use Rhubarb\Stem\Custard\RequiresRepositoryCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class SendCommunicationsCommand extends RequiresRepositoryCommand
{
    protected function configure()
    {
        parent::configure();

        $this->setName('communication:send-unsent')
            ->setDescription('Sends unsent Communications to the their relevant recipients')
            ->addOption("limit", "l", InputOption::VALUE_OPTIONAL, "Limits sending to n number of entries", 0)
            ->addArgument('communicationID', InputArgument::OPTIONAL, 'The id of the communication you wish to send');
    }

    protected function executeWithConnection(InputInterface $input, OutputInterface $output)
    {
        parent::executeWithConnection($input, $output);

        $communicationID = $input->getArgument('communicationID');
        $limit = $input->getOption("limit");

        if (isset($communicationID)) {
            $communication = new Communication($communicationID);
            CommunicationProcessor::sendCommunication($communication);
        } else {
            $unsentCommunicationsArray = Communication::findUnsentCommunications();

            if ($limit){
                $unsentCommunicationsArray->setRange(0, $limit);
            }

            foreach ($unsentCommunicationsArray as $communication) {
                CommunicationProcessor::sendCommunication($communication);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09761194029850746, 'fraction_numerical': 0.0005970149253731343, 'mean_word_length': 3.8285302593659942, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6189895', 'n_tokens_mistral': 877, 'n_tokens_neox': 818, 'n_words': 164}