function testBeginAndCommitTransaction() { $this->driver->shouldReceive("begin")->withNoArgs()->once(); $this->dbManager->begin(); $this->driver->shouldReceive("commit")->withNoArgs()->once(); $this->dbManager->commit(); }
/** * @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(); }
/** * @param string $agentName * @return bool */ public function renewCurrentAgent($agentName) { $this->dbManager->begin(); $row = $this->dbManager->getSingleRow("SELECT agent_pk, agent_name, agent_rev, agent_desc FROM agent " . "WHERE agent_enabled AND agent_name=\$1 ORDER BY agent_pk DESC LIMIT 1", array($agentName), __METHOD__ . '.get'); $this->dbManager->getSingleRow("UPDATE agent SET agent_rev=agent_rev||'.'||substr(md5(agent_ts::text),0,6) " . "WHERE agent_pk=\$1", array($row['agent_pk']), __METHOD__ . '.upd'); unset($row['agent_pk']); $this->dbManager->insertTableRow('agent', $row); $this->dbManager->commit(); return true; }
public function moveUploadBeyond($moveUpload, $beyondUpload) { $this->dbManager->begin(); $this->dbManager->prepare($stmt = __METHOD__ . '.get.single.Upload', $sql = 'SELECT upload_fk,' . self::PRIO_COLUMN . ' FROM upload_clearing WHERE group_fk=$1 AND upload_fk=$2'); $movePoint = $this->dbManager->getSingleRow($sql, array($this->groupId, $moveUpload), $stmt); $beyondPoint = $this->dbManager->getSingleRow($sql, array($this->groupId, $beyondUpload), $stmt); if ($movePoint[self::PRIO_COLUMN] > $beyondPoint[self::PRIO_COLUMN]) { $farPoint = $this->dbManager->getSingleRow("SELECT MAX(" . self::PRIO_COLUMN . ") m FROM upload_clearing WHERE group_fk=\$1 AND " . self::PRIO_COLUMN . "<\$2", array($this->groupId, $beyondPoint[self::PRIO_COLUMN]), 'get.upload.with.lower.priority'); $farPrio = $farPoint['m'] !== null ? $farPoint['m'] : $beyondPoint[self::PRIO_COLUMN] - 1; } else { $farPoint = $this->dbManager->getSingleRow("SELECT MIN(" . self::PRIO_COLUMN . ") m FROM upload_clearing WHERE group_fk=\$1 AND " . self::PRIO_COLUMN . ">\$2", array($this->groupId, $beyondPoint[self::PRIO_COLUMN]), 'get.upload.with.higher.priority'); $farPrio = $farPoint['m'] !== null ? $farPoint['m'] : $beyondPoint[self::PRIO_COLUMN] + 1; } $newPriority = ($farPrio + $beyondPoint[self::PRIO_COLUMN]) / 2; $this->dbManager->getSingleRow('UPDATE upload_clearing SET ' . self::PRIO_COLUMN . '=$1 WHERE group_fk=$2 AND upload_fk=$3', array($newPriority, $this->groupId, $moveUpload), __METHOD__ . '.update.priority'); $this->dbManager->commit(); }
/** * @param int $uploadTreeId * @param int $userId * @param int $groupId * @param int $licenseId * @param string $what * @param string $changeTo */ public function updateClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $what, $changeTo) { $this->dbManager->begin(); $statementGetOldata = "SELECT * FROM clearing_event WHERE uploadtree_fk=\$1 AND rf_fk=\$2 AND group_fk=\$3 ORDER BY clearing_event_pk DESC LIMIT 1"; $statementName = __METHOD__ . 'getOld'; $params = array($uploadTreeId, $licenseId, $groupId); $row = $this->dbManager->getSingleRow($statementGetOldata, $params, $statementName); if (!$row) { //The license was not added as user decision yet -> we promote it here $type = ClearingEventTypes::USER; $row['type_fk'] = $type; $row['comment'] = ""; $row['reportinfo'] = ""; } if ($what == 'reportinfo') { $reportInfo = $changeTo; $comment = $row['comment']; } else { $reportInfo = $row['reportinfo']; $comment = $changeTo; } $this->insertClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, false, $row['type_fk'], $reportInfo, $comment); $this->dbManager->commit(); }