Esempio n. 1
0
 public function exportData($export, $reporter)
 {
     $this->conn->beginTransaction();
     try {
         $lastExportedAt = (int) $export['lastExportedAt'];
         $areas = $this->conn->fetchAll('SELECT a.`id`, a.`name`, t.`id` AS `territoryId`, t.`name` AS `territoryName`, a.`customData`, a.`lastUpdatedAt` ' . 'FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = a.`territoryId` ' . 'WHERE a.`projectId` = :projectId AND a.`statusId` = :statusId', [':projectId' => $export['projectId'], ':statusId' => $export['areaStatusId']]);
         $block = new ExportBlock();
         foreach ($areas as $area) {
             $block->addId($area['id']);
             if ($area['lastUpdatedAt'] > $lastExportedAt) {
                 $area['customData'] = json_decode($area['customData']);
                 $block->addUpdatedId($area['id']);
                 $block->addUpdate($area);
             }
         }
         $event = new ExportEvent($export['projectId'], $export['lastExportedAt'], $reporter);
         $event->addBlock('area', $block);
         $event = $this->eventDispatcher->dispatch(ExportEvents::EXPORT_ONGOING, $event);
         $this->conn->executeQuery('UPDATE `' . ExportTables::DATA_EXPORT_TBL . '` SET `lastExportedAt` = :time WHERE `id` = :id', [':time' => time(), ':id' => $export['id']]);
         $this->conn->commit();
         return $event->output();
     } catch (Exception $ex) {
         $this->conn->rollBack();
         throw $ex;
     }
 }
Esempio n. 2
0
 public function addBlock($name, ExportBlock $block)
 {
     if (isset($this->blocks[$name])) {
         throw new InvalidArgumentException('Cannot overwrite export block: ' . $name);
     }
     $this->blocks[$name] = $block;
     $callback = $this->reporter;
     $callback('Exporting block ' . $name . ': IDs ' . $block->countIds() . '; Updates ' . $block->countUpdates());
 }
Esempio n. 3
0
 public function exportRouteDescriptions($lastExport, $routeIds, $updatedRouteIds)
 {
     $block = new ExportBlock();
     if (sizeof($routeIds) > 0) {
         $stmt = $this->conn->query('SELECT `routeId`, `noteType`, `content`, `lastUpdatedAt`  FROM `' . EdkTables::ROUTE_NOTE_TBL . '` WHERE `routeId` IN (' . implode(',', $routeIds) . ') ');
         while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
             $block->addId(['routeId' => $row['routeId'], 'noteType' => $row['noteType']]);
             if ($row['lastUpdatedAt'] > $lastExport || in_array($row['routeId'], $updatedRouteIds)) {
                 $block->addUpdate($row);
             }
         }
         $stmt->closeCursor();
     }
     return $block;
 }