protected function execute(InputInterface $input, OutputInterface $output)
 {
     $notFound = false;
     $source = $input->getArgument('source');
     $outputPath = $input->getArgument('output');
     $worker = new \MySQLExtractor\Application();
     $scanPathname = realpath($source);
     preg_match('/(.*):(.*)@(.*)\\/(.*)/', $source, $serverDetails);
     if (is_array($serverDetails) && count($serverDetails) === 5) {
         $mysqlCredentials = new \stdClass();
         $mysqlCredentials->dbuser = $serverDetails[1];
         $mysqlCredentials->dbpass = $serverDetails[2];
         $mysqlCredentials->host = $serverDetails[3];
         $mysqlCredentials->dbname = $serverDetails[4];
         $worker->processServer($mysqlCredentials);
     } else {
         if ($scanPathname) {
             $worker->processDisk($scanPathname);
         } else {
             // error, path not found
             $notFound = true;
         }
     }
     if ($notFound) {
         $output->write('Error: invalid source format, check if the source path exists and the format is valid.');
     } else {
         $worker->output($outputPath, $results = $worker->getDatabases());
         // will output .json files for each database
         $output->write('Finished. Check the output folder.' . PHP_EOL . implode(PHP_EOL, $worker->statistics()) . PHP_EOL);
     }
 }
 /**
  * calling from application will trigger execution
  */
 public function testCallingFromApplicationWillTriggerExecution()
 {
     $application = new \MySQLExtractor\Application();
     $application->processServer($this->mysqlCredentials);
     $helper = new \PHPUnitProtectedHelper($application);
     $extractor = $helper->getValue('extractor');
     $databases = $extractor->databases();
     $this->assertEquals(1, count($databases));
     // will filter based on the mysqlCredentials->dbname
     $this->assertInstanceOf('\\MySQLExtractor\\Presentation\\Database', $databases['database1']);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $notFound = false;
     $source = $input->getArgument('source');
     $destination = $input->getArgument('destination');
     $worker1 = new \MySQLExtractor\Application();
     $worker2 = new \MySQLExtractor\Application();
     preg_match('/(.*):(.*)@(.*)\\/(.*)/', $source, $serverSourceDetails);
     preg_match('/(.*):(.*)@(.*)\\/(.*)/', $destination, $serverDestinationDetails);
     if (is_array($serverSourceDetails) && count($serverSourceDetails) === 5) {
         $mysqlCredentials = new \stdClass();
         $mysqlCredentials->dbuser = $serverSourceDetails[1];
         $mysqlCredentials->dbpass = $serverSourceDetails[2];
         $mysqlCredentials->host = $serverSourceDetails[3];
         $mysqlCredentials->dbname = $serverSourceDetails[4];
         $worker1->processServer($mysqlCredentials);
     } else {
         // error, path not found
         $notFound = true;
     }
     if (is_array($serverDestinationDetails) && count($serverDestinationDetails) === 5) {
         $mysqlCredentials = new \stdClass();
         $mysqlCredentials->dbuser = $serverDestinationDetails[1];
         $mysqlCredentials->dbpass = $serverDestinationDetails[2];
         $mysqlCredentials->host = $serverDestinationDetails[3];
         $mysqlCredentials->dbname = $serverDestinationDetails[4];
         $worker2->processServer($mysqlCredentials);
     } else {
         // error, path not found
         $notFound = true;
     }
     if ($notFound) {
         $output->write('Error: invalid source format, check if the source path exists and the format is valid.');
     } else {
         $sourceDBs = json_decode(json_encode($worker1->getDatabases()), true);
         $destinationDBs = json_decode(json_encode($worker2->getDatabases()), true);
         $sourceDatabase = end($sourceDBs);
         $destinationDatabase = end($destinationDBs);
         $databaseDiffs = SnapshotCompareCommand::appendDifferencesDatabases($sourceDatabase, $destinationDatabase);
         $output->writeln('Done. ' . PHP_EOL . print_r(json_encode($databaseDiffs, JSON_PRETTY_PRINT), 2));
     }
 }