コード例 #1
0
ファイル: task.php プロジェクト: mrdeadmouse/u136006
 /**
  * This method is deprecated. Use CTaskItem::delete() instead.
  * @deprecated
  */
 public static function Delete($ID, $arParams = array())
 {
     global $DB, $CACHE_MANAGER, $USER;
     if (isset($USER) && is_object($USER)) {
         $actorUserId = (int) $USER->getId();
     } else {
         $actorUserId = 1;
     }
     if (isset($arParams['META::EVENT_GUID'])) {
         $eventGUID = $arParams['META::EVENT_GUID'];
         unset($arParams['META::EVENT_GUID']);
     } else {
         $eventGUID = sha1(uniqid('AUTOGUID', true));
     }
     $paramSkipExchangeSync = false;
     if (is_array($arParams)) {
         if (isset($arParams['skipExchangeSync']) && ($arParams['skipExchangeSync'] === 'Y' || $arParams['skipExchangeSync'] === true)) {
             $paramSkipExchangeSync = true;
         }
     }
     $ID = intval($ID);
     if ($ID < 1) {
         return false;
     }
     $rsTask = CTasks::GetByID($ID, false);
     if ($arTask = $rsTask->Fetch()) {
         foreach (GetModuleEvents('tasks', 'OnBeforeTaskDelete', true) as $arEvent) {
             if (ExecuteModuleEventEx($arEvent, array($ID, $arTask)) === false) {
                 return false;
             }
         }
         CTaskCountersProcessor::onBeforeTaskDelete($ID, $arTask);
         CTaskMembers::DeleteByTaskID($ID);
         CTaskFiles::DeleteByTaskID($ID);
         CTaskDependence::DeleteByTaskID($ID);
         CTaskDependence::DeleteByDependsOnID($ID);
         CTaskTags::DeleteByTaskID($ID);
         $strSql = "DELETE FROM b_tasks_viewed WHERE TASK_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strSql = "DELETE FROM b_tasks_reminder WHERE TASK_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         // clear cache
         if ($arTask["GROUP_ID"]) {
             $CACHE_MANAGER->ClearByTag("tasks_group_" . $arTask["GROUP_ID"]);
         }
         $arParticipants = array_unique(array_merge(array($arTask["CREATED_BY"], $arTask["RESPONSIBLE_ID"]), $arTask["ACCOMPLICES"], $arTask["AUDITORS"]));
         foreach ($arParticipants as $userId) {
             $CACHE_MANAGER->ClearByTag("tasks_user_" . $userId);
         }
         $strSql = "UPDATE b_tasks_template SET TASK_ID = NULL WHERE TASK_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strSql = "UPDATE b_tasks_template SET PARENT_ID = " . ($arTask["PARENT_ID"] ? $arTask["PARENT_ID"] : "NULL") . " WHERE PARENT_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strSql = "UPDATE b_tasks SET PARENT_ID = " . ($arTask["PARENT_ID"] ? $arTask["PARENT_ID"] : "NULL") . " WHERE PARENT_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strUpdate = $DB->PrepareUpdate("b_tasks", array('ZOMBIE' => 'Y', 'CHANGED_BY' => $actorUserId, 'CHANGED_DATE' => date($DB->DateFormatToPHP(CSite::GetDateFormat('FULL')), time() + CTasksTools::getTimeZoneOffset())), "tasks");
         $strSql = "UPDATE b_tasks SET " . $strUpdate . " WHERE ID = " . (int) $ID;
         if ($DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__)) {
             CTaskNotifications::SendDeleteMessage($arTask);
             if ($arTask["FORUM_TOPIC_ID"] && CModule::IncludeModule("forum")) {
                 CForumTopic::Delete($arTask["FORUM_TOPIC_ID"]);
             }
             if (!$paramSkipExchangeSync) {
                 CTaskSync::DeleteItem($arTask);
             }
             // MS Exchange
             // Emit pull event
             try {
                 $arPullRecipients = array();
                 foreach ($arParticipants as $userId) {
                     $arPullRecipients[] = (int) $userId;
                 }
                 $taskGroupId = 0;
                 // no group
                 if (isset($arTask['GROUP_ID']) && $arTask['GROUP_ID'] > 0) {
                     $taskGroupId = (int) $arTask['GROUP_ID'];
                 }
                 $arPullData = array('TASK_ID' => (int) $ID, 'BEFORE' => array('GROUP_ID' => $taskGroupId), 'TS' => time(), 'event_GUID' => $eventGUID);
                 self::EmitPullWithTagPrefix($arPullRecipients, 'TASKS_GENERAL_', 'task_remove', $arPullData);
                 self::EmitPullWithTag($arPullRecipients, 'TASKS_TASK_' . (int) $ID, 'task_remove', $arPullData);
             } catch (Exception $e) {
             }
             foreach (GetModuleEvents('tasks', 'OnTaskDelete', true) as $arEvent) {
                 ExecuteModuleEventEx($arEvent, array($ID));
             }
             if (CModule::IncludeModule("search")) {
                 CSearch::DeleteIndex("tasks", $ID);
             }
         }
         return true;
     }
     return false;
 }