Example #1
0
 /**
  * Creates a small folder/file hierarchy
  *
  * @param string $userId
  * @param array $structure
  */
 private function createSampleData($userId, $structure)
 {
     $userFolder = $this->server->getUserFolder($userId);
     $this->createStructure($userFolder, $structure);
     // Add configuration. This will break if the config filename or the userId is changed
     $this->addFile($userFolder, $userId . '-' . 'gallery.cnf', 'gallery.cnf');
 }
 /**
  * Creates an environment for a logged in user
  *
  * @return Environment
  */
 protected function setUserBasedEnv()
 {
     $this->coreTestCase->loginAsUser($this->userId);
     $this->userFolder = $this->server->getUserFolder($this->userId);
     $environment = $this->instantiateEnvironment();
     $environment->setStandardEnv();
     return $environment;
 }
 /**
  * Creates a small folder/file hierarchy and returns the top folder
  *
  * @param string $userId
  * @param string $userPassword
  *
  * @return Folder
  */
 private function createEnv($userId, $userPassword)
 {
     $this->setupUser($userId, $userPassword);
     $userFolder = $this->server->getUserFolder($userId);
     $user = $this->server->getUserManager()->get($userId);
     $user->setDisplayName('UberTester (' . $userId . ')');
     $folder1 = $userFolder->newFolder('folder1');
     $folder1->newFile('file1');
     $subFolder = $folder1->newFolder('folder1.1');
     $subFolder->newFile('file1.1');
     return $folder1;
 }
Example #4
0
 /**
  * @param array $fileIds
  * @param \OC_EventSource $eventSource
  */
 public function indexFiles(array $fileIds, \OC_EventSource $eventSource = null)
 {
     foreach ($fileIds as $id) {
         $fileStatus = $this->mapper->getOrCreateFromFileId($id);
         try {
             // before we start mark the file as error so we know there
             // was a problem in case the php execution dies and we don't try
             // the file again
             $this->mapper->markError($fileStatus);
             $nodes = $this->server->getUserFolder()->getById($id);
             // getById can return more than one id because the containing storage might be mounted more than once
             // Since we only want to index the file once, we only use the first entry
             if (isset($nodes[0])) {
                 /** @var File $node */
                 $node = $nodes[0];
             } else {
                 throw new VanishedException($id);
             }
             if (!$node instanceof File) {
                 throw new NotIndexedException();
             }
             $path = $node->getPath();
             foreach ($this->skippedDirs as $skippedDir) {
                 if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) {
                     throw new SkippedException('skipping file ' . $id . ':' . $path);
                 }
             }
             if ($eventSource) {
                 $eventSource->send('indexing', $path);
             }
             if ($this->indexFile($node, false)) {
                 $this->mapper->markIndexed($fileStatus);
             }
         } catch (VanishedException $e) {
             $this->mapper->markVanished($fileStatus);
         } catch (NotIndexedException $e) {
             $this->mapper->markUnIndexed($fileStatus);
         } catch (SkippedException $e) {
             $this->mapper->markSkipped($fileStatus);
             $this->logger->debug($e->getMessage());
         } catch (\Exception $e) {
             //sqlite might report database locked errors when stock filescan is in progress
             //this also catches db locked exception that might come up when using sqlite
             $this->logger->error($e->getMessage() . ' Trace:\\n' . $e->getTraceAsString());
             $this->mapper->markError($fileStatus);
             // TODO Add UI to trigger rescan of files with status 'E'rror?
             if ($eventSource) {
                 $eventSource->send('error', $e->getMessage());
             }
         }
     }
     $this->index->commit();
 }
Example #5
0
 /**
  * Creates the environment based on the linkItem the token links to
  *
  * @param array $linkItem
  */
 public function setTokenBasedEnv($linkItem)
 {
     // Resolves reshares down to the last real share
     $rootLinkItem = Share::resolveReShare($linkItem);
     $origShareOwner = $rootLinkItem['uid_owner'];
     $this->userFolder = $this->serverContainer->getUserFolder($origShareOwner);
     // TODO: Replace with this in 8.2 (https://github.com/owncloud/core/pull/16965)
     // You get root by calling getRootFolder() on the server container
     //$this->userFolder = $this->root->getUserFolder($origShareOwner);
     // This is actually the node ID
     $this->sharedNodeId = $linkItem['file_source'];
     $this->fromRootToFolder = $this->buildFromRootToFolder($this->sharedNodeId);
     $this->folderName = $linkItem['file_target'];
     $this->userId = $rootLinkItem['uid_owner'];
     $this->sharePassword = $linkItem['share_with'];
 }