Skip to content

Instantly share code, notes, and snippets.

@LukeCarrier
Created March 8, 2018 16:57
Show Gist options
  • Save LukeCarrier/09f6fa46577df993dbde5700d7e0532e to your computer and use it in GitHub Desktop.
Save LukeCarrier/09f6fa46577df993dbde5700d7e0532e to your computer and use it in GitHub Desktop.
PsySH/Moodle
<?php // ~/.config/psysh/config.php
require_once getenv('HOME') . '/.local/share/psysh/Commands/MoodleMeUpCommand.php';
return [
'commands' => [
new \LukeCarrier\Psysh\Commands\MoodleMeUpCommand(),
]
];
<?php // ~/.local/share/psysh/Commands/MoodleMeUpCommand.php
namespace LukeCarrier\Psysh\Commands;
use Psy\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MoodleMeUpCommand extends Command {
protected function configure() {
$this
->setName('moodle-me-up')
->setDefinition([])
->setDescription('Moodle me up, Scotty')
->setHelp(<<<HELP
Initialise the Moodle installation in the current working directory.
Not everything will work.
HELP
);
}
protected function execute(InputInterface $input, OutputInterface $output) {
global $CFG;
if (defined('MOODLE_INTERNAL')) {
$output->writeln('One step ahead of ya!');
return false;
}
$cwd = getcwd();
$bootstrap = "{$cwd}/lib/setup.php";
if (!file_exists($bootstrap)) {
$output->writeln('I cannie do it cap\'n!');
return false;
}
$tmp = getenv('TMP');
if ($tmp === false) {
$tmp = '/tmp';
}
define('MOODLE_INTERNAL', true);
define('CLI_SCRIPT', true);
define('ABORT_AFTER_CONFIG', true);
$CFG = (object) [
'dataroot' => $tmp,
'wwwroot' => 'http://localhost',
];
require_once $bootstrap;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment