protected function changeTreeIdsToPaths(&$ungrupedStatements, $uploadTreeTableName, $uploadId)
 {
     $parentId = $this->treeDao->getMinimalCoveringItem($uploadId, $uploadTreeTableName);
     foreach ($ungrupedStatements as &$statement) {
         $uploadTreeId = $statement['uploadtree_pk'];
         unset($statement['uploadtree_pk']);
         if (!array_key_exists($uploadTreeId, $this->fileNameCache)) {
             $this->fileNameCache[$uploadTreeId] = $this->treeDao->getFullPath($uploadTreeId, $uploadTreeTableName, $parentId);
         }
         $statement['fileName'] = $this->fileNameCache[$uploadTreeId];
     }
     unset($statement);
 }
Example #2
0
 public function testGetUploadHashes()
 {
     $this->testDb->createPlainTables(array('pfile'));
     $this->dbManager->queryOnce('ALTER TABLE uploadtree RENAME TO uploadtree_a');
     $this->testDb->insertData(array('uploadtree_a', 'pfile'));
     // (pfile_pk, pfile_md5, pfile_sha1, pfile_size) := (4, '59CACDFCE5051CD8A1D8A1F2DCCE40A5', '04621571BCBABCE75C4DD1C6445B87DEC0995734', 12320);
     $hashes = $this->treeDao->getItemHashes(7, 'uploadtree_a');
     assertThat($hashes, equalTo(array('md5' => '59CACDFCE5051CD8A1D8A1F2DCCE40A5', 'sha1' => '04621571BCBABCE75C4DD1C6445B87DEC0995734')));
 }
 public function testGetFileNamesGroupByText()
 {
     $this->clearedGetterTest = new TestClearedGetter();
     $uploadId = 1;
     $parentId = 112;
     $uploadTreeTableName = "ut";
     $this->uploadDao->shouldReceive('getUploadtreeTableName')->with($uploadId)->andReturn($uploadTreeTableName);
     $this->treeDao->shouldReceive('getMinimalCoveringItem')->with($uploadId, $uploadTreeTableName)->andReturn($parentId);
     $this->treeDao->shouldReceive('getFullPath')->with(1, $uploadTreeTableName, $parentId)->andReturn("a/1");
     $this->treeDao->shouldReceive('getFullPath')->with(2, $uploadTreeTableName, $parentId)->andReturn("a/2");
     $this->treeDao->shouldReceive('getFullPath')->with(3, $uploadTreeTableName, $parentId)->andReturn("a/b/1");
     $tester = new TestClearedGetter("text");
     $statements = $tester->getCleared($uploadId);
     $expected = array("statements" => array(array("content" => "1", "text" => "t1", "comments" => "c1", "files" => array("a/1")), array("content" => "1", "text" => "t2", "comments" => "c1", "files" => array("a/2")), array("content" => "2", "text" => "t3", "comments" => "c3", "files" => array("a/b/1"))));
     $expected = arsort($expected);
     assertThat($expected, equalTo($statements));
 }
Example #4
0
 private function runnerReuserScanWithARepoClearingEnhanced($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $originallyClearedItemId = 23;
     /* upload 3 in the test db is the same as upload 2 -> items 13-24 in upload 2 correspond to 33-44 */
     $reusingUploadItemShift = 20;
     $this->dbManager->queryOnce("UPDATE uploadtree_a SET pfile_fk=351 WHERE uploadtree_pk={$originallyClearedItemId}+{$reusingUploadItemShift}", __METHOD__ . '.minorChange');
     $this->uploadDao->addReusedUpload($uploadId = 3, $reusedUpload = 2, $this->groupId, $this->groupId, $reuseMode = 1);
     $repoPath = $this->testDb->getFossSysConf() . '/repo/files/';
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(4)->andReturn($repoPath . '04621571bcbabce75c4dd1c6445b87dec0995734.59cacdfce5051cd8a1d8a1f2dcce40a5.12320');
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(351)->andReturn($repoPath . 'c518ce1658140b65fa0132ad1130cb91512416bf.8e913e594d24ff3aeabe350107d97815.35829');
     list($clearingLicense1, $clearingLicense2, $addedEventIds) = $this->insertDecisionFromTwoEvents(DecisionScopes::REPO, $originallyClearedItemId);
     $clearingLicenses = array($clearingLicense1, $clearingLicense2);
     list($success, $output, $retCode) = $runner->run($uploadId, $this->userId, $this->groupId);
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'reuser failed: ' . $output);
     $newUploadClearings = $this->getFilteredClearings($uploadId, $this->groupId);
     $potentiallyReusableClearings = $this->getFilteredClearings($reusedUpload, $this->groupId);
     assertThat($newUploadClearings, is(arrayWithSize(1)));
     assertThat($potentiallyReusableClearings, is(arrayWithSize(1)));
     /** @var ClearingDecision */
     $potentiallyReusableClearing = $potentiallyReusableClearings[0];
     /** @var ClearingDecision */
     $newClearing = $newUploadClearings[0];
     /* they are actually the same ClearingDecision
      * only sameFolder and sameUpload are different */
     assertThat($newClearing, not(equalTo($potentiallyReusableClearing)));
     assertThat($newClearing->getClearingLicenses(), arrayContainingInAnyOrder($clearingLicenses));
     assertThat($newClearing->getType(), equalTo($potentiallyReusableClearing->getType()));
     assertThat($newClearing->getScope(), equalTo($potentiallyReusableClearing->getScope()));
     assertThat($newClearing->getUploadTreeId(), equalTo($potentiallyReusableClearing->getUploadTreeId() + $reusingUploadItemShift));
     /* reuser should have not created a correct local event history */
     $bounds = $this->uploadDao->getItemTreeBounds($originallyClearedItemId + $reusingUploadItemShift);
     $newEvents = $this->clearingDao->getRelevantClearingEvents($bounds, $this->groupId);
     assertThat($newEvents, is(arrayWithSize(count($clearingLicenses))));
     /** @var ClearingEvent $newEvent */
     foreach ($newEvents as $newEvent) {
         assertThat($newEvent->getEventId(), anyOf($addedEventIds));
         assertThat($newEvent->getClearingLicense(), anyOf($clearingLicenses));
     }
     $this->rmRepo();
 }
 /**
  *  @brief write out text in format 'filepath: copyright list'
  */
 private function printRow($row, $uploadtree_tablename, &$allCopyrightEntries, $parentId = 0)
 {
     $filepath = $this->treeDao->getFullPath($row['uploadtree_pk'], $uploadtree_tablename, $parentId);
     $copyrightArray = array();
     foreach ($allCopyrightEntries as $entry) {
         if ($entry['uploadtree_pk'] == $row['uploadtree_pk']) {
             $copyrightArray[] = $entry['content'];
         }
     }
     $copyright = implode(', ', $copyrightArray);
     /** include and exclude together */
     if (-1 != $this->includingCopyright && -1 != $this->excludingCopyright && !empty($this->includingCopyright) && !empty($this->excludingCopyright)) {
         if (empty($copyright) || stristr($copyright, $this->includingCopyright) || stristr($copyright, $this->excludingCopyright)) {
             return;
         }
     } else {
         if (!(-1 == $this->includingCopyright && -1 == $this->excludingCopyright) && !(empty($this->includingCopyright) && empty($this->excludingCopyright)) && !(empty($this->includingCopyright) && empty($copyright)) && !(empty($this->excludingCopyright) && !empty($copyright)) && !(-1 != $this->includingCopyright && !empty($this->includingCopyright) && !empty($copyright) && stristr($copyright, $this->includingCopyright)) && !(-1 != $this->excludingCopyright && !empty($this->excludingCopyright) && !empty($copyright) && !stristr($copyright, $this->excludingCopyright))) {
             return;
         }
     }
     print "{$filepath}: {$copyright}\n";
 }