Ejemplo n.º 1
0
 /**
  * @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();
 }
Ejemplo n.º 2
0
 /**
  * Returns site traffic capacity
  *
  * @param string $id Site ID.
  * @return array
  */
 public static function getSiteCapacity($id)
 {
     $cache = new \CPHPCache();
     if ($cache->initCache(time() - strtotime('today'), 'abtest_site_capacity', '/abtest')) {
         $capacity = $cache->getVars();
     } else {
         if (Loader::includeModule('conversion')) {
             if ($conversionRates = Conversion\RateManager::getTypes(array('ACTIVE' => true))) {
                 $baseRate = array_slice($conversionRates, 0, 1, true);
                 $reportContext = new Conversion\ReportContext();
                 $from = new \DateTime('first day of last month');
                 $to = new \DateTime('today');
                 $capacity = array();
                 $res = \Bitrix\Main\SiteTable::getList();
                 while ($site = $res->fetch()) {
                     $lid = $site['LID'];
                     $reportContext->setAttribute('conversion_site', $lid);
                     $rateData = reset($reportContext->getRatesDeprecated($baseRate, array('>=DAY' => Type\Date::createFromPhp($from), '<=DAY' => Type\Date::createFromPhp($to)), null));
                     $reportContext->unsetAttribute('conversion_site', $lid);
                     $rate = $rateData['RATE'];
                     $hits = $rateData['DENOMINATOR'];
                     $daily = floor($hits / (date_diff($from, $to)->format('%a') + 1));
                     $min = $rate > 0 && $rate < 1 ? ceil(16 * (1 / $rate - 1) / pow(MIN_EFFECT, 2)) : 0;
                     $est = $daily ? $min / ($daily / 2) : 0;
                     $capacity[$lid] = array('daily' => $daily, 'min' => $min, 'est' => $est);
                 }
                 $cache->startDataCache(strtotime('tomorrow') - time());
                 $cache->endDataCache($capacity);
             }
         }
     }
     $result = array();
     foreach ((array) $id as $lid) {
         $result[$lid] = isset($capacity[$lid]) ? $capacity[$lid] : array('min' => 0, 'est' => 0);
     }
     return is_array($id) ? $result : reset($result);
 }
Ejemplo n.º 3
0
use Bitrix\Conversion\AttributeManager;
use Bitrix\Conversion\AttributeGroupManager;
use Bitrix\Conversion\ReportContext;
use Bitrix\Main\Loader;
use Bitrix\Main\SiteTable;
use Bitrix\Main\Type\Date;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
Loader::IncludeModule('conversion');
if ($APPLICATION->GetGroupRight('conversion') < 'W') {
    $APPLICATION->AuthForm(Loc::getMessage('ACCESS_DENIED'));
}
$userOptions = CUserOptions::GetOption('conversion', 'filter', array());
// PERIOD
$from = ($d = $_GET['from'] ?: $userOptions['from']) && Date::isCorrect($d) ? new Date($d) : Date::createFromPhp(new DateTime('first day of last month'));
$to = ($d = $_GET['to'] ?: $userOptions['to']) && Date::isCorrect($d) ? new Date($d) : Date::createFromPhp(new DateTime('last day of this month'));
// RATES
if (!($rateTypes = RateManager::getTypes())) {
    die('No rates available!');
}
$rateName = $_GET['rate'] ?: $userOptions['rate'];
if (!($rateType = $rateTypes[$rateName])) {
    list($rateName, $rateType) = each($rateTypes);
}
// SITES
$sites = array();
$result = SiteTable::getList(array('select' => array('LID', 'NAME'), 'order' => array('DEF' => 'DESC', 'SORT' => 'ASC')));
while ($row = $result->fetch()) {
    $sites[$row['LID']] = $row['NAME'];
}
if (!$sites) {
Ejemplo n.º 4
0
 /**
  * @return array
  */
 public function getPeriod()
 {
     if ($this->isEmpty()) {
         throw new Main\InvalidOperationException('Could not prepare period. Filter is empty.');
     }
     $result = array();
     if ($this->periodTypeID === FilterPeriodType::YEAR) {
         $year = $this->year;
         $result['START'] = new Date("{$year}-1-1", 'Y-m-d');
         $result['END'] = new Date("{$year}-12-31", 'Y-m-d');
     } elseif ($this->periodTypeID === FilterPeriodType::QUARTER) {
         $year = $this->year;
         $quarter = $this->quarter;
         $lastMonth = 3 * $quarter;
         $firstMonth = $lastMonth - 2;
         $d = new \DateTime("{$year}-{$lastMonth}-01");
         $lastDay = $d->format('t');
         $result['START'] = new Date("{$year}-{$firstMonth}-01", 'Y-m-d');
         $result['END'] = new Date("{$year}-{$lastMonth}-{$lastDay}", 'Y-m-d');
     } elseif ($this->periodTypeID === FilterPeriodType::MONTH) {
         $year = $this->year;
         $month = $this->month;
         $d = new \DateTime("{$year}-{$month}-01");
         $lastDay = $d->format('t');
         $result['START'] = new Date("{$year}-{$month}-01", 'Y-m-d');
         $result['END'] = new Date("{$year}-{$month}-{$lastDay}", 'Y-m-d');
     } elseif ($this->periodTypeID === FilterPeriodType::CURRENT_MONTH) {
         $d = new \DateTime();
         $year = $d->format('Y');
         $month = $d->format('n');
         $lastDay = $d->format('t');
         $leftBoundary = new \DateTime();
         $leftBoundary->setDate($year, $month, 1);
         $leftBoundary->setTime(0, 0, 0);
         $rightBoundary = new \DateTime();
         $rightBoundary->setDate($year, $month, $lastDay);
         $rightBoundary->setTime(0, 0, 0);
         $result['START'] = Date::createFromPhp($leftBoundary);
         $result['END'] = Date::createFromPhp($rightBoundary);
     } elseif ($this->periodTypeID === FilterPeriodType::CURRENT_QUARTER) {
         $d = new \DateTime();
         $year = $d->format('Y');
         $month = $d->format('n');
         $quarter = $month <= 3 ? 1 : ($month <= 6 ? 2 : ($month <= 9 ? 3 : 4));
         $lastMonth = 3 * $quarter;
         $firstMonth = $lastMonth - 2;
         $d = new \DateTime("{$year}-{$lastMonth}-01");
         $lastDay = $d->format('t');
         $result['START'] = new Date("{$year}-{$firstMonth}-01", 'Y-m-d');
         $result['END'] = new Date("{$year}-{$lastMonth}-{$lastDay}", 'Y-m-d');
     } elseif ($this->periodTypeID === FilterPeriodType::LAST_DAYS_90 || $this->periodTypeID === FilterPeriodType::LAST_DAYS_60 || $this->periodTypeID === FilterPeriodType::LAST_DAYS_30 || $this->periodTypeID === FilterPeriodType::LAST_DAYS_7) {
         $rightBoundary = new \DateTime();
         $rightBoundary->setTime(0, 0, 0);
         $leftBoundary = new \DateTime();
         $leftBoundary->setTime(0, 0, 0);
         $intervalLength = 7;
         if ($this->periodTypeID === FilterPeriodType::LAST_DAYS_90) {
             $intervalLength = 90;
         } elseif ($this->periodTypeID === FilterPeriodType::LAST_DAYS_60) {
             $intervalLength = 60;
         } elseif ($this->periodTypeID === FilterPeriodType::LAST_DAYS_30) {
             $intervalLength = 30;
         }
         $interval = new \DateInterval("P{$intervalLength}D");
         $interval->invert = 1;
         $leftBoundary->add($interval);
         $result['START'] = Date::createFromPhp($leftBoundary);
         $result['END'] = Date::createFromPhp($rightBoundary);
     }
     return $result;
 }