Example #1
0
 private function importClockings(Status $logger, array $clockingTypeMap, array $usersByName, PDO $source, PropelPDO $dest)
 {
     $statement = $source->query('SELECT * FROM ext_clockings_clockings');
     $logger->info($statement->rowCount());
     if (!$dest->beginTransaction()) {
         throw new Exception('Could not start transaction.');
     }
     $clockingDataByOldID = array();
     try {
         while (is_array($row = $statement->fetch(PDO::FETCH_ASSOC))) {
             $oldId = $row['ID'];
             $authUserName = $row['creator'];
             $userName = $row['username'];
             if (empty($usersByName[$userName])) {
                 $logger->info('Clocking with old ID #' . $oldId . ' references unknown user "' . $userName . '".');
                 continue;
             }
             $type = $row['type'];
             if (!isset($clockingTypeMap[$type])) {
                 $logger->info('Clocking with old ID #' . $oldId . ' references unknown type ' . $type . '.');
                 continue;
             }
             $clockingType = $clockingTypeMap[$type];
             $start = (int) $row['start'];
             $end = (int) $row['end'];
             if ($clockingType->getWholeDay()) {
                 $start = strtotime('today', $start);
                 $end = strtotime('today', $end);
             }
             $clocking = new Clocking();
             $clocking->setUserRelatedByCreatorId($usersByName[$authUserName])->setUserRelatedByUserId($usersByName[$userName])->setClockingType($clockingType)->setApprovalStatus($this->getApprovalStatus($row))->setStart($start)->setEnd($end)->setBreaktime((int) round($row['break'] * 60))->setCreationdate((int) $row['creationdate'])->setLastChanged((int) $row['changed'])->setComment($row['comment'])->setDeleted($row['visibility'])->save($dest);
             $clockingDataByOldID[$oldId] = new ClockingData($clocking, $row);
         }
     } catch (Exception $e) {
         $dest->rollBack();
         $statement->closeCursor();
         $statement = null;
         throw $e;
     }
     if (!$dest->commit()) {
         throw new Exception('Could not commit transaction.');
     }
     $statement->closeCursor();
     $statement = null;
     return $clockingDataByOldID;
 }