latest update
[namibia] / module / Stock / src / Stock / Service / BulkImport.php
1 <?php
2 namespace Stock\Service;
3
4 use Stock\Utility\DataStore;
5 use Stock\Utility\BulkImportHelper;
6 use Stock\Utility\ImportUtility;
7 use Utility\Debug;
8 use Utility\Import\Csv as ImportCsv;
9 use Workspace\Contract\UseOnce as ContractUseOnce;
10 use Workspace\Service\DataBin as DataBinCore;
11 use Workspace\UseCase\Options as UseCaseOptions;
12 use Workspace\UseCase\Requirement as UseCaseRequirement;
13 use Workspace\Utility\ServiceInputParams;
14 use Zend\Form\Element\DateTime;
15
16
17 /**
18  * Class BulkImport
19  * @package Stock\Service
20  * @author  Andre Fourie
21  */
22 class BulkImport extends DataBinCore
23 {
24
25         /**
26          * @var \Stock\Utility\ImportUtility
27          */
28         protected $util;
29         /**
30          * @var \Stock\Utility\BulkImportHelper
31          */
32         protected $helper;
33         /**
34          * @var \Stock\Utility\DataStore
35          */
36         protected $store;
37         /**
38          * @var \Utility\Import\Csv
39          */
40         public $importer;
41         /**
42          * @var string
43          */
44         public $previousMmCode;
45
46     /**
47      * @var array
48      */
49     public $exceptions = array();
50
51     public $userId;
52     public $companyId;
53
54     public $recordCounter = 0;
55     public $successCounter = 0;
56     public $failedCounter = 0;
57
58         #-------------------------------------------------- API INTERFACE
59         /**
60          * Contract to Upload and run the TU data import.
61          * @return \Workspace\Contract\UseOnce
62          */
63         public function contractUpload()
64         {
65                 $requirement = new UseCaseRequirement();
66                 $requirement->addRequiredInput(
67                         array(
68                                 'Upload' => array(
69                                         'csvFile'       => 'Id',
70                     'importType'    => 'String255'
71                                 )
72                         )
73                 );
74                 return new ContractUseOnce(
75                         new UseCaseOptions(),
76                         $requirement
77                 );
78         }
79
80         /**
81          * Upload and run the TU data import.
82          * @param object|null                           $jobRecord
83          * @param \Workspace\Utility\ServiceInputParams $contract
84          * @return array
85          */
86         public function executeUpload($jobRecord, ServiceInputParams $contract)
87         {
88 //        \Utility\Debug::errorLog('executeUpload $contract->data', $contract->data);
89
90                 $jobRecord = null;
91                 $uploadId  = $contract->data->Upload['csvFile'];
92                 $document  = $this->em->find('Utility\\Entity\\Document', $uploadId);
93                 if (is_null($document))
94                 {
95                         Debug::errorLog(
96                                 'Bulk Data Import EXCEPTION',
97                                 'Could not find document id: ' . $uploadId
98                         );
99                         return;
100                 }
101                 $fileName = $document->filename;
102         $importType = $contract->data->Upload['importType'];
103
104                 $this->offlineBulkDataImport($fileName,$importType);
105
106                 return $contract->success('Import being processed.', array());
107
108         }
109
110
111         /**
112          * @param $fileName
113          */
114         protected function offlineBulkDataImport($fileName,$importType)
115         {
116 //              exec(
117 //                      'php /var/www/namibia/public/index.php bulk vehicle import '
118 //                      . $fileName . ' ' . $importType
119 //                      . ' >>/log/php.log &'
120 //              );
121
122         $authData      = \Utility\Registry::getAuthData();
123         $companyId = isset($authData['company']['id']) ? $authData['company']['id'] : null;
124         $userId = isset($authData['id']) ? $authData['id'] : null;
125
126 //        exec(
127 //            'php /var/www/NIRPH/Bid4Cars2Repo/public/index.php bulk vehicle import '
128 //            . $fileName . ' ' . $importType . ' ' . $userId . ' ' . $companyId
129 //            . ' >>/log/php.log &'
130 //        );
131
132         exec(
133             'php /var/www/namibia/public/index.php bulk vehicle import '
134             . $fileName . ' ' . $importType . ' ' . $userId . ' ' . $companyId
135             . ' >>/log/php.log &'
136         );
137         }
138
139
140
141         #-------------------------------------------------- OFFLINE PROCESSING
142         /**
143          * CRON functionality: Import updated transunion vehicle data.
144          * @param string $filename
145          */
146         public function scriptUpdateVehicleData($filename,$importType,$userId,$companyId)
147         {
148 //        \Utility\Debug::errorLog('$filename', $filename);
149 //        \Utility\Debug::errorLog('$importType', $importType);
150
151                 #-> Ensure we don't have problem with script timeout.
152                 set_time_limit(0);
153
154                 #-> Prepare helpers.
155                 $this->util   = new ImportUtility($this->em);
156                 $this->store  = new DataStore();
157                 $this->helper = new BulkImportHelper($this->em, $this->store);
158         $this->exceptions = array();
159         $this->userId = $userId;
160         $this->companyId = $companyId;
161
162                 #-> Catch errors.
163                 try
164                 {
165                         #-> Get things ready.
166                         $this->prepareForCsvProcessing($filename);
167
168             switch ($importType)
169             {
170                 case 'Drive':
171                     //Read File
172                     $file = fopen(getcwd() . '/public/documents/' . $filename, 'r');
173                     $data=array();
174                     while (($data_tmp = fgetcsv($file, 1000, ";")) !== FALSE) {
175 //                        \Utility\Debug::errorLog('$data_tmp', $data_tmp);
176                         $data[] = $data_tmp;
177                     }
178                     fclose($file);
179                     //Remove first line
180                     array_shift($data);
181                     //Write File
182                     $file = fopen(getcwd() . '/public/documents/' . $filename, 'w');
183                     foreach($data as $d){
184                         $d = str_replace('"','',$d);
185 //                        \Utility\Debug::errorLog('$d', $d);
186                         fputcsv($file, $d, ';');
187                     }
188                     fclose($file);
189
190                     break;
191             }
192
193             #-> Open uploaded csv file.
194             $data = $this->importer = new ImportCsv(
195                 getcwd() . '/public/documents/' . $filename, true, ';'
196             );
197
198                         #-> Handle csv data.
199
200             ini_set('auto_detect_line_endings',TRUE);
201                         while (($data = $this->importer->getRecord(ImportCsv::FETCH_ASSOC)) !== false)
202                         {
203                                 $this->processCsvEntryForPersistenceIfRequired($data,$importType);
204                         }
205 //            ini_set('auto_detect_line_endings',FALSE);
206
207                         #-> Cleanup.
208                         $this->cleanupAfterCsvProcessing();
209                 }
210                 catch (\Exception $e)
211                 {
212                         Debug::errorLog('Bulk Data Import EXCEPTION', $e->getMessage());
213                         Debug::errorLog('Bulk Data Import TRACE', $e->getTraceAsString());
214                 }
215
216         \Utility\Debug::errorLog('$importType', $importType);
217         \Utility\Debug::errorLog('$this->exceptions', $this->exceptions);
218         \Utility\Debug::errorLog('$this->recordCounter', $this->recordCounter);
219         \Utility\Debug::errorLog('$this->successCounter', $this->successCounter);
220         \Utility\Debug::errorLog('$this->failedCounter', $this->failedCounter);
221         /*
222          * send email with exceptions to user
223          */
224         if(!empty($this->exceptions))
225         {
226             $profileEntry = $this->em->getRepository('\\User\\Entity\\Profile')
227                 ->find($this->userId);
228
229 //            \Utility\Debug::errorLog('$profileEntry->email', $profileEntry->email);
230
231             $toCompanyId        = $this->companyId;
232             $toProfileId        = $this->userId;
233             $email                      = $profileEntry->email;
234             $mobile                     = null;
235             $subject            = "Bulk import of $importType system";
236             $templateName       = 'general';
237
238             $params['body'] = '<table border="0" cellspacing="0" cellpadding="0" width="600" style="border-collapse:collapse; border-spacing:0; margin:0; padding:0; width:600px; font-family: Arial, Sans-serif; font-size:12px;">
239                             <tr>
240                                 <td width="100%" valign="top" style="width:100%;">
241                                     Good Day ' . $profileEntry->firstName . ' ' . $profileEntry->familyName . ',
242                                 </td>
243                             </tr>
244                             <tr>
245                                 <td width="100%" valign="top" style="width:100%;">
246                                     &nbsp;
247                                 </td>
248                             </tr>
249                             <tr>
250                                 <td width="100%" valign="top" style="width:100%;">
251                                     The bulk import for ' . $importType . ' is complete
252                                 </td>
253                             </tr>
254                             <tr>
255                                 <td width="100%" valign="top" style="width:100%;">
256                                     &nbsp;
257                                 </td>
258                             </tr>
259                             <tr>
260                                 <td width="100%" valign="top" style="width:100%;">
261                                     Total records processed: ' . $this->recordCounter . '
262                                     <br>
263                                     Number of records successfully imported: ' . $this->successCounter . '
264                                     <br>
265                                     Number of records that could not be imported: ' . $this->successCounter . '
266                                 </td>
267                             </tr>
268                             <tr>
269                                 <td width="100%" valign="top" style="width:100%;">
270                                     &nbsp;
271                                 </td>
272                             </tr>
273                         </table>
274                         <table border="0" cellspacing="0" cellpadding="0" width="800" style="border-collapse:collapse; border-spacing:0; margin:0; padding:0; width:800px; font-family: Arial, Sans-serif; font-size:12px;">';
275
276             foreach($this->exceptions as $exceptions)
277             {
278                 $params['body'] .=  '<tr>
279                                 <td width="180" valign="top" style="width:180px; font-family: Arial, Sans-serif; font-size:12px;">
280                                     <b>MM Code:</b>
281                                 </td>
282                                 </tr>
283                                 <tr>
284                                 <td width="180" valign="top" style="width:180px; font-family: Arial, Sans-serif; font-size:12px;">
285                                     ' . $exceptions['MmCode'] . '
286                                 </td>
287                                 </tr>
288                                 <tr>
289                                 <td width="180" valign="top" style="width:180px;">
290                                     <b>Error(s):</b>
291                                 </td>
292                                  </tr>
293                                 ';
294
295                 if(is_array($exceptions['Error']))
296                 {
297                     foreach($exceptions['Error'] as $errors)
298                     {
299                         foreach($errors as $error)
300                         {
301                             $params['body'] .=  '
302
303                                 <tr><td width="180" valign="top" style="width:180px; font-family: Arial, Sans-serif; font-size:12px;">
304                                     ' . $error . '
305                                 </td> </tr>';
306                         }
307                     }
308                 }
309                 else
310                 {
311                     $params['body'] .=  '<tr><td width="180" valign="top" style="width:180px; font-family: Arial, Sans-serif; font-size:12px;">
312                                     ' . $exceptions['Error'] . '
313                                 </td> </tr>';
314                 }
315
316                 $params['body'] .=  '
317                                 <td width="20" valign="top" style="width:20px;">&nbsp;</td>
318                             </tr>';
319             }
320             $params['body'] .=  '</table>
321                 <table border="0" cellspacing="0" cellpadding="0" width="600" style="border-collapse:collapse; border-spacing:0; margin:0; padding:0; width:600px; font-family: Arial, Sans-serif; font-size:12px;">
322                             <tr>
323                                 <td width="100%" valign="top" style="width:100%;">
324                                     &nbsp;
325                                 </td>
326                             </tr>
327                             <tr>
328                                 <td width="100%" valign="top" style="width:100%;">
329                                     Regards
330                                 </td>
331                             </tr>
332                             <tr>
333                                 <td width="100%" valign="top" style="width:100%;">
334                                     Bid4Cars Team
335                                 </td>
336                             </tr>
337                         </table>
338             ';
339
340             $params['smsBody'] = '';
341
342 //            \Utility\Debug::errorLog('email body', $params['body']);
343
344             $oNotify = new \Utility\Comms\Notification();
345             $oNotify->sendFromTemplate(
346                 null,
347                 null,
348                 $toCompanyId,
349                 $toProfileId,
350                 $email,
351                 $mobile,
352                 $subject,
353                 $templateName,
354                 $params
355             );
356         }
357         }
358
359         /**
360          * @param $filename
361          */
362         protected function prepareForCsvProcessing($filename)
363         {
364                 #-> Establish new synchronization version to use.
365                 $this->store->version = $this->util->getLatestSynchVersion(
366                                 'Stock\\Entity\\Type'
367                         ) + 1;
368
369                 #-> Ensure that synchronization versions have a full sequence.
370                 $this->helper->ensureSynchronizationVersionSequence();
371
372                 #-> Prepare common variables.
373                 $this->previousMmCode = false;
374                 $this->em->beginTransaction();
375         }
376
377         /**
378          * Process a csv line entry.
379          * @param $packet
380          */
381         protected function processCsvEntryForPersistenceIfRequired($packet,$importType)
382         {
383 //        \Utility\Debug::errorLog('$packet', $packet);
384
385         $this->helper->errors = array();
386         $vehicleType = '';
387         $vehicleMmCode = '';
388
389
390                 #-> Ensure null instead of empty string on numeric fields.
391                 $packet = $this->helper->cleanupNumericInputFields($packet);
392
393         switch ($importType)
394         {
395             case 'Pinnacle':
396                 /*
397                  * prepare vehicle year data
398                  */
399                 $vehicleYearArray = explode('/',$packet['Registration Date']);
400                 $vehicleYearArray = explode(' ',$vehicleYearArray[2]);
401
402                 /*
403                  * define variables
404                  */
405                 $stockNumber = $packet['Stock Number'];
406                 $vehicleMmCode = $packet['MM Code'];
407                 $vehicleYear = $vehicleYearArray[0];
408                 $vehicleMake = $packet['Make'];
409                 $vehicleModel = $packet['Model'];
410                 $vehicleType = $packet['Specification'];
411                 $vehicleTransmission = $packet['Transmission'];
412                 $vehicleExteriorColour = $packet['Colour'];
413                 $vehicleInteriorColour = '';
414                 $vehicleUpholstery = $packet['Interior'];
415                 $vehicleCondition = $packet[''];
416                 $vehicleReg = $packet['Registration Number'];
417                 $vehicleVin = $packet['VIN'];
418                 $vehicleMileage = $packet['Odometer'];
419                 $vehicleFuelType = $packet['Fuel Type'];
420                 $vehicleEngineNumber = $packet['Engine Number'];
421                 $empty = $packet[''];
422                 break;
423             case 'Drive':
424
425                 /*
426                  * define variables
427                  */
428                 $stockNumber = $packet['Suffix to Use'];
429                 $vehicleMmCode = $packet['MM Code'];
430                 $vehicleYear = $packet['Model Year'];
431                 $vehicleMake = $packet['Fran'];
432                 $vehicleModel = $packet['Model'];
433                 $vehicleType = $packet['Description'];
434                 $vehicleTransmission = '';
435                 $vehicleExteriorColour = $packet['Colour'];
436                 $vehicleInteriorColour = $packet['Trim'];
437                 $vehicleUpholstery = '';
438                 $vehicleCondition = $packet['Condition'];
439                 $vehicleReg = $packet['Reg'];
440                 $vehicleVin = $packet['VIN'];
441                 $vehicleMileage = $packet['Mileage'];
442                 $vehicleFuelType = '';
443                 $vehicleEngineNumber = $packet['Engine'];
444                 break;
445         }
446
447         if('' == $vehicleType)
448         {
449             return;
450         }
451
452
453         #-> Safety check for year range.
454         if ($vehicleYear < 1970)
455         {
456             return;
457         }
458
459         $this->recordCounter++;
460
461 //        \Utility\Debug::errorLog('$vehicleMmCode', $vehicleMmCode);
462
463         if('' != $vehicleMmCode && 0 != $vehicleMmCode)
464         {
465             $yearId = '';
466             $exteriorColourId = '';
467             $interiorColourId = '';
468             $upholsteryId = '';
469             $conditionId = '';
470             $transmissionId = '';
471             $fuelTypeId = '';
472
473             #-> Get vehicle type ID.
474             $typeId = $this->helper->getVehicleType($vehicleMmCode,$vehicleMake);
475
476
477             if('' != $vehicleYear)
478             {
479                 #-> Get vehicle year ID.
480                 $yearId = $this->helper->getYearEntry($vehicleYear);
481             }
482
483             if('' != $vehicleExteriorColour)
484             {
485                 #-> Get vehicle exterior colour ID.
486                 $exteriorColourId = $this->helper->getExteriorColourEntry($vehicleExteriorColour);
487             }
488
489             if('' != $vehicleInteriorColour)
490             {
491                 #-> Get vehicle interior colour ID.
492                 $interiorColourId = $this->helper->getInteriorColourEntry($vehicleInteriorColour);
493             }
494
495             if('' != $vehicleUpholstery)
496             {
497                 #-> Get vehicle upholstery ID.
498                 $upholsteryId = $this->helper->getUpholsteryEntry($vehicleUpholstery);
499             }
500
501             if('' != $vehicleCondition)
502             {
503                 #-> Get vehicle condition ID.
504                 $conditionId = $this->helper->getConditionEntry($vehicleCondition);
505             }
506
507             if('' != $vehicleTransmission)
508             {
509                 #-> Get vehicle transmission ID.
510                 $transmissionId = $this->helper->getTransmissionEntry($vehicleTransmission);
511             }
512
513             if('' != $vehicleFuelType)
514             {
515                 #-> Get vehicle fuel type ID.
516                 $fuelTypeId = $this->helper->getFuelTypeEntry($vehicleFuelType);
517             }
518
519
520
521             if(!empty($this->helper->errors))
522             {
523                 array_push($this->exceptions,array('MmCode' => $vehicleMmCode,'Error' => $this->helper->errors));
524                 $this->failedCounter++;
525                 return;
526             }
527             else
528             {
529                 $data = \Utility\Comms\TransUnion::searchByMmCode(
530                     $vehicleMmCode,
531                     $vehicleYear
532                 );
533
534                 $retailPrice = 0.0;
535                 $tradePrice  = 0.0;
536                 $listPrice   = 0.0;
537
538                 \Utility\Debug::errorLog('TransUnion $data', $data);
539
540                 if (is_array($data) && isset($data['VehicleDetails'])
541                     && isset($data['VehicleDetails'][0])
542                     && isset($data['VehicleDetails'][0]['Value'])
543                 )
544                 {
545                     $retailPrice = isset($data['VehicleDetails'][0]['Value']['RetailPrice']) ? $data['VehicleDetails'][0]['Value']['RetailPrice'] : 0.0;
546                     $tradePrice  = isset($data['VehicleDetails'][0]['Value']['TradePrice']) ? $data['VehicleDetails'][0]['Value']['TradePrice'] : 0.0;
547                     $listPrice   = isset($data['VehicleDetails'][0]['Value']['NewPrice']) ? $data['VehicleDetails'][0]['Value']['NewPrice'] : 0.0;
548                 }
549
550 //                \Utility\Debug::errorLog('$this->userId', $this->userId);
551 //                \Utility\Debug::errorLog('$this->companyId', $this->companyId);
552 //
553 //                \Utility\Debug::errorLog('$typeId', $typeId);
554 //                \Utility\Debug::errorLog('$categoryId', $categoryId);
555 //                \Utility\Debug::errorLog('$modelId', $modelId);
556 //                \Utility\Debug::errorLog('$makeId', $makeId);
557 //                \Utility\Debug::errorLog('$yearId', $yearId);
558 //                \Utility\Debug::errorLog('$exteriorColourId', $exteriorColourId);
559 //                \Utility\Debug::errorLog('$interiorColourId', $interiorColourId);
560 //                \Utility\Debug::errorLog('$upholsteryId', $upholsteryId);
561 //                \Utility\Debug::errorLog('$conditionId', $conditionId);
562 //                \Utility\Debug::errorLog('$transmissionId', $transmissionId);
563 //                \Utility\Debug::errorLog('$fuelTypeId', $fuelTypeId);
564 //
565 //                \Utility\Debug::errorLog('$retailPrice', $retailPrice);
566 //                \Utility\Debug::errorLog('$tradePrice', $tradePrice);
567                 \Utility\Debug::errorLog('$listPrice', $listPrice);
568 //                \Utility\Debug::errorLog('$stockNumber', $stockNumber);
569 //                \Utility\Debug::errorLog('$vehicleReg', $vehicleReg);
570 //                \Utility\Debug::errorLog('$vehicleVin', $vehicleVin);
571 //                \Utility\Debug::errorLog('$vehicleEngineNumber', $vehicleEngineNumber);
572 //                \Utility\Debug::errorLog('$vehicleMileage', $vehicleMileage);
573
574                 /*
575                  * insert into stock table
576                  */
577                     \Utility\Registry::set('IsBulkImport', true);
578
579                     $stockEntry = $this->em->getRepository('\\Stock\\Entity\\Stock')
580                     ->findOneBy(array(
581                         'stockNumber'           => $stockNumber,
582                         'createdBy'             => $this->em->getRepository('\User\Entity\Profile')->find($this->userId),
583                         'company'                       => $this->em->getRepository('\Company\Entity\Company')->find($this->companyId),
584                         'archived'                      => false
585                     ));
586
587                     if(empty($stockEntry))
588                     {
589                         $stockEntry = new \Stock\Entity\Stock();
590
591                         $stockArray = array(
592                             'stockNumber'               => $stockNumber,
593                             'stockNumber'               => $stockNumber,
594                             'jobState'          => 'Stock',
595                             'tradePriceDate'    => new \DateTime('now'),
596                             'tradePrice'                => $tradePrice,
597                             'retailPrice'               => $retailPrice,
598                             'listPriceDate'     => new \DateTime('now'),
599                             'listPrice'             => $listPrice,
600                             'registrationNumber'=> $vehicleReg,
601                             'vinNumber'                 => $vehicleVin,
602                             'engineNumber'              => $vehicleEngineNumber,
603                             'km'                            => $vehicleMileage,
604                             'archived'                  => false
605                         );
606                         $stockArray['createdBy'] = $this->em->getRepository('\User\Entity\Profile')->find($this->userId);
607                         $stockArray['company'] = $this->em->getRepository('\Company\Entity\Company')->find($this->companyId);
608
609                         if('' != $typeId){$stockArray['type'] = $this->em->getRepository('\Stock\Entity\Type')->find($typeId);}
610 //                      if('' != $categoryId){$stockArray[] = $categoryId;}
611 //                      if('' != $modelId){$stockArray[] = $modelId;}
612 //                      if('' != $makeId){$stockArray[] = $makeId;}
613                         if('' != $yearId){$stockArray['vehicleYear'] = $this->em->getRepository('\Stock\Entity\Year')->find($yearId);}
614                         if('' != $exteriorColourId){$stockArray['exteriorColour'] = $this->em->getRepository('\Stock\Entity\ExteriorColour')->find($exteriorColourId);}
615                         if('' != $interiorColourId){$stockArray['interiorColour'] = $this->em->getRepository('\Stock\Entity\InteriorColour')->find($interiorColourId);}
616                         if('' != $upholsteryId){$stockArray['upholstery'] = $this->em->getRepository('\Stock\Entity\Upholstery')->find($upholsteryId);}
617                         if('' != $conditionId){$stockArray['condition'] = $this->em->getRepository('\Stock\Entity\Condition')->find($conditionId);}
618                         if('' != $transmissionId){$stockArray['transmissionType'] = $this->em->getRepository('\Stock\Entity\TransmissionType')->find($transmissionId);}
619                         if('' != $fuelTypeId){$stockArray['fuelType'] = $this->em->getRepository('\Stock\Entity\FuelType')->find($fuelTypeId);}
620
621                         try{
622
623                             $stockEntry->fromArray($stockArray);
624                             $this->em->persist($stockEntry);
625                             $this->em->flush();
626
627                         }
628                         catch (\Exception $e)
629                         {
630                             $this->failedCounter++;
631                             array_push($this->exceptions,array('MmCode' => $vehicleMmCode,'Error' => 'Could not insert stock entry for MM Code ' . $vehicleMmCode));
632                             return;
633                         }
634                         $this->successCounter++;
635                     }
636                     else
637                     {
638                         $this->failedCounter++;
639                         array_push($this->exceptions,array('MmCode' => $vehicleMmCode,'Error' => 'Could not insert stock entry for MM Code ' . $vehicleMmCode . ' stock number ' . $stockNumber . ' already exists.'));
640                         return;
641                     }
642             }
643         }
644         else
645         {
646             $this->failedCounter++;
647             array_push($this->exceptions,array('MmCode' => $vehicleMmCode,'Error' => 'Could not find MM Code for vehicle ' . $vehicleType));
648             return;
649         }
650
651                 #-> Bump the version?
652                 if ($this->store->numItems >= 200)
653                 {
654                         $this->store->version = $this->helper->processBatch();
655                 }
656         }
657
658         /**
659          */
660         protected function cleanupAfterCsvProcessing()
661         {
662                 $this->em->flush();
663                 $this->em->commit();
664                 $this->importer = null;
665         }
666
667 }