private function general_help() { ETSIS_CLI::line(<<<EOB NAME etsis DESCRIPTION Manage eduTrac SIS through command line. SYNOPSIS etsis <command> COMMANDS cli Get information about ETSIS-CLI itself. core Install, update and manage eduTrac SIS. help Get help on ETSIS-CLI. db Perform basic database operations. OPTIONAL PARAMETERS --require=<path> Load a PHP file before running a command. --path=<path> Path to eduTrac SIS files. --dir=<path> Set path to locate file or where file should be saved. FLAGS --verbose, -v Turn on verbose output. --quiet, -q Disable all output. EOB ); }
/** * Print various data about the CLI environment. * * ## EXAMPLES * * # Display CLI environment. * $ ./etsis cli info */ function info() { $php_bin = defined('PHP_BINARY') ? PHP_BINARY : getenv('ETSIS_CLI_PHP_USED'); ETSIS_CLI::line("PHP binary:\t" . $php_bin); ETSIS_CLI::line("PHP version:\t" . PHP_VERSION); ETSIS_CLI::line("php.ini used:\t" . get_cfg_var('cfg_file_path')); ETSIS_CLI::line("PHP Modules:\t" . shell_exec('php -m')); ETSIS_CLI::line("MySQL Version:\t" . exec('mysql -V')); ETSIS_CLI::line("ETSIS-CLI root dir:\t" . ETSIS_CLI_ROOT); ETSIS_CLI::line("ETSIS-CLI version:\t" . ETSIS_CLI_VERSION); }
public static function describe_command($class, $command) { if (method_exists($class, 'help')) { $class::help(); return; } $methods = self::get_subcommands($class); $out = "Usage: etsis {$command}"; if (empty($methods)) { ETSIS_CLI::line($out); } else { $out .= ' [' . implode('|', $methods) . ']'; ETSIS_CLI::line($out); } }
<?php header('Access-Control-Allow-Origin: *'); if ('cli' !== PHP_SAPI) { echo "This is CLI only.\n"; die(-1); } if (version_compare(PHP_VERSION, '5.4.0', '<')) { printf("Error: requires PHP %s or newer. You are running version %s.\n", '5.4.0', PHP_VERSION); die(-1); } date_default_timezone_set('UTC'); error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', 'Off'); ini_set('log_errors', 'On'); ini_set('error_log', 'app/tmp/logs/etsis-cli.' . date('m-d-Y') . '.txt'); define('ETSIS_CLI_ROOT', __DIR__); define('ETSIS_CLI_VERSION', '1.0.0'); // Constant that can be used to check if we are running etsis-cli or not define('ETSIS_CLI', true); // Include database config file. require_once 'phinx.php'; // Include the e-cli classes require_once ETSIS_CLI_ROOT . '/ETSIS-CLI/etsis_CLI.php'; require_once ETSIS_CLI_ROOT . '/ETSIS-CLI/etsis_CLI_Command.php'; require_once ETSIS_CLI_ROOT . '/php/Mysqldump.php'; require_once ETSIS_CLI_ROOT . '/php/notify.php'; require_once 'app/src/vendor/autoload.php'; // Load dependencies ETSIS_CLI::load_dependencies(); require_once ETSIS_CLI_ROOT . '/php/arguments.php';
public static function get_numeric_arg($args, $index, $name) { if (!isset($args[$index])) { ETSIS_CLI::error("{$name} required"); } if (!is_numeric($args[$index])) { ETSIS_CLI::error("{$name} must be numeric"); } return $args[$index]; }
<?php // Get the cli arguments list($arguments, $assoc_args) = ETSIS_CLI::parse_args(array_slice($GLOBALS['argv'], 1)); // Global parameter : --quiet/--silent define('ETSIS_CLI_QUIET', isset($assoc_args['quiet']) || isset($assoc_args['silent'])); // Global parameter : --require if (isset($assoc_args['require'])) { if (file_exists($assoc_args['require'])) { require $assoc_args['require']; unset($assoc_args['require']); } else { ETSIS_CLI::error(sprintf('File "%s" not found', $assoc_args['require'])); } } // Global parameter : --path if (!empty($assoc_args['path'])) { define('ETSIS_ROOT', rtrim($assoc_args['path'], '/')); unset($assoc_args['path']); } else { // Assume ETSIS root is current directory define('ETSIS_ROOT', $_SERVER['PWD']); } ETSIS_CLI::run_command($arguments, $assoc_args);
/** * Use this command to update installation. * * ## EXAMPLES * * #Updates a current installation. * $ ./etsis core update */ public function update() { $zip = new ZipArchive(); $current_release = ETSIS_CLI::getCurrentRelease(); $file = 'http://etsis.s3.amazonaws.com/core/1.1/release/' . $current_release . '.zip'; if (version_compare(trim(file_get_contents('RELEASE')), $current_release, '<')) { if (ETSIS_CLI::checkExternalFile($file) == 200) { //Download file to the server opt_notify(new \cli\progress\Bar('Downloading ', 1000000)); ETSIS_CLI::getDownload($current_release . '.zip', $file); //Unzip the file to update opt_notify(new \cli\progress\Bar('Unzipping ', 1000000)); $x = $zip->open($current_release . '.zip'); if ($x === true) { //Extract file in root. $zip->extractTo(realpath(__DIR__ . '/../../../../../../')); $zip->close(); //Remove download after completion. unlink($current_release . '.zip'); } ETSIS_CLI::line('Core upgrade complete.'); ETSIS_CLI::line('Run the command %G./etsis db migrate%n to check for database updates.'); } else { ETSIS_CLI::line('Update server cannot be reached. Please try again later.'); } } else { ETSIS_CLI::line('No Update'); } }
/** * List all the tables in eduTrac SIS database. * * ## EXAMPLES * * $ ./etsis db tables * Success: Database table list complete. */ public function tables() { try { $this->pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"]); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->pdo->query('SET CHARACTER SET utf8'); } catch (PDOException $e) { ETSIS_CLI::error(sprintf('"%s"', $e->getMessage())); } $opt = $this->pdo->query("SHOW TABLES"); foreach ($opt as $r) { ETSIS_CLI::line(' %GTable:%n ' . $r['Tables_in_' . DB_NAME]); } $this->pdo = null; ETSIS_CLI::success('Database table list complete.'); }