upgrade
This commit is contained in:
218
plugin/vchamilo/cli/bulkcreatenodes.php
Normal file
218
plugin/vchamilo/cli/bulkcreatenodes.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
exit;
|
||||
global $debuglevel;
|
||||
global $debugdisplay;
|
||||
$debuglevel = 4;
|
||||
$debugdisplay = 4;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
define('CHAMILO_INTERNAL', true);
|
||||
|
||||
// this will only run on master chamilo
|
||||
echo "Starting tool\n";
|
||||
echo "Chamilo Bulk Nodes Creation v.1.0\n";
|
||||
echo "=================================\n";
|
||||
require_once('../../../main/inc/global.inc.php');
|
||||
require_once('clilib.php'); // cli only functions
|
||||
// Ensure errors are well explained
|
||||
ini_set('debug_display', 1);
|
||||
ini_set('debug_level', E_ALL);
|
||||
|
||||
// now get cli options
|
||||
list($options, $unrecognized) = cli_get_params(
|
||||
array(
|
||||
'interactive' => false,
|
||||
'help' => false,
|
||||
'config' => false,
|
||||
'nodes' => '',
|
||||
'lint' => false,
|
||||
'verbose' => false
|
||||
),
|
||||
array(
|
||||
'h' => 'help',
|
||||
'i' => 'interactive',
|
||||
'c' => 'config',
|
||||
'n' => 'nodes',
|
||||
'l' => 'lint',
|
||||
'v' => 'verbose'
|
||||
)
|
||||
);
|
||||
|
||||
$interactive = !empty($options['interactive']);
|
||||
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
cli_error("Cli unkown options\n".$unrecognized);
|
||||
}
|
||||
|
||||
if ($options['help']) {
|
||||
$help = "Command line VChamilo Generator.
|
||||
Please note you must execute this script with the same uid as apache!
|
||||
|
||||
Options:
|
||||
--interactive Blocks on each step and waits for input to continue
|
||||
-h, --help Print out this help
|
||||
-c, --config Define an external config file
|
||||
-n, --nodes A node descriptor CSV file
|
||||
-l, --lint Decodes node file and give a report on nodes to be created.
|
||||
|
||||
Example:
|
||||
\$sudo -u www-data /usr/bin/php /var/www/chamilo/plugin/vchamilo/cli/bulkcreatenodes.php --nodes=<nodelist>
|
||||
"; //TODO: localize - to be translated later when everything is finished
|
||||
|
||||
echo $help;
|
||||
die;
|
||||
}
|
||||
|
||||
// Get all options from config file.
|
||||
|
||||
if (!empty($options['config'])) {
|
||||
echo "Loading config : ".$options['config'];
|
||||
if (!file_exists($options['config'])) {
|
||||
cli_error('Config file mentioned but not found');
|
||||
}
|
||||
|
||||
$content = file($options['config']);
|
||||
foreach ($content as $l) {
|
||||
if (preg_match('/^\s+$/', $l)) continue; // Empty lines.
|
||||
if (preg_match('/^[#\/!;]/', $l)) continue; // Comments (any form).
|
||||
if (preg_match('/^(.*?)=(.*)$/', $l, $matches)) {
|
||||
if (in_array($matches[1], $expectedoptions)) {
|
||||
$options[trim($matches[1])] = trim($matches[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require_once($_configuration['root_sys'].'local/classes/database.class.php'); // cli only functions
|
||||
require_once($_configuration['root_sys'].'local/classes/textlib.class.php'); // cli only functions
|
||||
require_once($_configuration['root_sys'].'local/classes/mootochamlib.php'); // moodle like API
|
||||
require_once($_configuration['root_sys'].'/plugin/vchamilo/lib/vchamilo_plugin.class.php');
|
||||
|
||||
global $DB;
|
||||
if ($options['verbose']) echo "building database manager\n";
|
||||
$DB = new DatabaseManager();
|
||||
if ($options['verbose']) echo "building plugin vchamilo\n";
|
||||
$plugin = VChamiloPlugin::create();
|
||||
|
||||
if (empty($options['nodes'])) {
|
||||
cli_error('Missing node definition. Halt.');
|
||||
}
|
||||
|
||||
if ($options['verbose']) echo "parsing nodelist\n";
|
||||
$nodes = vchamilo_parse_csv_nodelist($options['nodes'], $plugin);
|
||||
|
||||
if ($options['lint']) {
|
||||
ctrace("Lint mode:\n");
|
||||
print_object($nodes);
|
||||
die;
|
||||
}
|
||||
|
||||
if (empty($nodes)) {
|
||||
cli_error('Node list empty');
|
||||
}
|
||||
|
||||
ctrace('Starting generation');
|
||||
|
||||
// Get main admin for further replacement.
|
||||
$admin = $DB->get_record('user', array('username' => 'admin'));
|
||||
|
||||
foreach ($nodes as $data) {
|
||||
|
||||
ctrace('Making node '.$data->root_web);
|
||||
|
||||
if (!empty($data->template)) {
|
||||
ctrace('Using template '.$data->template);
|
||||
|
||||
if (!vchamilo_template_exists($data->template)) {
|
||||
ctrace('Template not found. Skipping node.');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($DB->get_record('vchamilo', array('root_web' => $data->root_web))) {
|
||||
ctrace('Node exists. skipping');
|
||||
continue;
|
||||
}
|
||||
|
||||
$data->what = 'addinstance';
|
||||
$data->registeronly = false;
|
||||
|
||||
$NDB = null;
|
||||
|
||||
$automation = true;
|
||||
$return = include($_configuration['root_sys'].'plugin/vchamilo/views/editinstance.controller.php');
|
||||
if ($return == -1) {
|
||||
cli_error('Node create process error');
|
||||
}
|
||||
|
||||
// This is specific code for presetting any plugin data per instance from the CSV
|
||||
ctrace('Setting up ent_installer');
|
||||
if ($NDB) {
|
||||
// Copy admin account info from master
|
||||
$NDB->set_field('user', 'password', $admin->password, array('username' => 'admin'), 'user_id');
|
||||
|
||||
// Setting ENT_installer values
|
||||
if (!empty($data->ent_installer)) {
|
||||
foreach ($data->ent_installer as $setting => $value) {
|
||||
$settingrec = new StdClass();
|
||||
$settingrec->variable = 'ent_installer_'.$setting;
|
||||
$settingrec->subkey = 'ent_installer';
|
||||
$settingrec->type = 'setting';
|
||||
$settingrec->category = 'Plugins';
|
||||
$settingrec->access_url = 1;
|
||||
$settingrec->selected_value = $value;
|
||||
ctrace("Setting up {$settingrec->variable}|{$settingrec->subkey} to $value\n");
|
||||
if ($oldrec = $NDB->get_record('settings_current', array('variable' => $settingrec->variable, 'subkey' => $settingrec->subkey, 'type' => $settingrec->type))) {
|
||||
$settingrec->id = $oldrec->id;
|
||||
$NDB->update_record('settings_current', $settingrec, 'id');
|
||||
} else {
|
||||
$NDB->insert_record('settings_current', $settingrec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// updating other config values
|
||||
if (!empty($data->config)) {
|
||||
ctrace("VChamilo has config overrides\n");
|
||||
foreach ($data->config as $configkey => $configsetting) {
|
||||
ctrace("Setting up {$configkey}");
|
||||
// Note you can just alter existing settings here as we cannot pull enough data from csv headers to get a complete setting descriptor.
|
||||
$settingrec = new StdClass();
|
||||
$settingrec->variable = $configkey;
|
||||
if (!empty($settingrec->subkey)) {
|
||||
$settingrec->subkey = $configsetting->subkey;
|
||||
}
|
||||
// $settingrec->type = 'setting';
|
||||
// $settingrec->category = 'Plugins';
|
||||
// $settingrec->access_url = 1;
|
||||
$settingrec->selected_value = $configsetting->value;
|
||||
|
||||
if (!empty($settingrec->subkey)) {
|
||||
$params = array('variable' => $settingrec->variable, 'subkey' => $settingrec->subkey);
|
||||
} else {
|
||||
$params = array('variable' => $settingrec->variable);
|
||||
}
|
||||
|
||||
if ($oldrec = $NDB->get_record('settings_current', $params)) {
|
||||
ctrace("Updating {$settingrec->variable}|{$settingrec->subkey} to $configsetting->value\n");
|
||||
$settingrec->id = $oldrec->id;
|
||||
$NDB->update_record('settings_current', $settingrec, 'id');
|
||||
}
|
||||
}
|
||||
}
|
||||
$NDB->dismount();
|
||||
} else {
|
||||
ctrace('No Side CNX for setup');
|
||||
}
|
||||
|
||||
if ($interactive) {
|
||||
$input = readline("Continue (y/n|r) ?\n");
|
||||
if ($input == 'r' || $input == 'R') {
|
||||
// do nothing, just continue
|
||||
} elseif ($input == 'n' || $input == 'N') {
|
||||
echo "finishing\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
170
plugin/vchamilo/cli/bulkdestroynodes.php
Normal file
170
plugin/vchamilo/cli/bulkdestroynodes.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
exit;
|
||||
/**
|
||||
* This script is to be used from PHP command line and will create a set
|
||||
* of Virtual VChamilo automatically from a CSV nodelist description.
|
||||
* The standard structure of the nodelist is given by the nodelist-dest.csv file.
|
||||
*/
|
||||
|
||||
global $debuglevel;
|
||||
global $debugdisplay;
|
||||
$debuglevel = 4;
|
||||
$debugdisplay = 4;
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
define('CHAMILO_INTERNAL', true);
|
||||
|
||||
// this will only run on master chamilo
|
||||
echo "Starting tool\n";
|
||||
echo "Chamilo Bulk Nodes Creation v.1.0\n";
|
||||
echo "=================================\n";
|
||||
require_once('../../../main/inc/global.inc.php');
|
||||
require_once('clilib.php'); // cli only functions
|
||||
// Ensure errors are well explained
|
||||
ini_set('debug_display', 1);
|
||||
ini_set('debug_level', E_ALL);
|
||||
|
||||
// Now get cli options.
|
||||
list($options, $unrecognized) = cli_get_params(
|
||||
array(
|
||||
'interactive' => false,
|
||||
'help' => false,
|
||||
'config' => false,
|
||||
'nodes' => '',
|
||||
'lint' => false
|
||||
),
|
||||
array(
|
||||
'h' => 'help',
|
||||
'c' => 'config',
|
||||
'n' => 'nodes',
|
||||
'i' => 'interactive',
|
||||
'l' => 'lint'
|
||||
)
|
||||
);
|
||||
|
||||
$interactive = !empty($options['interactive']);
|
||||
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
|
||||
}
|
||||
|
||||
if ($options['help']) {
|
||||
$help =
|
||||
"Command line VMoodle Generator.
|
||||
Please note you must execute this script with the same uid as apache!
|
||||
|
||||
Options:
|
||||
--interactive No interactive questions or confirmations
|
||||
-h, --help Print out this help
|
||||
-c, --config Define an external config file
|
||||
-n, --nodes A node descriptor CSV file
|
||||
-l, --lint Decodes node file and give a report on nodes to be created.
|
||||
|
||||
Example:
|
||||
\$sudo -u www-data /usr/bin/php /var/www/chamilo19/plugin/vchamilo/cli/bulkdestroynodes.php --nodes=<node-file-path>
|
||||
"; //TODO: localize - to be translated later when everything is finished
|
||||
|
||||
echo $help;
|
||||
die;
|
||||
}
|
||||
|
||||
// Get all options from config file.
|
||||
if (!empty($options['config'])) {
|
||||
echo "Loading config : ".$options['config'];
|
||||
if (!file_exists($options['config'])) {
|
||||
cli_error(get_string('confignotfound', 'block_vmoodle'));
|
||||
}
|
||||
$content = file($options['config']);
|
||||
foreach ($content as $l) {
|
||||
if (preg_match('/^\s+$/', $l)) {
|
||||
continue; // Empty lines.
|
||||
}
|
||||
if (preg_match('/^[#\/!;]/', $l)) {
|
||||
continue; // Comments (any form).
|
||||
}
|
||||
if (preg_match('/^(.*?)=(.*)$/', $l, $matches)) {
|
||||
if (in_array($matches[1], $expectedoptions)) {
|
||||
$options[trim($matches[1])] = trim($matches[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require_once($_configuration['root_sys'].'local/classes/database.class.php'); // cli only functions
|
||||
if ($options['verbose']) {
|
||||
echo "loaded dbclass\n";
|
||||
}
|
||||
require_once($_configuration['root_sys'].'local/classes/textlib.class.php'); // cli only functions
|
||||
if ($options['verbose']) {
|
||||
echo "loaded textlib\n";
|
||||
}
|
||||
require_once($_configuration['root_sys'].'local/classes/mootochamlib.php'); // moodle like API
|
||||
if ($options['verbose']) {
|
||||
echo "loaded moodle wrapping\n";
|
||||
}
|
||||
require_once($_configuration['root_sys'].'/plugin/vchamilo/lib/vchamilo_plugin.class.php');
|
||||
if ($options['verbose']) {
|
||||
echo "loaded vchamilo plugin\n";
|
||||
}
|
||||
|
||||
global $DB;
|
||||
if ($options['verbose']) {
|
||||
echo "building database manager\n";
|
||||
}
|
||||
$DB = new DatabaseManager();
|
||||
if ($options['verbose']) {
|
||||
echo "building plugin vchamilo\n";
|
||||
}
|
||||
$plugin = VChamiloPlugin::create();
|
||||
|
||||
if (empty($options['nodes'])) {
|
||||
cli_error(get_string('climissingnodes', 'block_vmoodle'));
|
||||
}
|
||||
|
||||
if ($options['verbose']) {
|
||||
echo "parsing nodelist\n";
|
||||
}
|
||||
$nodes = vchamilo_parse_csv_nodelist($options['nodes'], $plugin);
|
||||
|
||||
if ($options['lint']) {
|
||||
ctrace("Lint mode:\n");
|
||||
print_object($nodes);
|
||||
die;
|
||||
}
|
||||
|
||||
if (empty($nodes)) {
|
||||
cli_error(get_string('cliemptynodelist', 'block_vmoodle'));
|
||||
}
|
||||
|
||||
ctrace('Starting CLI processing');
|
||||
|
||||
foreach ($nodes as $n) {
|
||||
|
||||
ctrace('Destroying node :'.$n->vhostname);
|
||||
|
||||
if (!$DB->get_record('vchamilo', array('root_web' => $n->root_web))) {
|
||||
ctrace('Node does not exist. Skipping');
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* This launches automatically all steps of the controller.management.php script several times
|
||||
* with the "doadd" action and progressing in steps.
|
||||
*/
|
||||
$action = "fulldeleteinstances";
|
||||
|
||||
$automation = true;
|
||||
|
||||
$return = include($_configuration['root_sys'].'/plugin/vchamilo/views/manage.controller.php');
|
||||
if ($interactive) {
|
||||
$input = readline("Continue (y/n|r) ?\n");
|
||||
if ($input == 'r' || $input == 'R') {
|
||||
$vmoodlestep--;
|
||||
} elseif ($input == 'n' || $input == 'N') {
|
||||
echo "finishing\n";
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
exit (0);
|
||||
343
plugin/vchamilo/cli/clilib.php
Normal file
343
plugin/vchamilo/cli/clilib.php
Normal file
@@ -0,0 +1,343 @@
|
||||
<?php
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Opens and parses/checks a VChamilo instance definition file
|
||||
* @param string $nodelistlocation
|
||||
* @param string $plugin
|
||||
* @return mixed
|
||||
*/
|
||||
function vchamilo_parse_csv_nodelist($nodelistlocation = '', $plugin = null) {
|
||||
global $_configuration;
|
||||
|
||||
$vnodes = array();
|
||||
|
||||
if (empty($nodelistlocation)) {
|
||||
$nodelistlocation = $_configuration['root_sys'].'/plugin/vchamilo/nodelist.csv';
|
||||
}
|
||||
|
||||
// decode file
|
||||
$csv_delimiter = "\;";
|
||||
$csv_delimiter2 = ";";
|
||||
|
||||
// make arrays of valid fields for error checking
|
||||
$required = array(
|
||||
'root_web' => 1,
|
||||
'sitename' => 1,
|
||||
'institution' => 1,
|
||||
'main_database' => 1,
|
||||
'statistics_database' => 1,
|
||||
'user_personal_database' => 1,
|
||||
'db_user' => 1,
|
||||
'db_password' => 1,
|
||||
'course_folder' => 1,
|
||||
);
|
||||
|
||||
$optional = array(
|
||||
'db_host' => 1,
|
||||
'template' => 1,
|
||||
'table_prefix' => 1,
|
||||
'single_database' => 1,
|
||||
'tracking_enabled' => 1,
|
||||
'visible' => 1,
|
||||
);
|
||||
|
||||
$optionalDefaults = array(
|
||||
'db_host' => $_configuration['db_host'],
|
||||
'db_prefix' => 'chm_',
|
||||
'table_prefix' => '',
|
||||
'tracking_enabled' => 0,
|
||||
'single_database' => 1,
|
||||
'template' => '',
|
||||
'visible' => 1
|
||||
);
|
||||
|
||||
$patterns = array();
|
||||
|
||||
// Metas are accepted patterns (optional)
|
||||
$metas = array(
|
||||
'plugin_.*',
|
||||
'config_.*'
|
||||
);
|
||||
|
||||
// Get header (field names)
|
||||
|
||||
$textlib = new textlib();
|
||||
|
||||
if (!$fp = fopen($nodelistlocation, 'rb')) {
|
||||
cli_error($plugin->get_lang('badnodefile', 'vchamilo', $nodelistlocation));
|
||||
}
|
||||
|
||||
// Jump any empty or comment line
|
||||
$text = fgets($fp, 1024);
|
||||
$i = 0;
|
||||
while (vchamilo_is_empty_line_or_format($text, $i == 0)) {
|
||||
$text = fgets($fp, 1024);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$headers = explode($csv_delimiter2, $text);
|
||||
|
||||
// Check for valid field names
|
||||
foreach ($headers as $h) {
|
||||
$header[] = trim($h);
|
||||
$patternized = implode('|', $patterns)."\\d+";
|
||||
$metapattern = implode('|', $metas);
|
||||
if (!(isset($required[$h]) ||
|
||||
isset($optionalDefaults[$h]) ||
|
||||
isset($optional[$h]) ||
|
||||
preg_match("/$patternized/", $h) ||
|
||||
preg_match("/$metapattern/", $h))) {
|
||||
cli_error("Node parse : invalidfieldname $h ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($required[trim($h)])) {
|
||||
$required[trim($h)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$expectedcols = count($headers);
|
||||
$i++;
|
||||
|
||||
// Check for required fields.
|
||||
foreach ($required as $key => $value) {
|
||||
if ($value) { // Required field missing.
|
||||
cli_error("fieldrequired $key");
|
||||
return;
|
||||
}
|
||||
}
|
||||
$linenum = 2; // Since header is line 1.
|
||||
|
||||
// Take some from admin profile, other fixed by hardcoded defaults.
|
||||
while (!feof($fp)) {
|
||||
|
||||
// Make a new base record.
|
||||
$vnode = new StdClass();
|
||||
foreach ($optionalDefaults as $key => $value) {
|
||||
$vnode->$key = $value;
|
||||
}
|
||||
|
||||
//Note: commas within a field should be encoded as , (for comma separated csv files)
|
||||
//Note: semicolon within a field should be encoded as ; (for semicolon separated csv files)
|
||||
$text = fgets($fp, 1024);
|
||||
if (vchamilo_is_empty_line_or_format($text, false)) {
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$valueset = explode($csv_delimiter2, $text);
|
||||
if (count($valueset) != $expectedcols) {
|
||||
cli_error('wrong line count at line '.$i);
|
||||
}
|
||||
$f = 0;
|
||||
foreach ($valueset as $value) {
|
||||
// Decode encoded commas.
|
||||
$key = $headers[$f];
|
||||
if (preg_match('/\|/', $key)) {
|
||||
list($plugin, $variable) = explode('|', str_replace('plugin_', '', $key));
|
||||
if (empty($variable)) die("Key error in CSV : $key ");
|
||||
if (!isset($vnode->$plugin)) {
|
||||
$vnode->$plugin = new StdClass();
|
||||
}
|
||||
$vnode->$plugin->$variable = trim($value);
|
||||
} else {
|
||||
if (preg_match('/^config_/', $key)) {
|
||||
$smartkey = str_replace('config_', '', $key);
|
||||
$keyparts = implode('|', $smartkey);
|
||||
$keyvar = $keyparts[0];
|
||||
$subkey = @$keyparts[1];
|
||||
$vnode->config->$smartkey = new StdClass;
|
||||
$vnode->config->$smartkey->subkey = $subkey;
|
||||
$vnode->config->$smartkey->value = trim($value);
|
||||
} else {
|
||||
$vnode->$key = trim($value);
|
||||
}
|
||||
}
|
||||
$f++;
|
||||
}
|
||||
$vnodes[] = $vnode;
|
||||
}
|
||||
|
||||
return $vnodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a CSV input line format for empty or commented lines
|
||||
* Ensures compatbility to UTF-8 BOM or unBOM formats
|
||||
* @param resource $text
|
||||
* @param bool $resetfirst
|
||||
* @return bool
|
||||
*/
|
||||
function vchamilo_is_empty_line_or_format(&$text, $resetfirst = false) {
|
||||
global $CFG;
|
||||
|
||||
static $textlib;
|
||||
static $first = true;
|
||||
|
||||
// We may have a risk the BOM is present on first line
|
||||
if ($resetfirst) $first = true;
|
||||
if (!isset($textlib)) $textlib = new textlib(); // Singleton
|
||||
$text = $textlib->trim_utf8_bom($text);
|
||||
$first = false;
|
||||
|
||||
$text = preg_replace("/\n?\r?/", '', $text);
|
||||
|
||||
// last chance
|
||||
if ('ASCII' == mb_detect_encoding($text)) {
|
||||
$text = utf8_encode($text);
|
||||
}
|
||||
|
||||
// Check the text is empty or comment line and answer true if it is.
|
||||
return preg_match('/^$/', $text) || preg_match('/^(\(|\[|-|#|\/| )/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get input from user
|
||||
* @param string $prompt text prompt, should include possible options
|
||||
* @param string $default default value when enter pressed
|
||||
* @param array $options list of allowed options, empty means any text
|
||||
* @param bool $casesensitiveoptions true if options are case sensitive
|
||||
* @return string entered text
|
||||
*/
|
||||
function cli_input($prompt, $default = '', array $options = null, $casesensitiveoptions = false) {
|
||||
echo $prompt;
|
||||
echo "\n: ";
|
||||
$input = fread(STDIN, 2048);
|
||||
$input = trim($input);
|
||||
if ($input === '') {
|
||||
$input = $default;
|
||||
}
|
||||
if ($options) {
|
||||
if (!$casesensitiveoptions) {
|
||||
$input = strtolower($input);
|
||||
}
|
||||
if (!in_array($input, $options)) {
|
||||
echo "Incorrect value, please retry.\n"; // TODO: localize, mark as needed in install
|
||||
return cli_input($prompt, $default, $options, $casesensitiveoptions);
|
||||
}
|
||||
}
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cli script parameters.
|
||||
* @param array $longoptions array of --style options ex:('verbose'=>false)
|
||||
* @param array $shortmapping array describing mapping of short to long style options ex:('h'=>'help', 'v'=>'verbose')
|
||||
* @return array array of arrays, options, unrecognised as optionlongname=>value
|
||||
*/
|
||||
function cli_get_params(array $longoptions, array $shortmapping = null) {
|
||||
$shortmapping = (array) $shortmapping;
|
||||
$options = array();
|
||||
$unrecognized = array();
|
||||
|
||||
if (empty($_SERVER['argv'])) {
|
||||
// Bad luck, we can continue in interactive mode ;-)
|
||||
return array($options, $unrecognized);
|
||||
}
|
||||
$rawoptions = $_SERVER['argv'];
|
||||
|
||||
// Remove anything after '--', options can not be there.
|
||||
if (($key = array_search('--', $rawoptions)) !== false) {
|
||||
$rawoptions = array_slice($rawoptions, 0, $key);
|
||||
}
|
||||
|
||||
// Remove script.
|
||||
unset($rawoptions[0]);
|
||||
foreach ($rawoptions as $raw) {
|
||||
if (substr($raw, 0, 2) === '--') {
|
||||
$value = substr($raw, 2);
|
||||
$parts = explode('=', $value);
|
||||
if (count($parts) == 1) {
|
||||
$key = reset($parts);
|
||||
$value = true;
|
||||
} else {
|
||||
$key = array_shift($parts);
|
||||
$value = implode('=', $parts);
|
||||
}
|
||||
if (array_key_exists($key, $longoptions)) {
|
||||
$options[$key] = $value;
|
||||
} else {
|
||||
$unrecognized[] = $raw;
|
||||
}
|
||||
|
||||
} else if (substr($raw, 0, 1) === '-') {
|
||||
$value = substr($raw, 1);
|
||||
$parts = explode('=', $value);
|
||||
if (count($parts) == 1) {
|
||||
$key = reset($parts);
|
||||
$value = true;
|
||||
} else {
|
||||
$key = array_shift($parts);
|
||||
$value = implode('=', $parts);
|
||||
}
|
||||
if (array_key_exists($key, $shortmapping)) {
|
||||
$options[$shortmapping[$key]] = $value;
|
||||
} else {
|
||||
$unrecognized[] = $raw;
|
||||
}
|
||||
} else {
|
||||
$unrecognized[] = $raw;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Apply defaults.
|
||||
foreach ($longoptions as $key=>$default) {
|
||||
if (!array_key_exists($key, $options)) {
|
||||
$options[$key] = $default;
|
||||
}
|
||||
}
|
||||
// Finished.
|
||||
return array($options, $unrecognized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print or return section separator string
|
||||
* @param bool $return false means print, true return as string
|
||||
* @return mixed void or string
|
||||
*/
|
||||
function cli_separator($return = false) {
|
||||
$separator = str_repeat('-', 79)."\n";
|
||||
if ($return) {
|
||||
return $separator;
|
||||
} else {
|
||||
echo $separator;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print or return section heading string
|
||||
* @param string $string text
|
||||
* @param bool $return false means print, true return as string
|
||||
* @return mixed void or string
|
||||
*/
|
||||
function cli_heading($string, $return = false) {
|
||||
$string = "== $string ==\n";
|
||||
if ($return) {
|
||||
return $string;
|
||||
} else {
|
||||
echo $string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write error notification
|
||||
* @param $text
|
||||
* @return void
|
||||
*/
|
||||
function cli_problem($text) {
|
||||
fwrite(STDERR, $text."\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to standard out and error with exit in error.
|
||||
*
|
||||
* @param string $text
|
||||
* @param int $errorCode
|
||||
* @return void (does not return)
|
||||
*/
|
||||
function cli_error($text, $errorCode = 1) {
|
||||
fwrite(STDERR, $text);
|
||||
fwrite(STDERR, "\n");
|
||||
die($errorCode);
|
||||
}
|
||||
77
plugin/vchamilo/cli/cron.php
Normal file
77
plugin/vchamilo/cli/cron.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
exit;
|
||||
/**
|
||||
* This script should be called by a properly set cron process on your server.
|
||||
* For more information, check the installation guide in the documentation
|
||||
* folder.
|
||||
* Add your own executable scripts below the inclusion of notification.php
|
||||
* @package chamilo.cron
|
||||
*/
|
||||
/**
|
||||
* Settings that will influence the execution of the cron tasks
|
||||
*/
|
||||
//ini_set('max_execution_time',300); //authorize execution for up to 5 minutes
|
||||
//ini_set('memory_limit','100M'); //authorize script to use up to 100M RAM
|
||||
/**
|
||||
* Included cron-ed tasks. You might want to turn error-logging off by
|
||||
* commenting the first and last line of this section.
|
||||
*/
|
||||
|
||||
define('CLI_SCRIPT', true); // for chamilo imported code
|
||||
define('CHAMILO_INTERNAL', true);
|
||||
global $CLI_VCHAMILO_PRECHECK;
|
||||
|
||||
$CLI_VCHAMILO_PRECHECK = true; // force first config to be minimal
|
||||
require __DIR__.'/../../../app/config/configuration.php'; // get boot config
|
||||
require_once $_configuration['root_sys'].'plugin/vchamilo/cli/clilib.php'; // cli only functions
|
||||
|
||||
// Ensure errors are well explained
|
||||
|
||||
// now get cli options
|
||||
list($options, $unrecognized) = cli_get_params(
|
||||
array(
|
||||
'help' => false,
|
||||
'host' => false,
|
||||
),
|
||||
array(
|
||||
'h' => 'help',
|
||||
'H' => 'host'
|
||||
)
|
||||
);
|
||||
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
|
||||
}
|
||||
|
||||
if ($options['help']) {
|
||||
$help =
|
||||
"Command line chamilo CRON
|
||||
|
||||
Options:
|
||||
-h, --help Print out this help
|
||||
-H, --host Set the host (physical or virtual) to operate on
|
||||
|
||||
"; //TODO: localize - to be translated later when everything is finished
|
||||
|
||||
echo $help;
|
||||
die;
|
||||
}
|
||||
|
||||
if (!empty($options['host'])) {
|
||||
// arms the vchamilo switching
|
||||
echo('Arming for '.$options['host']."\n"); // mtrace not yet available.
|
||||
define('CLI_VCHAMILO_OVERRIDE', $options['host']);
|
||||
}
|
||||
// replay full config whenever. If vchamilo switch is armed, will switch now config
|
||||
require $_configuration['root_sys'].'app/config/configuration.php'; // do REALLY force configuration to play again, or the following call will not have config tweaked (require_once)
|
||||
echo('Config check : playing for '.$_configuration['root_web']."\n");
|
||||
|
||||
error_log('[chamilo][cronjob] Starting cron jobs as process '.getmypid());
|
||||
echo '<pre>';
|
||||
echo ('[chamilo][cronjob] Starting cron jobs as process '.getmypid()."\n");
|
||||
require_once $_configuration['root_sys'].'main/cron/notification.php';
|
||||
error_log('[chamilo][cronjob] Ending cron jobs of process '.getmypid());
|
||||
echo('[chamilo][cronjob] Ending cron jobs of process '.getmypid()."\n");
|
||||
echo '</pre>';
|
||||
25
plugin/vchamilo/cli/maincron.php
Normal file
25
plugin/vchamilo/cli/maincron.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
exit;
|
||||
|
||||
/**
|
||||
* This script should be called by a properly set cron process on your server.
|
||||
* For more information, check the installation guide in the documentation
|
||||
* folder.
|
||||
* Add your own executable scripts below the inclusion of notification.php
|
||||
* @package chamilo.cron
|
||||
*/
|
||||
/**
|
||||
* Settings that will influence the execution of the cron tasks
|
||||
*/
|
||||
//ini_set('max_execution_time',300); //authorize execution for up to 5 minutes
|
||||
//ini_set('memory_limit','100M'); //authorize script to use up to 100M RAM
|
||||
/**
|
||||
* Included cron-ed tasks. You might want to turn error-logging off by
|
||||
* commenting the first and last line of this section.
|
||||
*/
|
||||
define('CLI_SCRIPT', true); // for chamilo imported code
|
||||
define('CHAMILO_INTERNAL', true);
|
||||
error_log('[chamilo][cronjob] Starting cron jobs as process '.getmypid());
|
||||
require_once(dirname(dirname(dirname(__DIR__))).'/main/cron/notification.php');
|
||||
error_log('[chamilo][cronjob] Ending cron jobs of process '.getmypid());
|
||||
12
plugin/vchamilo/cli/nodelist-dist.csv
Normal file
12
plugin/vchamilo/cli/nodelist-dist.csv
Normal file
@@ -0,0 +1,12 @@
|
||||
#
|
||||
# root_web : a fully qualified domain as wwwroot for the instance
|
||||
# template : a VChamilo template name (stored from a vchamilo snapshot) or empty if no template
|
||||
# tracking_enabled : 0 or 1
|
||||
# single_database : 0 or 1
|
||||
# main_database : the main database
|
||||
# statistics_database : if empty, is using main_database
|
||||
# user_personal_database : if empty, is using main_database
|
||||
# course_folder : absolute path to course material
|
||||
#
|
||||
root_web;template;sitename;institution;db_host;db_user;db_password;table_prefix;db_prefix;tracking_enabled;single_database;main_database;statistics_database;user_personal_database;course_folder
|
||||
|
||||
|
Reference in New Issue
Block a user