public function testGetController()
 {
     $logger = new Logger();
     $resolver = new ControllerResolver($logger);
     $request = Request::create('/');
     $this->assertFalse($resolver->getController($request), '->getController() returns false when the request has no _controller attribute');
     $this->assertEquals(array('Unable to look for the controller as the "_controller" parameter is missing'), $logger->getLogs('warning'));
     $request->attributes->set('_controller', 'Symfony\\Component\\HttpKernel\\Tests\\ControllerResolverTest::testGetController');
     $controller = $resolver->getController($request);
     $this->assertInstanceOf('Symfony\\Component\\HttpKernel\\Tests\\ControllerResolverTest', $controller[0], '->getController() returns a PHP callable');
     $request->attributes->set('_controller', $lambda = function () {
     });
     $controller = $resolver->getController($request);
     $this->assertSame($lambda, $controller);
     $request->attributes->set('_controller', $this);
     $controller = $resolver->getController($request);
     $this->assertSame($this, $controller);
     $request->attributes->set('_controller', 'Symfony\\Component\\HttpKernel\\Tests\\ControllerResolverTest');
     $controller = $resolver->getController($request);
     $this->assertInstanceOf('Symfony\\Component\\HttpKernel\\Tests\\ControllerResolverTest', $controller);
     $request->attributes->set('_controller', array($this, 'controllerMethod1'));
     $controller = $resolver->getController($request);
     $this->assertSame(array($this, 'controllerMethod1'), $controller);
     $request->attributes->set('_controller', array('Symfony\\Component\\HttpKernel\\Tests\\ControllerResolverTest', 'controllerMethod4'));
     $controller = $resolver->getController($request);
     $this->assertSame(array('Symfony\\Component\\HttpKernel\\Tests\\ControllerResolverTest', 'controllerMethod4'), $controller);
     $request->attributes->set('_controller', 'Symfony\\Component\\HttpKernel\\Tests\\some_controller_function');
     $controller = $resolver->getController($request);
     $this->assertSame('Symfony\\Component\\HttpKernel\\Tests\\some_controller_function', $controller);
     $request->attributes->set('_controller', 'foo');
     try {
         $resolver->getController($request);
         $this->fail('->getController() throws an \\InvalidArgumentException if the _controller attribute is not well-formatted');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getController() throws an \\InvalidArgumentException if the _controller attribute is not well-formatted');
     }
     $request->attributes->set('_controller', 'foo::bar');
     try {
         $resolver->getController($request);
         $this->fail('->getController() throws an \\InvalidArgumentException if the _controller attribute contains a non-existent class');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getController() throws an \\InvalidArgumentException if the _controller attribute contains a non-existent class');
     }
     $request->attributes->set('_controller', 'Symfony\\Component\\HttpKernel\\Tests\\ControllerResolverTest::bar');
     try {
         $resolver->getController($request);
         $this->fail('->getController() throws an \\InvalidArgumentException if the _controller attribute contains a non-existent method');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getController() throws an \\InvalidArgumentException if the _controller attribute contains a non-existent method');
     }
 }
 /**
  * Execute the runall command, which executes all the commands.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $days = $this->getContainer()->getParameter('days_silent');
     $journals = $em->getRepository('AppBundle:Journal')->findSilent($days);
     $count = count($journals);
     $this->logger->notice("Found {$count} silent journals.");
     if (count($journals) === 0) {
         return;
     }
     $users = $em->getRepository('AppUserBundle:User')->findUserToNotify();
     if (count($users) === 0) {
         $this->logger->error('No users to notify.');
         return;
     }
     $this->sendNotifications($days, $users, $journals);
     foreach ($journals as $journal) {
         if ($this->pingJournal($journal)) {
             $this->logger->notice("Ping Success {$journal->getUrl()})");
             $journal->setStatus('healthy');
             $journal->setContacted(new DateTime());
         } else {
             $journal->setStatus('unhealthy');
             $journal->setNotified(new DateTime());
         }
     }
     if (!$input->getOption('dry-run')) {
         $em->flush();
     }
 }
示例#3
0
 /**
  * get a unique filename in path.
  *
  * @param $folder
  * @param $fileName
  * @param int $counter
  *
  * @return string
  */
 private function getUniqueFileName($folder, $fileName, $counter = 0)
 {
     $newFileName = $fileName;
     if ($counter > 0) {
         $fileNameParts = explode('.', $fileName, 2);
         $newFileName = $fileNameParts[0] . '-' . $counter . '.' . $fileNameParts[1];
     }
     $filePath = $this->getPathByFolderAndFileName($folder, $newFileName);
     $this->logger->debug('Check FilePath: ' . $filePath);
     if (!$this->filesystem->exists($filePath)) {
         return $newFileName;
     }
     ++$counter;
     return $this->getUniqueFileName($folder, $fileName, $counter);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var DepositRepository $repo */
     $repo = $this->em->getRepository('AppBundle:Deposit');
     $deposits = $repo->findAll();
     foreach ($deposits as $deposit) {
         $this->logger->notice("{$deposit->getDepositUuid()}");
         $checksum = strtoupper($this->getChecksum($deposit));
         if ($checksum !== $deposit->getChecksumValue()) {
             $this->logger->warning("Updating checksum for {$deposit->getDepositUuid()}");
             $deposit->setChecksumValue($checksum);
         }
     }
     if (!$input->getOption('dry-run')) {
         $this->em->flush();
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $state = $input->getArgument('state');
     $uuids = $input->getArgument('deposit');
     $deposits = $this->getDeposits($uuids);
     foreach ($deposits as $deposit) {
         $this->logger->notice("Setting {$deposit->getDepositUuid()} to {$state}");
         $deposit->setState($state);
         if ($input->getOption('clear')) {
             $deposit->setErrorLog(array());
             $deposit->setPackageSize(null);
             $deposit->setPlnState(null);
             $deposit->setProcessingLog('');
             $deposit->addToProcessingLog('Deposit reset.');
             $deposit->setAuContainer(null);
         }
     }
     $this->em->flush();
 }
 /**
  * Execute the runall command, which executes all the commands.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $days = $this->getContainer()->getParameter('days_reminder');
     $journals = $em->getRepository('AppBundle:Journal')->findOverdue($days);
     $count = count($journals);
     $this->logger->notice("Found {$count} overdue journals.");
     if (count($journals) === 0) {
         return;
     }
     $users = $em->getRepository('AppUserBundle:User')->findUserToNotify();
     if (count($users) === 0) {
         $this->logger->error('No users to notify.');
         return;
     }
     $this->sendReminders($days, $users, $journals);
     foreach ($journals as $journal) {
         $journal->setNotified(new DateTime());
     }
     if (!$input->getOption('dry-run')) {
         $em->flush();
     }
 }
 /**
  * Execute the runall command, which executes all the commands.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $router = $this->getContainer()->get('router');
     $bwlist = $this->getContainer()->get('blackwhitelist');
     $ping = $this->getContainer()->get('ping');
     $ping->setLogger($this->logger);
     /*
      * @var Journal[]
      */
     $journals = $em->getRepository('AppBundle:Journal')->findAll();
     $minVersion = $input->getArgument('minVersion');
     if (!$minVersion) {
         $minVersion = $this->getContainer()->getParameter('min_ojs_version');
     }
     $all = $input->getOption('all');
     $count = count($journals);
     $i = 0;
     foreach ($journals as $journal) {
         ++$i;
         $fmt = sprintf('%5d', $i);
         $url = $router->generate('journal_show', array('id' => $journal->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
         $uuid = $journal->getUuid();
         if (!$all && $journal->getStatus() === 'ping-error') {
             $this->logger->notice("{$fmt}/{$count} - skipped (previous ping-error) - - {$journal->getUrl()}");
             continue;
         }
         if (!$all && $bwlist->isWhitelisted($uuid)) {
             $this->logger->notice("{$fmt}/{$count} - skipped (whitelisted) - - {$journal->getUrl()}");
             continue;
         }
         if (!$all && $bwlist->isBlacklisted($uuid)) {
             $this->logger->notice("{$fmt}/{$count} - skipped (blacklisted) - - {$journal->getUrl()}");
             continue;
         }
         try {
             $response = $ping->ping($journal);
         } catch (Exception $e) {
             $this->logger->error("Ping - HTTP ERROR: {$e->getMessage()} - {$journal->getUrl()} - {$url}");
             $journal->setStatus('ping-error');
             $em->flush($journal);
             continue;
         }
         if ($response->getHttpStatus() !== 200) {
             $this->logger->error("Ping - HTTP {$response->getHttpStatus()} - - {$journal->getUrl()} - {$url} - {$response->getError()}");
             $journal->setStatus('ping-error');
             $em->flush($journal);
             continue;
         }
         if (!$response->getOjsRelease()) {
             $this->logger->warning("Ping - HTTP {$response->getHttpStatus()} - no version number found - {$journal->getUrl()} - {$url}");
             $journal->setStatus('ping-error');
             $em->flush($journal);
             continue;
         }
         $this->logger->notice("Ping - {$response->getHttpStatus()} - {$response->getOjsRelease()} - {$journal->getUrl()} - {$url}");
         if (version_compare($response->getOjsRelease(), $minVersion, '<')) {
             continue;
         }
         if ($input->getOption('dry-run')) {
             continue;
         }
         if ($bwlist->isWhitelisted($uuid) || $bwlist->isBlacklisted($uuid)) {
             continue;
         }
         $whitelist = new Whitelist();
         $whitelist->setUuid($journal->getUuid());
         $whitelist->setComment("{$journal->getUrl()} added automatically by ping-whitelist command.");
         $em->persist($whitelist);
         $em->flush();
     }
 }