/**
  * The procedural part that gets executes an API call and loops through the
  * results, processing them and saving them to the database table.
  *
  * @return void
  */
 public function processResults($options, $showProgress = true, $showMemory = false)
 {
     $this->_showProgress = $showProgress;
     $this->_showMemory = $showMemory;
     /**
      * Perform the actual API call
      */
     $results = $this->_doApiCall($options);
     //var_dump($results);
     //var_dump($this->_perPage);
     //var_dump($this);
     //var_dump($results->totalPages());
     $this->totalPages = $results->totalPages();
     //var_dump($this->totalPages);
     if ($this->_showMemory) {
         require_once 'Zend/Measure/Binary.php';
         $curMem = memory_get_usage(true);
         $curMem = new Zend_Measure_Binary(memory_get_usage(true), Zend_Measure_Binary::BYTE);
         echo '<h1>Current memory usage after fetching page ' . $options['page'] . ' of ' . $this->totalPages . ': ' . $curMem->convertTo(Zend_Measure_Binary::MEGABYTE) . '</h1>' . PHP_EOL;
     }
     foreach ($results as $result) {
         $this->_setRow($result->id);
         $this->_formatData($result);
         $this->_preSave($result);
         $this->_saveRow($result);
         $this->_postSave($result);
         $this->_rowAction = null;
         $this->_tableRow = null;
     }
     if ($this->_showMemory) {
         $curMem = new Zend_Measure_Binary(memory_get_usage(true), Zend_Measure_Binary::BYTE);
         echo '<h1>Current memory usage after database work of page ' . $options['page'] . ' of ' . $this->totalPages . ': ' . $curMem->convertTo(Zend_Measure_Binary::MEGABYTE) . '</h1>' . PHP_EOL;
     }
     if ($this->_showProgress) {
         echo '<h1>Done with page ' . $options['page'] . '</h1>' . PHP_EOL;
         @ob_end_flush();
         @ob_flush();
         @flush();
     }
 }
 /**
  * Show stats
  *
  * @param array $stats
  * @param OutputInterface $output
  * @return void
  */
 protected function _showStats(&$stats, OutputInterface $output)
 {
     $countBefore = $stats['count']['before'];
     $countAfter = $stats['count']['after'];
     $countPercentage = $stats['count']['percent'];
     $sizeBefore = $stats['size']['before'];
     $sizeAfter = $stats['size']['after'];
     $sizePercentage = $stats['size']['percent'];
     if ($countBefore <= $countAfter) {
         $output->writeln('<info>No files to remove</info> <comment>YOUR MEDIA IS OPTIMIZED AS HELL!</comment>');
         return;
     }
     $measureBefore = new \Zend_Measure_Binary($sizeBefore);
     $measureAfter = new \Zend_Measure_Binary($sizeAfter);
     $formattedBefore = $measureBefore->convertTo(\Zend_Measure_Binary::MEGABYTE);
     $formattedAfter = $measureAfter->convertTo(\Zend_Measure_Binary::MEGABYTE);
     $pad1Length = max(strlen($countBefore), strlen($formattedBefore));
     $pad2Length = max(strlen($countAfter), strlen($formattedAfter));
     $output->writeln('<info>Statistics: (before -> after)</info>');
     $output->writeln(' <comment>files:</comment> ' . str_pad($countBefore, $pad1Length, ' ', STR_PAD_LEFT) . ' -> ' . str_pad($countAfter, $pad2Length, ' ', STR_PAD_LEFT) . ' (' . round($countPercentage * 100, 1) . '%)');
     $output->writeln(' <comment>size:</comment>  ' . str_pad($formattedBefore, $pad1Length, ' ', STR_PAD_LEFT) . ' -> ' . str_pad($formattedAfter, $pad2Length, ' ', STR_PAD_LEFT) . ' (' . round($sizePercentage * 100, 1) . '%)');
     $output->writeln("\n");
 }