Exemple #1
0
 public static function tasks_extended_meta_occurInLogsAs($args)
 {
     $arMessages = array();
     $parsedReturnValue = null;
     $withoutExceptions = false;
     try {
         if (!(CTasksTools::IsAdmin() || CTasksTools::IsPortalB24Admin())) {
             throw new TasksException('Only root can do this', TasksException::TE_ACCESS_DENIED);
         }
         CTaskAssert::assert(is_array($args) && count($args) == 1);
         $userId = array_pop($args);
         CTasksTools::setOccurAsUserId($userId);
         $parsedReturnValue = CTasksTools::getOccurAsUserId();
         $withoutExceptions = true;
     } catch (CTaskAssertException $e) {
         $arMessages[] = array('id' => 'TASKS_ERROR_ASSERT_EXCEPTION', 'text' => 'TASKS_ERROR_ASSERT_EXCEPTION');
     } catch (TasksException $e) {
         $errCode = $e->getCode();
         $errMsg = $e->getMessage();
         if ($e->GetCode() & TasksException::TE_FLAG_SERIALIZED_ERRORS_IN_MESSAGE) {
             $arMessages = unserialize($errMsg);
         } else {
             $arMessages[] = array('id' => 'TASKS_ERROR_EXCEPTION_#' . $errCode, 'text' => 'TASKS_ERROR_EXCEPTION_#' . $errCode . '; ' . $errMsg . '; ' . TasksException::renderErrorCode($e));
         }
     } catch (Exception $e) {
         $errMsg = $e->getMessage();
         if ($errMsg !== '') {
             $arMessages[] = array('text' => $errMsg, 'id' => 'TASKS_ERROR');
         }
     }
     if ($withoutExceptions) {
         return $parsedReturnValue;
     } else {
         self::_emitError($arMessages);
         throw new Exception();
     }
 }
Exemple #2
0
 /**
  * Agent handler for repeating tasks.
  * Create new task based on given template.
  * 
  * @param integer $templateId - id of task template
  * @param integer $flipFlop - this param needs for prevent duplicate names 
  * 		of agent (when adding agent, there is still exists current agent,
  * 		which will be removed later, when our function returns empty string),
  * 		must be 1 or 0.
  * 
  * @return string empty string.
  */
 public static function RepeatTaskByTemplateId($templateId, $flipFlop = 0)
 {
     global $DB;
     $curFlipFlop = (int) $flipFlop;
     if ($curFlipFlop === 0) {
         $newFlipFlop = 1;
     } else {
         $newFlipFlop = 0;
     }
     $templateId = (int) $templateId;
     $arFilter = array('ID' => $templateId);
     $rsTemplate = CTaskTemplates::GetList(array(), $arFilter, false, false, array('*', 'UF_*'));
     $arTemplate = $rsTemplate->Fetch();
     if (!$arTemplate) {
         return '';
     }
     // nothing to do
     if ($arTemplate['REPLICATE'] !== 'Y') {
         return '';
     }
     // nothing to do
     if (intval($arTemplate['CREATED_BY'])) {
         CTasksTools::setOccurAsUserId($arTemplate['CREATED_BY']);
     }
     // not admin in logs, but template creator
     CTaskItem::addByTemplate($templateId, CTasksTools::GetCommanderInChief(), array(), array('TEMPLATE_DATA' => $arTemplate, 'SPAWNED_BY_AGENT' => true));
     $arTemplate['REPLICATE_PARAMS'] = unserialize($arTemplate['REPLICATE_PARAMS']);
     // get next time task will be created, i.e. next Thursday if today is Thursday (and task marked as repeated) and so on
     $nextTime = CTasks::GetNextTime($arTemplate['REPLICATE_PARAMS']);
     if ($nextTime) {
         CTimeZone::Disable();
         $currentAgentCallStr = 'CTasks::RepeatTaskByTemplateId(' . $templateId . ', ' . $curFlipFlop . ');';
         $newAgentCallStr = 'CTasks::RepeatTaskByTemplateId(' . $templateId . ', ' . $newFlipFlop . ');';
         CAgent::RemoveAgent($currentAgentCallStr);
         CAgent::AddAgent($newAgentCallStr, 'tasks', 'N', 86400, $nextTime, 'Y', $nextTime);
         CTimeZone::Enable();
     }
     return '';
 }