/**
  * Returns list of recently files by user.
  * @param mixed|int|User|\CAllUser $user User.
  * @param array                    $filter Filter.
  * @return File[]
  * @internal
  */
 public function getFileModelListByUser($user, array $filter = array())
 {
     $userId = User::resolveUserId($user);
     if (!$userId) {
         $this->errorCollection->addOne(new Error('Could not get user id.'));
         return array();
     }
     $driver = Driver::getInstance();
     $storage = $driver->getStorageByUserId($userId);
     if (!$storage) {
         $this->errorCollection->addOne(new Error('Could not get storage by user id.'));
         return array();
     }
     if ($this->isFirstRun($userId)) {
         if (!$this->hasData($userId)) {
             $this->fixColdStart($userId);
         }
         $this->saveFirstRun($userId);
     }
     $securityContext = $storage->getCurrentUserSecurityContext();
     $parameters = array('filter' => array('RECENTLY_USED.USER_ID' => $userId, 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE, 'TYPE' => ObjectTable::TYPE_FILE), 'order' => array('RECENTLY_USED.CREATE_TIME' => 'DESC'), 'limit' => RecentlyUsedTable::MAX_COUNT_FOR_USER);
     if ($filter) {
         $parameters['filter'] = array_merge($parameters['filter'], $filter);
     }
     $parameters = $driver->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY'));
     return File::getModelList($parameters);
 }
Example #2
0
 public static function RemoveTmpFileAgent()
 {
     $storageModel = self::GetStorage();
     if (!$storageModel) {
         return "CIMDisk::RemoveTmpFileAgent();";
     }
     $date = new \Bitrix\Main\Type\DateTime();
     $date->add('YESTERDAY');
     $fileModels = \Bitrix\Disk\File::getModelList(array('filter' => array('GLOBAL_CONTENT_VERSION' => 1, 'STORAGE_ID' => $storageModel->getId(), '<CREATE_TIME' => $date), 'limit' => 200));
     foreach ($fileModels as $fileModel) {
         $fileModel->delete(\Bitrix\Disk\SystemUser::SYSTEM_USER_ID);
     }
     return "CIMDisk::RemoveTmpFileAgent();";
 }
Example #3
0
 /**
  * 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;
 }