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); } }
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)); } }
<?php $path = dirname(__FILE__); require_once realpath($path . '/../vendor/autoload.php'); $worker = new \MySQLExtractor\Application(); //$mysqlCredentials = new stdClass(); //$mysqlCredentials->host = '127.0.0.1'; //$mysqlCredentials->dbuser = '******'; //$mysqlCredentials->dbpass = '******'; //$mysqlCredentials->dbname = 'redmine'; // //$worker->processServer($mysqlCredentials); // // or: $worker->processDisk($path . '/test_sql/', 'project_mooc'); // folder containing .sql files (format: dbname.sql) $worker->output($path . '/output/', $worker->getDatabases()); // will output .json files for each database echo "Finished. Check the output folder.\n\n" . implode("\n", $worker->statistics()) . "\n\n";