/**
  * Fixes cold start, when we don't have any data in RecentlyUsedTable.
  * @param mixed|int|User|\CAllUser $user User.
  * @return bool
  * @throws \Bitrix\Main\ArgumentException
  */
 private function fixColdStart($user)
 {
     $userId = User::resolveUserId($user);
     if (!$userId) {
         $this->errorCollection->addOne(new Error('Could not get user id.'));
         return false;
     }
     $storage = Driver::getInstance()->getStorageByUserId($userId);
     if (!$storage) {
         $this->errorCollection->addOne(new Error('Could not get storage by user id.'));
         return false;
     }
     $fromDate = DateTime::createFromTimestamp(time() - 14 * 24 * 3600);
     $objects = array();
     $query = FileTable::getList(array('select' => array('ID', 'UPDATE_TIME'), 'filter' => array('STORAGE_ID' => $storage->getId(), 'TYPE' => ObjectTable::TYPE_FILE, 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE, '>UPDATE_TIME' => $fromDate, array('LOGIC' => 'OR', array('CREATED_BY' => $userId), array('UPDATED_BY' => $userId))), 'order' => array('UPDATE_TIME' => 'DESC'), 'limit' => RecentlyUsedTable::MAX_COUNT_FOR_USER));
     while ($row = $query->fetch()) {
         $objects[] = array('USER_ID' => $userId, 'OBJECT_ID' => $row['ID'], 'CREATE_TIME' => $row['UPDATE_TIME']);
     }
     unset($row, $query, $fromDate);
     Collection::sortByColumn($objects, array('CREATE_TIME' => SORT_ASC));
     RecentlyUsedTable::insertBatch($objects);
     return true;
 }
Example #2
0
 public static function GetPropertiesDialog($documentType, $activityName, $arWorkflowTemplate, $arWorkflowParameters, $arWorkflowVariables, $arCurrentValues = null, $formName = "")
 {
     $runtime = CBPRuntime::GetRuntime();
     if (!is_array($arWorkflowParameters)) {
         $arWorkflowParameters = array();
     }
     if (!is_array($arWorkflowVariables)) {
         $arWorkflowVariables = array();
     }
     $documentService = $runtime->GetService("DocumentService");
     if (!is_array($arCurrentValues)) {
         $arCurrentValues = array();
         $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
         if (is_array($arCurrentActivity["Properties"]) && array_key_exists("Fields", $arCurrentActivity["Properties"]) && is_array($arCurrentActivity["Properties"]["Fields"])) {
             foreach ($arCurrentActivity["Properties"]["Fields"] as $k => $v) {
                 $arCurrentValues[$k] = $v;
                 if (in_array($k, array("CREATED_BY", "RESPONSIBLE_ID", "ACCOMPLICES", "AUDITORS"))) {
                     if (!is_array($arCurrentValues[$k])) {
                         $arCurrentValues[$k] = array($arCurrentValues[$k]);
                     }
                     $ar = array();
                     foreach ($arCurrentValues[$k] as $val) {
                         if (intval($val) . "!" == $val . "!") {
                             $val = "user_" . $val;
                         }
                         $ar[] = $val;
                     }
                     $arCurrentValues[$k] = CBPHelper::UsersArrayToString($ar, $arWorkflowTemplate, $documentType);
                 }
                 if ('UF_TASK_WEBDAV_FILES' == $k && is_array($arCurrentValues[$k]) && CModule::IncludeModule("disk") && \Bitrix\Disk\Configuration::isSuccessfullyConverted()) {
                     foreach ($arCurrentValues[$k] as $key => $fileId) {
                         if (!empty($fileId) && is_string($fileId) && substr($fileId, 0, 1) != 'n') {
                             $item = \Bitrix\Disk\Internals\FileTable::getList(array('select' => array('ID'), 'filter' => array('=XML_ID' => $fileId, 'TYPE' => \Bitrix\Disk\Internals\FileTable::TYPE_FILE)))->fetch();
                             if ($item) {
                                 $arCurrentValues[$k][$key] = 'n' . $item['ID'];
                             }
                         }
                     }
                     unset($fileId);
                 }
             }
         }
         $arCurrentValues["HOLD_TO_CLOSE"] = $arCurrentActivity["Properties"]["HoldToClose"] ? "Y" : "N";
         $arCurrentValues["AUTO_LINK_TO_CRM_ENTITY"] = $arCurrentActivity["Properties"]["AUTO_LINK_TO_CRM_ENTITY"] ? "Y" : "N";
     } else {
         foreach (static::$arAllowedTasksFieldNames as $field) {
             if ((!is_array($arCurrentValues[$field]) && strlen($arCurrentValues[$field]) <= 0 || is_array($arCurrentValues[$field]) && count($arCurrentValues[$field]) <= 0) && strlen($arCurrentValues[$field . "_text"]) > 0) {
                 $arCurrentValues[$field] = $arCurrentValues[$field . "_text"];
             }
         }
     }
     $arDocumentFields = self::__GetFields();
     return $runtime->ExecuteResourceFile(__FILE__, "properties_dialog.php", array("arCurrentValues" => $arCurrentValues, "formName" => $formName, "documentType" => $documentType, "popupWindow" => &$popupWindow, "arDocumentFields" => $arDocumentFields));
 }