Beispiel #1
0
 public function run()
 {
     $writerFactory = new WriterFactory();
     /** @var WriterInterface $writer */
     $writer = $writerFactory->get($this->config['parameters']['db']);
     $uploaded = [];
     $tables = $this->config['parameters']['tables'];
     foreach ($tables as $table) {
         $ignoreExport = false;
         if (isset($options['table'])) {
             $ignoreExport = true;
         }
         if (!$writer->isTableValid($table, $ignoreExport)) {
             Logger::log('warning', sprintf("Table '%s' not exported", $table["tableId"]));
             continue;
         }
         $sourceTableId = $table['tableId'];
         $outputTableName = $table['dbName'];
         // @todo: select not ignored columns in csv somehow - during data preparation
         $sourceFilename = $this->dataDir . "/in/tables/" . $sourceTableId . ".csv";
         try {
             if ($writer->isAsync()) {
                 $writer->drop($outputTableName);
                 $writer->create($table);
                 //                $writer->writeAsync($fileInfo, $outputTableName);
             } else {
                 $writer->drop($outputTableName);
                 $writer->create($table);
                 $writer->write($sourceFilename, $outputTableName, $table);
             }
         } catch (\Exception $e) {
             throw new UserException($e->getMessage(), 400, $e);
         }
         $uploaded[] = $sourceTableId;
     }
     return ['status' => 'ok', 'uploaded' => $uploaded];
 }
Beispiel #2
0
 /**
  * @param $driver
  * @return WriterInterface
  * @throws \Exception
  * @throws \Keboola\Juicer\Exception\UserException
  */
 public function getWriter($driver)
 {
     $writerFactory = new WriterFactory();
     return $writerFactory->get($this->getConfig($driver)['parameters']['db']);
 }