<commit_before><?php

    namespace thebuggenie\modules\mailing\entities\tables;

    use thebuggenie\core\framework,
        thebuggenie\core\entities\tables\ScopedTable,
        b2db\Criteria,
        Swift_Message;

    /**
     * @Table(name="mailing_queue")
     */
    class MailQueueTable extends ScopedTable
    {

        const B2DB_TABLE_VERSION = 1;
        const B2DBNAME = 'mailing_queue';
        const ID = 'mailing_queue.id';
        const MESSAGE = 'mailing_queue.headers';
        const DATE = 'mailing_queue.date';
        const SCOPE = 'mailing_queue.scope';
        const SUBJECT = 'mailing_queue.subject';
        const FROM = 'mailing_queue.from';
        const TO = 'mailing_queue.to';
        const MESSAGE_HTML = 'mailing_queue.part';

        protected function _initialize()
        {
            parent::_setup(self::B2DBNAME, self::ID);
            parent::_addVarchar(self::SUBJECT, 255);
            parent::_addVarchar(self::FROM, 255);
            parent::_addVarchar(self::TO, 255);
            parent::_addText(self::MESSAGE);
            parent::_addText(self::MESSAGE_HTML);
            parent::_addInteger(self::DATE, 10);
        }

        public function addMailToQueue(Swift_Message $mail)
        {
            $crit = $this->getCriteria();
            $crit->addInsert(self::SUBJECT, $mail->getSubject());
            $crit->addInsert(self::FROM, serialize($mail->getFrom()));
            $crit->addInsert(self::TO, serialize($mail->getTo()));
            $crit->addInsert(self::MESSAGE, $mail->getBody());
            $crit->addInsert(self::MESSAGE_HTML, serialize($mail->getChildren()));
            $crit->addInsert(self::DATE, NOW);
            $crit->addInsert(self::SCOPE, framework\Context::getScope()->getID());

            $res = $this->doInsert($crit);

            return $res->getInsertID();
        }

        public function getQueuedMessages($limit = null)
        {
            $crit = $this->getCriteria();
            $crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());
            if ($limit !== null)
            {
                $crit->setLimit($limit);
            }
            $crit->addOrderBy(self::DATE, Criteria::SORT_ASC);

            $messages = array();
            $res = $this->doSelect($crit);

            if ($res)
            {
                while ($row = $res->getNextRow())
                {
                    require_once THEBUGGENIE_VENDOR_PATH . 'swiftmailer' . DS . 'swiftmailer' . DS . 'lib' . DS . 'swift_required.php';
                    $message = Swift_Message::newInstance();
                    $message->setSubject($row->get(self::SUBJECT));
                    $message->setFrom(unserialize($row->get(self::FROM)));
                    $message->setTo(unserialize($row->get(self::TO)));
                    $message->setBody($row->get(self::MESSAGE));
                    $message->setChildren(unserialize($row->get(self::MESSAGE_HTML)));

                    $messages[$row->get(self::ID)] = $message;
                }
            }

            return $messages;
        }

        public function deleteProcessedMessages($ids)
        {
            $crit = $this->getCriteria();
            $crit->addWhere(self::ID, (array) $ids, Criteria::DB_IN);
            $crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());

            $res = $this->doDelete($crit);
        }

    }
<commit_msg>Changed "mailing_queue" table's column "to" to be text as it can contain multiple recipients emails.<commit_after><?php

    namespace thebuggenie\modules\mailing\entities\tables;

    use thebuggenie\core\framework,
        thebuggenie\core\entities\tables\ScopedTable,
        b2db\Criteria,
        Swift_Message;

    /**
     * @Table(name="mailing_queue")
     */
    class MailQueueTable extends ScopedTable
    {

        const B2DB_TABLE_VERSION = 1;
        const B2DBNAME = 'mailing_queue';
        const ID = 'mailing_queue.id';
        const MESSAGE = 'mailing_queue.headers';
        const DATE = 'mailing_queue.date';
        const SCOPE = 'mailing_queue.scope';
        const SUBJECT = 'mailing_queue.subject';
        const FROM = 'mailing_queue.from';
        const TO = 'mailing_queue.to';
        const MESSAGE_HTML = 'mailing_queue.part';

        protected function _initialize()
        {
            parent::_setup(self::B2DBNAME, self::ID);
            parent::_addVarchar(self::SUBJECT, 255);
            parent::_addVarchar(self::FROM, 255);
            parent::_addText(self::TO);
            parent::_addText(self::MESSAGE);
            parent::_addText(self::MESSAGE_HTML);
            parent::_addInteger(self::DATE, 10);
        }

        public function addMailToQueue(Swift_Message $mail)
        {
            $crit = $this->getCriteria();
            $crit->addInsert(self::SUBJECT, $mail->getSubject());
            $crit->addInsert(self::FROM, serialize($mail->getFrom()));
            $crit->addInsert(self::TO, serialize($mail->getTo()));
            $crit->addInsert(self::MESSAGE, $mail->getBody());
            $crit->addInsert(self::MESSAGE_HTML, serialize($mail->getChildren()));
            $crit->addInsert(self::DATE, NOW);
            $crit->addInsert(self::SCOPE, framework\Context::getScope()->getID());

            $res = $this->doInsert($crit);

            return $res->getInsertID();
        }

        public function getQueuedMessages($limit = null)
        {
            $crit = $this->getCriteria();
            $crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());
            if ($limit !== null)
            {
                $crit->setLimit($limit);
            }
            $crit->addOrderBy(self::DATE, Criteria::SORT_ASC);

            $messages = array();
            $res = $this->doSelect($crit);

            if ($res)
            {
                while ($row = $res->getNextRow())
                {
                    require_once THEBUGGENIE_VENDOR_PATH . 'swiftmailer' . DS . 'swiftmailer' . DS . 'lib' . DS . 'swift_required.php';
                    $message = Swift_Message::newInstance();
                    $message->setSubject($row->get(self::SUBJECT));
                    $message->setFrom(unserialize($row->get(self::FROM)));
                    $message->setTo(unserialize($row->get(self::TO)));
                    $message->setBody($row->get(self::MESSAGE));
                    $message->setChildren(unserialize($row->get(self::MESSAGE_HTML)));

                    $messages[$row->get(self::ID)] = $message;
                }
            }

            return $messages;
        }

        public function deleteProcessedMessages($ids)
        {
            $crit = $this->getCriteria();
            $crit->addWhere(self::ID, (array) $ids, Criteria::DB_IN);
            $crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());

            $res = $this->doDelete($crit);
        }

    }

{'fraction_non_alphanumeric': 0.1519953897132978, 'fraction_numerical': 0.004178072323872641, 'mean_word_length': 2.0594975760246803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '4246782', 'n_tokens_mistral': 2030, 'n_tokens_neox': 1952, 'n_words': 289}