コード例 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $startTime = microtime(true);
     $config = $input->getOption('config');
     $configuration = $config ? Configuration::fromFile($config) : Configuration::defaults();
     $parser = new PhpCmsVersionChecker\Parser\Parser();
     $storage = PhpCmsVersionChecker\Storage::getConnection($configuration->get("DB"));
     $alert = PhpCmsVersionChecker\Alert::getInstance($configuration->get("Mailer"));
     foreach ($configuration->get("CMS") as $cms => $cms_options) {
         // get version number from the website
         $version_id = $parser->parse($cms, $cms_options);
         // get version number stored in local storage
         $stored_version = $storage->getVersion($cms);
         // if the two versions are different send out a mail and store the new value in the db
         if ($version_id != false && $version_id != $stored_version) {
             $storage->putVersion($cms, $version_id);
             try {
                 // send out notification about the version change
                 $alert->send($cms, $version_id, $cms_options['url']);
             } catch (Swift_TransportException $e) {
                 $output->writeln("Mail notification was not sent. " . $e->getMessage());
             }
         }
         $output->writeln("{$cms} Version: " . $version_id . ' -> ' . $stored_version);
     }
     $duration = microtime(true) - $startTime;
     $output->writeln('');
     $output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB');
 }
コード例 #2
0
 /**
  * Check default value works
  * @covers Cpeter\PhpCmsVersionChecker\Configuration\Configuration::get
  */
 public function testGet()
 {
     $configuration = Configuration::defaults();
     $config = $configuration->get('invalid', 'default');
     $this->assertTrue($config == 'default');
 }