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); } }
<?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";