/**
  * Check if we have already processed the daily journal for today
  * If not login to the qkeylm site and download the journal
  * Download all images
  * Send out the notification email with the images as attachement
  * Mark journal as processed
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $startTime = microtime(true);
     $config = $input->getOption('config');
     $configuration = $config ? Configuration::fromFile($config) : Configuration::defaults();
     $qkeylm = new PhpQkeylmEmailNotification\Qkeylm\QkeylmApi($configuration->get("QKEYLM"));
     $storage = PhpQkeylmEmailNotification\Storage::getConnection($configuration->get("DB"));
     $alert = PhpQkeylmEmailNotification\Alert::getInstance($configuration->get("Mailer"));
     $dropbox_enabled = !empty((string) $input->getOption('dropbox'));
     if ($dropbox_enabled) {
         $dropbox = PhpQkeylmEmailNotification\Dropbox\Dropbox::getInstance($configuration->get("Dropbox"));
     }
     date_default_timezone_set($configuration->get("TimeZone", "Australia/Sydney"));
     $date = date("Y-m-d");
     if ($input->getOption('date')) {
         $date = $input->getOption('date');
     }
     $force = !empty($input->getOption('force')) ? true : false;
     // check if current date was already processed
     $date_already_processed = $storage->checkEntry($date);
     if (!$force && $date_already_processed) {
         // already processed
         $output->writeln('Page was already processed today. Giving up now.');
     }
     if ($force || !$date_already_processed) {
         $journal = $qkeylm->getDailyJournal($date);
         // send notification and save processed status only if the returned journal is for today
         if ($journal['date'] == $date) {
             $storage->setLatestEntry($date);
             $output->writeln('Sending the notification.');
             try {
                 // send out notification about the version change
                 $alert->send($journal);
             } catch (Swift_TransportException $e) {
                 $output->writeln("Mail notification was not sent. " . $e->getMessage());
             }
             if ($dropbox_enabled) {
                 // upload the images to dropbox
                 try {
                     $output->writeln('Uploading files to Dropbox.');
                     $dropbox->uploadImages($journal);
                 } catch (Exception $e) {
                     $output->writeln("Dropbox upload failed. " . $e->getMessage());
                 }
             }
         } else {
             $output->writeln('No entry for today at this time.');
         }
     }
     $duration = microtime(true) - $startTime;
     $output->writeln('');
     $output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB');
 }
 /**
  * Check default value works
  * @covers Cpeter\PhpQkeylmEmailNotification\Configuration\Configuration::get
  */
 public function testGet()
 {
     $configuration = Configuration::defaults();
     $config = $configuration->get('invalid', 'default');
     $this->assertTrue($config == 'default');
 }