/** * Interacts with the user. * * This method is executed before the InputDefinition is validated. * This means that this is the only place where the command can * interactively ask for values of missing required arguments. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function interact(InputInterface $input, OutputInterface $output) { global $CFG; // If we can write to current directory then use it by default for moodlepath and datapath. Else put this in data folder. $testplanjson = util::get_json_config_path(true); // Make sure we have moodlepath and datapath, before excuting any option. if (!$input->getOption('moodlepath') || !$input->getOption('datapath')) { // Check if it's already set, if not then ask user. if (file_exists($testplanjson)) { $configjson = file_get_contents($testplanjson); $configjson = json_decode($configjson, true); if (isset($configjson['config']['moodlepath']) && isset($configjson['config']['datapath'])) { return array($configjson['config']['moodlepath'], $configjson['config']['datapath']); } } $dialog = $this->getHelperSet()->get('dialog'); list($moodlepath, $datapath) = $this->ask_install_dirs($output); while (!$dialog->askConfirmation($output, '<question>Are you sure to use following paths</question>' . PHP_EOL . ' <info>Moodle path: ' . $moodlepath . '</info>' . PHP_EOL . '<info>Data path:' . $datapath . ' (Y/N): </info>')) { // Keep asking user till we get final input. list($moodlepath, $datapath) = $this->ask_install_dirs($output); } } else { $moodlepath = $input->getOption('moodlepath'); $datapath = $input->getOption('datapath'); } // Get the config if it exists or default and update moodlepath and datapath. if (file_exists($testplanjson)) { $configjson = file_get_contents($testplanjson); $configjson = json_decode($configjson, true); } else { $testplanjsondist = __DIR__ . '/../testplan.json-dist'; $configjson = file_get_contents($testplanjsondist); $configjson = json_decode($configjson, true); } $configjson['config'] = array('moodlepath' => $moodlepath, 'datapath' => $datapath); // Save final config with install paths. file_put_contents($testplanjson, json_encode($configjson, JSON_PRETTY_PRINT)); }