/**
  * @param ItemTreeBounds $itemBounds
  * @param int $userId
  * @param int $groupId
  * @param int $type
  * @param boolean $global
  * @param int[] $additionalEventIds additional event ids to include, indexed by licenseId
  */
 public function makeDecisionFromLastEvents(ItemTreeBounds $itemBounds, $userId, $groupId, $type, $global, $additionalEventIds = array())
 {
     if ($type < self::NO_LICENSE_KNOWN_DECISION_TYPE) {
         return;
     }
     $this->dbManager->begin();
     $itemId = $itemBounds->getItemId();
     $previousEvents = $this->clearingDao->getRelevantClearingEvents($itemBounds, $groupId);
     if ($type === self::NO_LICENSE_KNOWN_DECISION_TYPE) {
         $type = DecisionTypes::IDENTIFIED;
         $clearingEventIds = $this->insertClearingEventsForAgentFindings($itemBounds, $userId, $groupId, true, ClearingEventTypes::USER);
         foreach ($previousEvents as $eventId => $clearingEvent) {
             if (!in_array($eventId, $clearingEventIds) && !$clearingEvent->isRemoved()) {
                 $licenseId = $clearingEvent->getLicenseId();
                 $newEventId = $this->clearingDao->insertClearingEvent($itemBounds->getItemId(), $userId, $groupId, $licenseId, true);
                 $clearingEventIds[$licenseId] = $newEventId;
             }
         }
     } else {
         $clearingEventIds = $this->insertClearingEventsForAgentFindings($itemBounds, $userId, $groupId, false, ClearingEventTypes::AGENT, $previousEvents);
         foreach ($previousEvents as $clearingEvent) {
             $clearingEventIds[$clearingEvent->getLicenseId()] = $clearingEvent->getEventId();
         }
     }
     $currentDecision = $this->clearingDao->getRelevantClearingDecision($itemBounds, $groupId);
     $clearingEventIds = array_unique(array_merge($clearingEventIds, $additionalEventIds));
     $scope = $global ? DecisionScopes::REPO : DecisionScopes::ITEM;
     if (null === $currentDecision || $this->clearingDecisionIsDifferentFrom($currentDecision, $type, $scope, $clearingEventIds)) {
         $this->clearingDao->createDecisionFromEvents($itemBounds->getItemId(), $userId, $groupId, $type, $scope, $clearingEventIds);
     } else {
         $this->clearingDao->removeWipClearingDecision($itemId, $groupId);
     }
     $this->dbManager->commit();
 }
Пример #2
0
 /**
  * @param int $itemId
  * @param ClearingDecision $clearingDecisionToCopy
  */
 protected function createCopyOfClearingDecision($itemId, $userId, $groupId, $clearingDecisionToCopy)
 {
     $clearingEventIdsToCopy = array();
     /** @var ClearingEvent $clearingEvent */
     foreach ($clearingDecisionToCopy->getClearingEvents() as $clearingEvent) {
         $clearingEventIdsToCopy[] = $clearingEvent->getEventId();
     }
     $this->clearingDao->createDecisionFromEvents($itemId, $userId, $groupId, $clearingDecisionToCopy->getType(), $clearingDecisionToCopy->getScope(), $clearingEventIdsToCopy);
 }
Пример #3
0
 protected function insertDecisionFromTwoEvents($scope = DecisionScopes::ITEM, $originallyClearedItemId = 23)
 {
     $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
     $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef();
     $addedLicenses = array($licenseRef1, $licenseRef2);
     assertThat($addedLicenses, not(arrayContaining(null)));
     $clearingLicense1 = new ClearingLicense($licenseRef1, false, ClearingEventTypes::USER, "42", "44");
     $clearingLicense2 = new ClearingLicense($licenseRef2, true, ClearingEventTypes::USER, "-42", "-44");
     $eventId1 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, $this->userId, $this->groupId, $licenseRef1->getId(), $clearingLicense1->isRemoved(), $clearingLicense1->getType(), $clearingLicense1->getReportinfo(), $clearingLicense1->getComment());
     $eventId2 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, 5, $this->groupId, $licenseRef2->getId(), $clearingLicense2->isRemoved(), $clearingLicense2->getType(), $clearingLicense2->getReportinfo(), $clearingLicense2->getComment());
     $addedEventIds = array($eventId1, $eventId2);
     $this->clearingDao->createDecisionFromEvents($originallyClearedItemId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $scope, $addedEventIds);
     return array($clearingLicense1, $clearingLicense2, $addedEventIds);
 }