/** * Links a transaction with the specified clockings. * * @return void */ private function linkTransactionClockings(Transaction $transaction, $clockings, PropelPDO $con) { foreach ($clockings as $clocking) { /* $approvalStatus = $clocking->getApprovalStatus(); switch ( $approvalStatus ) { case ClockingPeer::APPROVAL_STATUS_PRELIMINARY: case ClockingPeer::APPROVAL_STATUS_REQUIRED: $clocking->setApprovalStatus(ClockingPeer::APPROVAL_STATUS_CONFIRMED); break; case ClockingPeer::APPROVAL_STATUS_CONFIRMED: case ClockingPeer::APPROVAL_STATUS_AS_IS: break; case ClockingPeer::APPROVAL_STATUS_DENIED: throw new Exception($clocking->__toString().' has been denied and therefore cannot be used in a transaction.'); default: throw new Exception($clocking->__toString().' has an invalid approval status '.$approvalStatus.'.'); } */ $transactionClocking = new TransactionClocking(); $transactionClocking->setTransaction($transaction)->setClocking($clocking)->save($con); } }
private function importTransactions(Status $logger, array $clockingTypeMap, array $bookingTypesByIdentifier, array $usersByName, array $clockingDataByOldID, PDO $source, PropelPDO $dest) { if (!$dest->beginTransaction()) { throw new Exception('Could not start transaction.'); } try { $statement = $source->query('SELECT * FROM ext_clockings_transactions'); $logger->info($statement->rowCount()); $oldTransactions = $statement->fetchAll(PDO::FETCH_ASSOC); $statement->closeCursor(); $statement = null; foreach ($oldTransactions as $rowIndex => $oldTransaction) { $authUserName = $oldTransaction['creator']; $userName = $oldTransaction['username']; if (empty($usersByName[$userName])) { $logger->info('Transaction #' . $oldTransaction['ID'] . ' references unknown user "' . $userName . '".'); continue; } $transaction = new Transaction(); $dataItems = $this->getTransactionClockingDataItems($logger, $oldTransaction, $clockingDataByOldID, $source); $clockings = $this->getClockings($dataItems); if (empty($clockings)) { $date = (int) $oldTransaction['date']; $start = $date; $end = $date; } else { list($start, $end) = $this->getClockingRange($clockings); foreach ($clockings as $clocking) { $transactionClocking = new TransactionClocking(); $transaction->addTransactionClocking($transactionClocking->setTransaction($transaction)->setClocking($clocking)); } } // Check transaction / booking consistency $logger->start('Checking consistency of new transactions & bookings'); $worktimeId = $bookingTypesByIdentifier['regular']->getId(); $flexitimeId = $bookingTypesByIdentifier['flexitime']->getId(); $overtimeId = $bookingTypesByIdentifier['overtime']->getId(); $vacationId = $bookingTypesByIdentifier['vacation']->getId(); $sickLeaveId = $bookingTypesByIdentifier['sick_leave']->getId(); $educationId = $bookingTypesByIdentifier['education']->getId(); $actualTimes = array($worktimeId => 0.0, $flexitimeId => 0.0, -$flexitimeId => 0.0, $overtimeId => 0.0, $vacationId => 0.0, $sickLeaveId => 0.0, $educationId => 0.0); //$actualDenied = 0; $bookings = $this->createBookings($logger, $dataItems, $bookingTypesByIdentifier, $dest); foreach ($bookings as $booking) { $bookingTypeId = $booking->getBookingTypeId(); if (!isset($actualTimes[$bookingTypeId])) { throw new Exception('Unknown booking type #' . $bookingTypeId . ' specified for booking #' . $booking->getId() . '.'); } $value = $booking->getValue(); if ($bookingTypeId === $flexitimeId and $value < 0) { $actualTimes[-$bookingTypeId] += $value; } else { $actualTimes[$bookingTypeId] += $value; } $transaction->addBooking($booking); } $transaction->setUserRelatedByCreatorId($usersByName[$authUserName])->setUserRelatedByUserId($usersByName[$userName])->setStart($start)->setEnd($end)->setCreationdate((int) $oldTransaction['creationdate'])->setComment($oldTransaction['comment'])->setDeleted($oldTransaction['visibility'])->save($dest); // Cross-check times of bookings and transaction #$this->failTimeDelta($logger, $oldTransaction, 'time', $actualTimes[$worktimeId] + $actualTimes[$flexitimeId] + $actualTimes[$overtimeId], $bookings); #$this->failTimeDelta($logger, $oldTransaction, 'time', $actualTimes[$worktimeId], $bookings); $this->failTimeDelta($logger, $oldTransaction, 'flexitime', $actualTimes[$flexitimeId] + $actualTimes[-$flexitimeId], $bookings); $this->failTimeDelta($logger, $oldTransaction, 'overtime', $actualTimes[$overtimeId], $bookings); //$this->failTimeDelta($logger, $oldTransaction, 'denied', $actualDenied, $bookings); $logger->done(); } } catch (Exception $e) { $dest->rollBack(); throw $e; } if (!$dest->commit()) { throw new Exception('Could not commit transaction.'); } }
/** * @param TransactionClocking $transactionClocking The transactionClocking object to add. */ protected function doAddTransactionClocking($transactionClocking) { $this->collTransactionClockings[] = $transactionClocking; $transactionClocking->setTransaction($this); }