/** * 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; }
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)); }
/** * Deletes file and all connected data and entities (@see Sharing, @see Rights, etc). * @param int $deletedBy Id of user. * @return bool * @throws \Bitrix\Main\ArgumentNullException */ public function delete($deletedBy) { $this->errorCollection->clear(); $success = EditSessionTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } $success = ExternalLinkTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } foreach ($this->getSharingsAsReal() as $sharing) { $sharing->delete($deletedBy); } //with status unreplied, declined (not approved) $success = SharingTable::deleteByFilter(array('REAL_OBJECT_ID' => $this->id)); if (!$success) { return false; } foreach ($this->getAttachedObjects() as $attached) { $attached->delete(); } unset($attached); BizProcDocument::deleteWorkflowsFile($this->id); SimpleRightTable::deleteBatch(array('OBJECT_ID' => $this->id)); $success = RightTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } $success = VersionTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } DeletedLog::addFile($this, $deletedBy, $this->errorCollection); \CFile::delete($this->fileId); $deleteResult = FileTable::delete($this->id); if (!$deleteResult->isSuccess()) { return false; } Driver::getInstance()->getIndexManager()->dropIndex($this); if (!$this->isLink()) { //todo potential - very hard operation. foreach (File::getModelList(array('filter' => array('REAL_OBJECT_ID' => $this->id, '!=REAL_OBJECT_ID' => $this->id))) as $link) { $link->delete($deletedBy); } unset($link); } $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterDeleteFile", array($this->getId(), $deletedBy)); $event->send(); return true; }
protected function deleteProcess($deletedBy, $withDeletingSharing = true) { $this->errorCollection->clear(); $success = EditSessionTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } $success = ExternalLinkTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if ($withDeletingSharing) { foreach ($this->getSharingsAsLink() as $sharing) { $sharing->delete($deletedBy, false); } //with status unreplied, declined (not approved) $success = SharingTable::deleteByFilter(array('REAL_OBJECT_ID' => $this->id)); } if (!$success) { return false; } SimpleRightTable::deleteBatch(array('OBJECT_ID' => $this->id)); $success = RightTable::deleteByFilter(array('OBJECT_ID' => $this->id)); if (!$success) { return false; } DeletedLog::addFile($this, $deletedBy, $this->errorCollection); $resultDelete = FileTable::delete($this->id); if (!$resultDelete->isSuccess()) { return false; } $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterDeleteFile", array($this->getId(), $deletedBy)); $event->send(); return true; }