/**
  * @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();
 }