Ejemplo n.º 1
0
 function Execute()
 {
     global $DB;
     $rubrics = CRubric::GetList(array(), array("ACTIVE" => "Y", "AUTO" => "Y"));
     $current_time = time();
     $time_of_exec = false;
     $result = "";
     while (($arRubric = $rubrics->Fetch()) && $time_of_exec === false) {
         if ($arRubric["LAST_EXECUTED"] == '') {
             continue;
         }
         $last_executed = MakeTimeStamp(ConvertDateTime($arRubric["LAST_EXECUTED"], "DD.MM.YYYY HH:MI:SS"), "DD.MM.YYYY HH:MI:SS");
         if ($last_executed <= 0) {
             continue;
         }
         //parse schedule
         $arDoM = CPostingTemplate::ParseDaysOfMonth($arRubric["DAYS_OF_MONTH"]);
         $arDoW = CPostingTemplate::ParseDaysOfWeek($arRubric["DAYS_OF_WEEK"]);
         $arToD = CPostingTemplate::ParseTimesOfDay($arRubric["TIMES_OF_DAY"]);
         if ($arToD) {
             sort($arToD, SORT_NUMERIC);
         }
         //sdate = truncate(last_execute)
         $arSDate = localtime($last_executed);
         $sdate = mktime(0, 0, 0, $arSDate[4] + 1, $arSDate[3], $arSDate[5] + 1900);
         while ($sdate < $current_time && $time_of_exec === false) {
             $arSDate = localtime($sdate);
             if ($arSDate[6] == 0) {
                 $arSDate[6] = 7;
             }
             //determine if date is good for execution
             if ($arDoM) {
                 $flag = array_search($arSDate[3], $arDoM);
                 if ($arDoW) {
                     $flag = array_search($arSDate[6], $arDoW);
                 }
             } elseif ($arDoW) {
                 $flag = array_search($arSDate[6], $arDoW);
             } else {
                 $flag = false;
             }
             if ($flag !== false && $arToD) {
                 foreach ($arToD as $intToD) {
                     if ($sdate + $intToD > $last_executed && $sdate + $intToD <= $current_time) {
                         $time_of_exec = $sdate + $intToD;
                         break;
                     }
                 }
             }
             $sdate = mktime(0, 0, 0, date("m", $sdate), date("d", $sdate) + 1, date("Y", $sdate));
             //next day
         }
         if ($time_of_exec !== false) {
             $arRubric["START_TIME"] = ConvertTimeStamp($last_executed, "FULL");
             $arRubric["END_TIME"] = ConvertTimeStamp($time_of_exec, "FULL");
             $arRubric["SITE_ID"] = $arRubric["LID"];
             CPostingTemplate::AddPosting($arRubric);
         }
         $result = "CPostingTemplate::Execute();";
     }
     return $result;
 }