public function testSync() { $syncProvider = $this->getMock('Oro\\Bundle\\CacheBundle\\Provider\\SyncCacheInterface'); $notSyncProvider = $this->getMock('Oro\\Bundle\\CacheBundle\\Provider\\SyncCacheInterface'); $syncProvider->expects($this->once())->method('sync'); $manager = new OroDataCacheManager(); $manager->registerCacheProvider($syncProvider); $manager->registerCacheProvider($notSyncProvider); $manager->sync(); }
/** * Launches a command as a separate process. * * The '--process-timeout' parameter can be used to set the process timeout * in seconds. Default timeout is 300 seconds. * If '--ignore-errors' parameter is specified any errors are ignored; * otherwise, an exception is raises if an error happened. * If '--disable-cache-sync' parameter is specified a synchronization of caches between current * process and its child processes are disabled. * * @param string $command * @param array $params * @param LoggerInterface|null $logger * * @return integer The exit status code * * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function runCommand($command, $params = [], LoggerInterface $logger = null) { $params = array_merge(['command' => $command], $params); if ($this->env && $this->env !== 'dev') { $params['--env'] = $this->env; } $ignoreErrors = false; if (array_key_exists('--ignore-errors', $params)) { $ignoreErrors = true; unset($params['--ignore-errors']); } $pb = new ProcessBuilder(); $pb->add($this->getPhp())->add($this->consoleCmdPath); if (array_key_exists('--process-timeout', $params)) { $pb->setTimeout($params['--process-timeout']); unset($params['--process-timeout']); } else { $pb->setTimeout($this->defaultTimeout); } $disableCacheSync = false; if (array_key_exists('--disable-cache-sync', $params)) { $disableCacheSync = $params['--disable-cache-sync']; unset($params['--disable-cache-sync']); } foreach ($params as $name => $val) { $this->processParameter($pb, $name, $val); } $process = $pb->inheritEnvironmentVariables(true)->getProcess(); if (!$logger) { $logger = new NullLogger(); } $exitCode = $process->run(function ($type, $data) use($logger) { if ($type === Process::ERR) { $logger->error($data); } else { $logger->notice($data); } }); // synchronize all data caches if ($this->dataCacheManager && !$disableCacheSync) { $this->dataCacheManager->sync(); } $this->processResult($exitCode, $ignoreErrors, $logger); return $exitCode; }
/** * Launches a command. * If '--process-isolation' parameter is specified the command will be launched as a separate process. * In this case you can parameter '--process-timeout' to set the process timeout * in seconds. Default timeout is 300 seconds. * If '--ignore-errors' parameter is specified any errors are ignored; * otherwise, an exception is raises if an error happened. * * @param string $command * @param array $params * @return CommandExecutor * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified */ public function runCommand($command, $params = []) { $params = array_merge(['command' => $command], $params); if ($this->env && $this->env !== 'dev') { $params['--env'] = $this->env; } $ignoreErrors = false; if (array_key_exists('--ignore-errors', $params)) { $ignoreErrors = true; unset($params['--ignore-errors']); } if (array_key_exists('--process-isolation', $params)) { unset($params['--process-isolation']); $pb = new ProcessBuilder(); $pb->add($this->getPhp())->add($_SERVER['argv'][0]); if (array_key_exists('--process-timeout', $params)) { $pb->setTimeout($params['--process-timeout']); unset($params['--process-timeout']); } else { $pb->setTimeout($this->defaultTimeout); } foreach ($params as $name => $val) { $this->processParameter($pb, $name, $val); } $process = $pb->inheritEnvironmentVariables(true)->getProcess(); $output = $this->output; $process->run(function ($type, $data) use($output) { $output->write($data); }); $this->lastCommandExitCode = $process->getExitCode(); // synchronize all data caches if ($this->dataCacheManager) { $this->dataCacheManager->sync(); } } else { $this->application->setAutoExit(false); $this->lastCommandExitCode = $this->application->run(new ArrayInput($params), $this->output); } $this->processResult($ignoreErrors); return $this; }