Пример #1
0
 /**
  * Get EntityManager
  *
  * @return Doctrine\ORM\EntityManager
  */
 public function getEntityManager()
 {
     if ($this->em !== null && $this->em->isOpen()) {
         return $this->em;
     }
     return $this->_configureEntityManager();
 }
 /**
  * Flush on kernel terminate.
  */
 public function onKernelTerminate()
 {
     if ($this->em->isOpen()) {
         $this->em->flush();
         // That was not so hard... And you need a bundle to do that! Poor guy...
     }
 }
 /**
  * Because the EntityManager gets closed when there's an error, it needs to
  * be created again
  *
  * @return EntityManager
  * @throws ORMException
  */
 protected function getEntityManager()
 {
     if (!$this->em) {
         $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
     }
     if (!$this->em->isOpen()) {
         $this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration());
     }
     return $this->em;
 }
Пример #4
0
 /**
  * Getter for entityManager
  *
  * @return EntityManager
  */
 public static function getEntityManager()
 {
     #if(null === self::$_entityManager) {
     #  self::$_entityManager = \Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('entityManager');
     #}
     // Check if entitymanager has been closed (most likely due to a previously thrown PDOException)
     if (!self::$_entityManager->isOpen()) {
         // Entitymanger has closed, create a new one
         $connection = self::$_entityManager->getConnection();
         $config = self::$_entityManager->getConfiguration();
         self::$_entityManager = EntityManager::create($connection, $config);
     }
     return self::$_entityManager;
 }
Пример #5
0
 /**
  * Prepares EntityManager, reset it if closed with error
  */
 protected function ensureEntityManagerReady()
 {
     $this->em = $this->registry->getManager();
     if (!$this->em->isOpen()) {
         $this->registry->resetManager();
         $this->ensureEntityManagerReady();
     }
 }
Пример #6
0
 /**
  * @param string $jobType
  * @param string $jobName
  * @param array $configuration
  * @return JobResult
  */
 public function executeJob($jobType, $jobName, array $configuration = array())
 {
     // create and persist job instance and job execution
     $jobInstance = new JobInstance(self::CONNECTOR_NAME, $jobType, $jobName);
     $jobInstance->setCode($this->generateJobCode($jobName));
     $jobInstance->setLabel(sprintf('%s.%s', $jobType, $jobName));
     $jobInstance->setRawConfiguration($configuration);
     $jobExecution = new JobExecution();
     $jobExecution->setJobInstance($jobInstance);
     // persist batch entities
     $this->batchJobManager->persist($jobInstance);
     $this->batchJobManager->persist($jobExecution);
     // do job
     $jobResult = $this->doJob($jobInstance, $jobExecution);
     // EntityManager can be closed when there was an exception in flush method called inside some jobs execution
     // Can't be implemented right now due to OroEntityManager external dependencies
     // on ExtendManager and FilterCollection
     if (!$this->entityManager->isOpen()) {
         $this->managerRegistry->resetManager();
         $this->entityManager = $this->managerRegistry->getManager();
     }
     // flush batch entities
     $this->batchJobManager->flush($jobInstance);
     $this->batchJobManager->flush($jobExecution);
     // set data to JobResult
     $jobResult->setJobId($jobInstance->getId());
     $jobResult->setJobCode($jobInstance->getCode());
     // TODO: Find a way to work with multiple amount of job and step executions
     // TODO: https://magecore.atlassian.net/browse/BAP-2600
     /** @var JobExecution $jobExecution */
     $jobExecution = $jobInstance->getJobExecutions()->first();
     if ($jobExecution) {
         $stepExecution = $jobExecution->getStepExecutions()->first();
         if ($stepExecution) {
             $context = $this->contextRegistry->getByStepExecution($stepExecution);
             $jobResult->setContext($context);
         }
     }
     return $jobResult;
 }
Пример #7
0
 /**
  * Writes the record down to the log of the implementing handler
  *
  * @param  array $record
  *
  * @return void
  */
 protected function write(array $record)
 {
     $this->record = $record;
     $error = new Error();
     $error->setMessage($this->getFromRecord('message'));
     $error->setFile($this->getFile());
     $error->setLine($this->getLine());
     $error->setTrace($this->getTrace());
     $error->setType($this->getType());
     $error->setCode($this->getCode());
     $error->setUri($this->getFromRecordExtra('uri'));
     $error->setRoute($this->getFromRecordExtra('route'));
     $error->setController($this->getFromRecordExtra('controller'));
     $error->setUserAgent($this->getFromRecordExtra('userAgent'));
     $error->setUserContext($this->getFromRecordExtra('userContext'));
     $error->setUser($this->getFromRecordExtra('user'));
     if (!$this->entityManager->isOpen()) {
         $this->entityManager = $this->entityManager->create($this->entityManager->getConnection(), $this->entityManager->getConfiguration());
     }
     $this->entityManager->persist($error);
     $this->entityManager->flush($error);
     $this->lastError->setId($error->getId());
 }
Пример #8
0
 /** CREATE LOGS **/
 public function setLogTalk($ação, $erro)
 {
     if (!$this->entityManager->isOpen()) {
         $this->entityManager = $this->entityManager->create($this->entityManager->getConnection(), $this->entityManager->getConfiguration());
     }
     $log = new Logs();
     $log->setDataLogs(new \DateTime('now'));
     $log->setDescricaoLogs($erro);
     $log->setDescricaoAcaoLogs($ação);
     try {
         $this->entityManager->persist($log);
         $this->entityManager->flush();
     } catch (\Exception $e) {
         throw new \Exception("Não foi possível guardar as mensagens recebidas:" . $e->getMessage());
     }
 }
 /**
  * @param ScheduledCommand $scheduledCommand
  * @param OutputInterface $output
  * @param InputInterface $input
  */
 private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterface $output, InputInterface $input)
 {
     $scheduledCommand = $this->em->merge($scheduledCommand);
     $scheduledCommand->setLastExecution(new \DateTime());
     $scheduledCommand->setLocked(true);
     $this->em->flush();
     try {
         $command = $this->getApplication()->find($scheduledCommand->getCommand());
     } catch (\InvalidArgumentException $e) {
         $scheduledCommand->setLastReturnCode(-1);
         $output->writeln('<error>Cannot find ' . $scheduledCommand->getCommand() . '</error>');
         return;
     }
     $input = new ArrayInput(array_merge(array('command' => $scheduledCommand->getCommand(), '--env' => $input->getOption('env')), $scheduledCommand->getArguments(true)));
     // Use a StreamOutput or NullOutput to redirect write() and writeln() in a log file
     if (false === $this->logPath && "" != $scheduledCommand->getLogFile()) {
         $logOutput = new NullOutput();
     } else {
         $logOutput = new StreamOutput(fopen($this->logPath . $scheduledCommand->getLogFile(), 'a', false), $this->commandsVerbosity);
     }
     // Execute command and get return code
     try {
         $output->writeln('<info>Execute</info> : <comment>' . $scheduledCommand->getCommand() . ' ' . $scheduledCommand->getArguments() . '</comment>');
         $result = $command->run($input, $logOutput);
     } catch (\Exception $e) {
         $logOutput->writeln($e->getMessage());
         $logOutput->writeln($e->getTraceAsString());
         $result = -1;
     }
     if (false === $this->em->isOpen()) {
         $output->writeln('<comment>Entity manager closed by the last command.</comment>');
         $this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration());
     }
     $scheduledCommand = $this->em->merge($scheduledCommand);
     $scheduledCommand->setLastReturnCode($result);
     $scheduledCommand->setLocked(false);
     $scheduledCommand->setExecuteImmediately(false);
     $this->em->flush();
     /*
      * This clear() is necessary to avoid conflict between commands and to be sure that none entity are managed
      * before entering in a new command
      */
     $this->em->clear();
     unset($command);
     gc_collect_cycles();
 }
Пример #10
0
 /**
  * @author Krzysztof Bednarczyk
  * @param Language $language
  * @param string $token
  * @param string $domain
  * @return bool
  */
 public function createTranslation(Language $language, $token, $domain)
 {
     try {
         if (!$this->em->isOpen()) {
             $this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration());
         }
         $language = $this->em->getRepository("BordeuxLanguageBundle:Language")->find($language->getId());
         $translation = new LanguageTranslation();
         $translation->setLanguage($language->getAlias() ?: $language);
         $translation->setTranslation($token);
         $translation->setLanguageToken($this->getToken($token));
         $translation->setDomain($domain);
         $this->em->persist($translation);
         $this->em->flush([$translation]);
     } catch (\Exception $e) {
         return false;
     }
     return true;
 }
Пример #11
0
 protected function resetEntityManager()
 {
     if (!$this->entityManager->isOpen()) {
         $this->entityManager = $this->entityManager->create($this->entityManager->getConnection(), $this->entityManager->getConfiguration());
     }
 }
Пример #12
0
 /**
  * @param EntityManager $em
  * @return EntityManager
  * @throws \Doctrine\ORM\ORMException
  */
 public static function getEntityManager(EntityManager $em)
 {
     if (!$em->isOpen()) {
         $em = $em->create($em->getConnection(), $em->getConfiguration());
     }
     return $em;
 }
Пример #13
0
 /**
  * {@inheritDoc}
  *
  * @static 
  */
 public static function isOpen()
 {
     return \Doctrine\ORM\EntityManager::isOpen();
 }
 /**
  * {@inheritdoc}
  */
 public function isOpen()
 {
     return $this->wrapped->isOpen();
 }