protected function installSampleData(InputInterface $input, OutputInterface $output)
{
$magentoPackage = $this->config['magentoPackage'];
/* @var $magentoPackage \Composer\Package\MemoryPackage */
$extra = $magentoPackage->getExtra();
if (!isset($extra['sample-data'])) {
return;
}
$dialog = $this->getHelper('dialog');
$installSampleData = $input->getOption('installSampleData') !== null ? $this->_parseBoolOption($input->getOption('installSampleData')) : $dialog->askConfirmation($output, '<question>Install sample data?</question> <comment>[y]</comment>: ');
if ($installSampleData) {
$filesystem = new Filesystem();
foreach ($this->commandConfig['demo-data-packages'] as $demoPackageData) {
if ($demoPackageData['name'] == $extra['sample-data']) {
$package = $this->downloadByComposerConfig($input, $output, $demoPackageData, $this->config['installationFolder'] . '/_temp_demo_data', false);
$this->_fixComposerExtractionBug();
$expandedFolder = $this->config['installationFolder'] . '/_temp_demo_data/' . str_replace(array('.tar.gz', '.tar.bz2', '.zip'), '', basename($package->getDistUrl()));
if (is_dir($expandedFolder)) {
$filesystem->recursiveCopy($expandedFolder, $this->config['installationFolder']);
$filesystem->recursiveRemoveDirectory($expandedFolder);
}
// Remove empty folder
if (is_dir($this->config['installationFolder'] . '/vendor/composer')) {
$filesystem->recursiveRemoveDirectory($this->config['installationFolder'] . '/vendor/composer');
}
// Install sample data
$sampleDataSqlFile = glob($this->config['installationFolder'] . '/_temp_demo_data/magento_*sample_data*sql');
$db = $this->config['db'];
/* @var $db PDO */
if (isset($sampleDataSqlFile[0])) {
if (OperatingSystem::isProgramInstalled('mysql')) {
$exec = 'mysql ' . '-h' . escapeshellarg(strval($this->config['db_host'])) . ' ' . '-u' . escapeshellarg(strval($this->config['db_user'])) . ' ' . ($this->config['db_port'] != '3306' ? '-P' . escapeshellarg($this->config['db_port']) . ' ' : '') . (!strval($this->config['db_pass'] == '') ? '-p' . escapeshellarg($this->config['db_pass']) . ' ' : '') . strval($this->config['db_name']) . ' < ' . escapeshellarg($sampleDataSqlFile[0]);
$output->writeln('<info>Importing <comment>' . $sampleDataSqlFile[0] . '</comment> with mysql cli client</info>');
Exec::run($exec);
@unlink($sampleDataSqlFile[0]);
} else {
$output->writeln('<info>Importing <comment>' . $sampleDataSqlFile[0] . '</comment> with PDO driver</info>');
// Fallback -> Try to install dump file by PDO driver
$dbUtils = new DatabaseUtils();
$dbUtils->importSqlDump($db, $sampleDataSqlFile[0]);
}
}
}
}
if (is_dir($this->config['installationFolder'] . '/_temp_demo_data')) {
$filesystem->recursiveRemoveDirectory($this->config['installationFolder'] . '/_temp_demo_data');
}
}
}