/** * @param ImportScheduleLog $schedule * @throws \CronBundle\Import\Exception */ protected function runOneUserImports(ImportScheduleLog $schedule) { $schedule->setIsLock(1); $this->globalEntityManager->persist($schedule); $this->globalEntityManager->flush(); $this->importLog->resetUserLogData(); $this->importLog->addMessage('user selected => ' . $schedule->getUserId()); //TODO Biztosítani kell, hogy az adott user adatbázis kapcsolata legyen behúzva //Ezt most configból veszi $this->userEntityManager = $this->getDoctrine()->getManager('customer' . $schedule->getUserId()); $this->userEntityManager->clear(); $this->settingService = $this->get('setting'); $this->settingService->setEntityManager($this->userEntityManager); $this->AnalyticsService = $this->get('AnalyticsService'); $this->importListFactoryService = $this->get('ImportListFactory'); $importIndex = $schedule->getActualImportIndex(); $importList = $this->importListFactoryService->getImportList(); $importList->setImporterClassNameSpace($this->getParameter('importerClassNameSpace')); $importList->setImporterComponentFactoryNameSpace($this->getParameter('importerComponentFactoryNameSpace')); $iterator = new ImporterIterator($importList); $iterator->setActualImportIndex($importIndex); while ($iterator->hasImport()) { if (!$this->isInTimeLimit()) { $this->importLog->addMessage('reached user time limit => ' . $schedule->getUserId()); break; } if (!$this->isInUserFailLimit($schedule)) { $this->importLog->addMessage('reached user ERROR limit => ' . $schedule->getUserId()); //TODO e-mail küldés break; } $this->importLog->addMessage('import selected => ' . $importIndex); $importer = $iterator->getActualImport(); $importer->setSettingService($this->settingService); $importer->setAnalyticsService($this->AnalyticsService); $importer->setEntityManager($this->userEntityManager); $importer->setImportLog($this->importLog); $importer->setRuntimeWatcher($this->runtimeWatcher); $this->importLog->addMessage('import run => ' . $importIndex); $importer->init(); $importer->import(); if ($importer->getError()) { $this->importLog->addMessage('import ERROR in run => ' . $importIndex); $importIndex = $iterator->getActualImportIndex(); $schedule->setActualImportIndex($importIndex); $schedule->setUpdateDate(); $failedCounter = $schedule->getFailedCounter() + 1; $schedule->setFailedCounter($failedCounter); $this->failedCounter++; continue; } $this->importLog->addMessage('import success run => ' . $importIndex . ' | ' . $this->importLog->getAllProcessItemCount()); if (!$importer->isFinishedImport()) { $iterator->setActualImportIndex($importIndex); $this->importLog->addMessage('import NOT finished => ' . $importIndex); continue; } $this->importLog->addMessage('import finished => ' . $importIndex); $iterator->setNextImportIndex(); $importIndex = $iterator->getActualImportIndex(); $schedule->setActualImportIndex($importIndex); $schedule->setUpdateDate(); if (!$iterator->hasImport()) { $schedule->setActualImportIndex(1); $schedule->setLastFinishedImportDate(new \DateTime()); $schedule->setPriority(0); $this->importLog->addMessage('all import finished => ' . $schedule->getUserId()); continue; } $this->importLog->addMessage('all import NOT finished => ' . $schedule->getUserId()); $this->globalEntityManager->flush(); } $schedule->setIsLock(0); $this->globalEntityManager->persist($schedule); $this->globalEntityManager->flush(); }