本文整理匯總了PHP中Doctrine\ORM\EntityManager::isOpen方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::isOpen方法的具體用法?PHP EntityManager::isOpen怎麽用?PHP EntityManager::isOpen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::isOpen方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getEntityManager
/**
* Get EntityManager
*
* @return Doctrine\ORM\EntityManager
*/
public function getEntityManager()
{
if ($this->em !== null && $this->em->isOpen()) {
return $this->em;
}
return $this->_configureEntityManager();
}
示例2: onKernelTerminate
/**
* 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...
}
}
示例3: getEntityManager
/**
* 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: getEntityManager
/**
* 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: ensureEntityManagerReady
/**
* 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: executeJob
/**
* @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: write
/**
* 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: setLogTalk
/** 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());
}
}
示例9: executeCommand
/**
* @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: createTranslation
/**
* @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: resetEntityManager
protected function resetEntityManager()
{
if (!$this->entityManager->isOpen()) {
$this->entityManager = $this->entityManager->create($this->entityManager->getConnection(), $this->entityManager->getConfiguration());
}
}
示例12: getEntityManager
/**
* @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: isOpen
/**
* {@inheritDoc}
*
* @static
*/
public static function isOpen()
{
return \Doctrine\ORM\EntityManager::isOpen();
}
示例14: isOpen
/**
* {@inheritdoc}
*/
public function isOpen()
{
return $this->wrapped->isOpen();
}