public function testFetchRetryMessages()
 {
     $message = self::getTestMessage();
     $this->db->storeMessage($message, 'test_queue', '', '', time() - 1);
     $fetched = $this->db->fetchRetryMessages(10);
     $this->assertNotNull($fetched, 'No record retrieved by fetchRetryMessages.');
     $expected = $message + array('damaged_id' => 1, 'original_queue' => 'test_queue');
     $this->assertEquals($expected, $fetched[0], 'Fetched record does not matches stored message.');
 }
 /**
  * Do the actual work of the script.
  */
 public function execute()
 {
     $this->damagedDatabase = DamagedDatabase::get();
     $messages = $this->damagedDatabase->fetchRetryMessages($this->getOption('max-messages'));
     $stats = array();
     $config = Configuration::getDefaultConfig();
     foreach ($messages as $message) {
         $queueName = $message['original_queue'];
         // FIXME: getting it by alias, this will be annoying cos -new
         $queue = BaseQueueConsumer::getQueue($queueName);
         unset($message['original_queue']);
         $queue->push($message);
         $this->damagedDatabase->deleteMessage($message);
         if (isset($stats[$queueName])) {
             $stats[$queueName]++;
         } else {
             $stats[$queueName] = 1;
         }
     }
     foreach ($stats as $queueName => $count) {
         Logger::info("Requeued {$count} messages to {$queueName}.");
     }
 }