protected static function modifyToDb($data) { $result = array(); foreach ($data as $name => $value) { if ($name == 'date' && $value instanceof \DateTime) { $value = DateTime::createFromPhp($value); } if (in_array($name, array('originalData', 'updateData'))) { $value = \WS\Migrations\arrayToJson($value); } $result[$name] = $value; } return $result; }
/** * @return string * @throws \Bitrix\Main\ArgumentException */ public static function checkPeriod($isAgentExec = true) { $isAgentExecInSetting = \COption::GetOptionString("sender", "reiterate_method") !== 'cron'; if ($isAgentExec && !$isAgentExecInSetting || !$isAgentExec && $isAgentExecInSetting) { return ""; } $dateTodayPhp = new \DateTime(); $datetimeToday = Type\DateTime::createFromPhp(clone $dateTodayPhp); $dateToday = clone $dateTodayPhp; $dateToday = Type\Date::createFromPhp($dateToday->setTime(0, 0, 0)); $dateTomorrow = clone $dateTodayPhp; $dateTomorrow = Type\Date::createFromPhp($dateTomorrow->setTime(0, 0, 0))->add('1 DAY'); $arDateFilter = array($dateToday, $dateTomorrow); $chainDb = MailingChainTable::getList(array('select' => array('ID', 'LAST_EXECUTED', 'POSTING_ID', 'DAYS_OF_MONTH', 'DAYS_OF_WEEK', 'TIMES_OF_DAY'), 'filter' => array('=REITERATE' => 'Y', '=MAILING.ACTIVE' => 'Y', 'STATUS' => MailingChainTable::STATUS_WAIT))); while ($arMailingChain = $chainDb->fetch()) { $lastExecuted = $arMailingChain['LAST_EXECUTED']; /* @var \Bitrix\Main\Type\DateTime $lastExecuted*/ if ($lastExecuted && $lastExecuted->getTimestamp() >= $dateToday->getTimestamp()) { continue; } $timeOfExecute = static::getDateExecute($dateTodayPhp, $arMailingChain["DAYS_OF_MONTH"], $arMailingChain["DAYS_OF_WEEK"], $arMailingChain["TIMES_OF_DAY"]); if ($timeOfExecute) { $arUpdateMailChain = array('LAST_EXECUTED' => $datetimeToday); $postingDb = PostingTable::getList(array('select' => array('ID'), 'filter' => array('=MAILING_CHAIN_ID' => $arMailingChain['ID'], '><DATE_CREATE' => $arDateFilter))); $arPosting = $postingDb->fetch(); if (!$arPosting) { $postingId = MailingChainTable::initPosting($arMailingChain['ID']); } else { $postingId = $arPosting['ID']; $arUpdateMailChain['POSTING_ID'] = $postingId; PostingTable::initGroupRecipients($postingId); } if ($postingId) { $arUpdateMailChain['STATUS'] = MailingChainTable::STATUS_SEND; $arUpdateMailChain['AUTO_SEND_TIME'] = Type\DateTime::createFromPhp($timeOfExecute); } MailingChainTable::update(array('ID' => $arMailingChain['ID']), $arUpdateMailChain); } } return static::getAgentNamePeriod(); }
protected static function modifyToDb($data) { $data['date'] && $data['date'] instanceof \DateTime && ($data['date'] = DateTime::createFromPhp($data['date'])); return $data; }