Exemplo n.º 1
0
 public function parse()
 {
     $batch = 10;
     while (($data = $this->getLine()) !== false) {
         try {
             array_walk($data, function (&$value) {
                 $value = trim($value);
                 if (!strlen($value)) {
                     $value = null;
                 }
             });
             if (($product = $this->isProductExist($data[3])) === false) {
                 $product = new Entity\Product();
             }
             $product->setCustomer($this->_customer);
             $product->setName($data[3]);
             $product->setTnved($data[5]);
             $product->setHscode($data[6]);
             $product->setDescription($data[7]);
             $product->setDescriptionInvoice($data[8]);
             $product->setExtraData($data[9]);
             $product->setNetWeight($data[10]);
             $product->setStatus($this->_status);
             $product->setCustomText1($data[13]);
             $this->_em->persist($product);
             if ($this->_count % $batch === 0) {
                 echo memory_get_usage() / 1024, "\n";
                 $this->_em->flush();
                 $this->_em->clear($product);
             }
             $this->_count++;
         } catch (\Exception $ex) {
             $logger = $this->get('logger');
             $logger->error($ex->getMessage());
         }
     }
     $this->_em->flush();
     $this->_em->clear();
 }
Exemplo n.º 2
0
 private function createNewProduct($data)
 {
     $product = new Entity\Product();
     $product->setCustomer($this->_customer);
     $product->setName($data[3]);
     $product->setTnved($data[5]);
     $product->setHscode($data[6]);
     $product->setDescription($data[7]);
     $product->setDescriptionInvoice($data[8]);
     $product->setExtraData($data[9]);
     $product->setNetWeight($data[10]);
     $product->setStatus($this->_status);
     $product->setCustomText1($data[13]);
     $this->_em->persist($product);
     return $product;
 }