Beispiel #1
0
 public function extract(ContextInterface $context)
 {
     $data = $this->csv->current();
     if (null !== $this->identifierColumn) {
         $context->setIdentifier($data[$this->identifierColumn]);
     }
     $this->csv->next();
     return $data;
 }
Beispiel #2
0
 public function load($data, ContextInterface $context)
 {
     if ($id = $context->getIdentifier()) {
         return $this->conn->update($context->getTableName(), $data, ['id' => $id]);
     }
     // @TODO get id
     //$context->setIdentifier($id);
     //$data['id'] = $this->conn->fetchColumn("SELECT NEXTVAL('fos_user_id_seq')", [], 0);
     return $this->conn->insert($context->getTableName(), $data);
 }
Beispiel #3
0
 public function extract(ContextInterface $context)
 {
     if (!$this->valid()) {
         return false;
     }
     $data = $this->current();
     $this->next();
     if (null !== $this->identifierColumn) {
         $context->setIdentifier($data[$this->identifierColumn]);
     }
     return $data;
 }
Beispiel #4
0
 public function transform($data, ContextInterface $context)
 {
     $this->mapper->verifyCount($data);
     $id = $context->getIdentifier();
     if (null !== $this->logger) {
         $this->logger->info(sprintf('Transforming data with id #%s', $id));
     }
     $object = $this->doctrine->getRepository($this->className)->find($id);
     if (null === $object) {
         //TODO use a configurable factory here
         $object = new $this->className();
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Creating new object "%s"', $this->className));
         }
     }
     $this->mapper->set($data, $object);
     return $object;
 }
Beispiel #5
0
 public function load($entity, ContextInterface $context)
 {
     if (null === $this->entityClass) {
         $this->entityClass = get_class($entity);
     }
     $this->doctrine->getManager()->persist($entity);
     $shouldFlush = $shouldClear = false;
     if ($context instanceof ORMContext) {
         $shouldFlush = $context->shouldFlush();
         $context->shouldFlush(false);
         // TODO really ?
         $shouldClear = $context->shouldClear();
         $context->shouldClear(false);
         // TODO really ?
     }
     $this->counter++;
     if ($this->counter % $this->flushEvery === 0 || $shouldFlush) {
         $this->flush($context);
     }
     if ($this->counter % $this->flushEvery === 0 || $shouldClear) {
         $this->clear($context);
     }
 }
Beispiel #6
0
 public function transform($data, ContextInterface $context)
 {
     $target = $context->getTransformedData();
     $this->set($data, $target);
     return $target;
 }