Пример #1
0
 public static function IsHistoryUpdate($documentID)
 {
     static $arHistoryFields = array("ID", "DOCUMENT_ID", "MODIFIED", "DOCUMENT");
     $historyService = self::GetHistoryService();
     $result = false;
     if (self::IsGlueEnabled()) {
         $arFilter = array("DOCUMENT_ID" => $documentID, "USER_ID" => CUser::GetID());
         $dbDoc = $historyService->GetHistoryList(array("ID" => "DESC"), $arFilter, false, false, $arHistoryFields);
         CTimeZone::Disable();
         if ($dbDoc && ($arDoc = $dbDoc->Fetch())) {
             CTimeZone::Enable();
             if (CWebdavDocumentHistory::GetHistoryState($documentID, $arDoc['ID'], $arDoc) == 'Y') {
                 $result = $arDoc;
             }
         } else {
             CTimeZone::Enable();
         }
     }
     return $result;
 }
Пример #2
0
 /**
  * Метод возвращает массив произвольной структуры, содержащий всю информацию о документе. По этому массиву документ восстановливается методом RecoverDocumentFromHistory.
  *
  * @param string $documentId - код документа.
  * @return array - массив документа.
  */
 public function GetDocumentForHistory($documentId, $historyIndex, $update = false)
 {
     $documentId = intval($documentId);
     if ($documentId <= 0) {
         throw new CBPArgumentNullException("documentId");
     }
     $diskId = self::processGetDiskIdByDocId($documentId);
     if ($diskId !== null) {
         return self::proxyToDisk(__FUNCTION__, array($diskId, $historyIndex, $update));
     }
     $arResult = null;
     $dbDocumentList = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"));
     if ($objDocument = $dbDocumentList->GetNextElement()) {
         $arDocumentFields = $objDocument->GetFields();
         $arDocumentProperties = $objDocument->GetProperties();
         $arResult["NAME"] = $arDocumentFields["~NAME"];
         $arResult["FIELDS"] = array();
         foreach ($arDocumentFields as $fieldKey => $fieldValue) {
             if ($fieldKey == "~PREVIEW_PICTURE" || $fieldKey == "~DETAIL_PICTURE") {
                 $arResult["FIELDS"][substr($fieldKey, 1)] = CBPDocument::PrepareFileForHistory(array("webdav", "CIBlockDocumentWebdavSocnet", $documentId), $fieldValue, $historyIndex);
             } elseif (substr($fieldKey, 0, 1) == "~") {
                 $arResult["FIELDS"][substr($fieldKey, 1)] = $fieldValue;
             }
         }
         $arResult["PROPERTIES"] = array();
         foreach ($arDocumentProperties as $propertyKey => $propertyValue) {
             if (strlen($propertyValue["USER_TYPE"]) > 0) {
                 $arResult["PROPERTIES"][$propertyKey] = array("VALUE" => $propertyValue["VALUE"], "DESCRIPTION" => $propertyValue["DESCRIPTION"]);
             } elseif ($propertyValue["PROPERTY_TYPE"] == "L") {
                 $arResult["PROPERTIES"][$propertyKey] = array("VALUE" => $propertyValue["VALUE_ENUM_ID"], "DESCRIPTION" => $propertyValue["DESCRIPTION"]);
             } elseif ($propertyValue["PROPERTY_TYPE"] == "F" && $propertyKey == 'FILE') {
                 $arDocID = $documentId;
                 if (!is_array($documentId)) {
                     $arDocID = array("webdav", "CIBlockDocumentWebdavSocnet", $documentId);
                 }
                 $arResult['PROPERTIES'][$propertyKey] = CWebdavDocumentHistory::GetFileForHistory($arDocID, $propertyValue, $historyIndex);
                 $arResult['OLD_FILE_ID'] = $propertyValue['VALUE'];
                 //for historical comment.
                 if ($update) {
                     $historyGlueState = CWebdavDocumentHistory::GetHistoryState($arDocID, null, null, array('CHECK_TIME' => 'Y'));
                 } else {
                     $historyGlueState = CWebdavDocumentHistory::GetHistoryState($arDocID, null, null, array('NEW' => 'Y', 'CHECK_TIME' => 'Y'));
                 }
                 $arResult['PROPERTIES'][$propertyKey]['HISTORYGLUE'] = $historyGlueState;
             } elseif ($propertyValue["PROPERTY_TYPE"] == "F") {
                 $arResult["PROPERTIES"][$propertyKey] = array("VALUE" => CBPDocument::PrepareFileForHistory(array("webdav", "CIBlockDocumentWebdavSocnet", $documentId), $propertyValue["VALUE"], $historyIndex), "DESCRIPTION" => $propertyValue["DESCRIPTION"]);
             } else {
                 $arResult["PROPERTIES"][$propertyKey] = array("VALUE" => $propertyValue["VALUE"], "DESCRIPTION" => $propertyValue["DESCRIPTION"]);
             }
         }
     }
     return $arResult;
 }
Пример #3
0
 function AddDocumentToHistory($docID, $fileName)
 {
     global $USER;
     $documentId = $this->wfParams["DOCUMENT_TYPE"];
     $documentId[2] = $docID;
     $userID = $USER->GetID();
     $rDoc = CIBlockElement::GetList(array(), array('ID' => $docID), false, false, array('MODIFIED_BY'));
     if ($rDoc && ($arDoc = $rDoc->Fetch())) {
         $userID = $arDoc['MODIFIED_BY'];
     }
     $historyDoc = CWebdavDocumentHistory::IsHistoryUpdate($documentId);
     $historyIndex = false;
     if ($historyDoc) {
         $historyIndex = CWebdavDocumentHistory::UpdateDocumentHistory($documentId, $historyDoc['ID']);
     } else {
         $historyIndex = CBPDocument::AddDocumentToHistory($documentId, $fileName, $userID);
     }
     return $historyIndex;
 }