本文整理汇总了PHP中cli_error函数的典型用法代码示例。如果您正苦于以下问题:PHP cli_error函数的具体用法?PHP cli_error怎么用?PHP cli_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cli_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_category_tree
private function get_category_tree($id)
{
global $DB;
$category = $DB->get_record('course_categories', array('id' => $id));
if ($id && !$category) {
cli_error("Wrong category '{$id}'");
} elseif (!$id) {
$category = NULL;
}
$parentcategory = \coursecat::get($id);
if ($parentcategory->has_children()) {
$parentschildren = $parentcategory->get_children();
foreach ($parentschildren as $singlecategory) {
if ($singlecategory->has_children()) {
$childcategories = $this->get_category_tree($singlecategory->id);
$category->categories[] = $childcategories;
} else {
// coursecat variables are protected, need to get data from db
$singlecategory = $DB->get_record('course_categories', array('id' => $singlecategory->id));
$category->categories[] = $singlecategory;
}
}
}
return $category;
}
示例2: execute
public function execute()
{
global $DB;
$options = $this->expandedOptions;
$from_date = strtotime($options['from']);
if ($options['to']) {
$to_date = strtotime($options['to']);
} else {
$to_date = time();
}
if ($from_date === false) {
cli_error('invalid from date');
}
if ($to_date === false) {
cli_error('invalid to date');
}
if ($to_date < $from_date) {
cli_error('to date must be higher than from date');
}
$period = $period = $options['period'];
$sql = "SELECT (FROM_UNIXTIME(period * ( {$period}*60 ))) AS time, \n\t\t\t\tonline_users FROM (SELECT ROUND( time / ( {$period}*60 ) ) AS period,\n\t\t\t\tCOUNT( DISTINCT userid ) AS online_users\n\t\t\t\tFROM {log}\n\t\t\t\tWHERE action <> 'error' AND module <> 'library'\n\t\t\t\tAND time >= {$from_date} AND time <= {$to_date}\n\t\t\t\tGROUP BY period\n\t\t\t\t) AS concurrent_users_report";
$query = $DB->get_records_sql($sql);
foreach ($query as $k => $v) {
echo $k . " users online: " . $v->online_users . "\n";
}
}
示例3: execute
public function execute()
{
$setting = trim($this->arguments[2]);
$value = trim($this->arguments[3]);
switch ($this->arguments[0]) {
case 'course':
if (!self::setCourseSetting($this->arguments[1], $setting, $value)) {
// the setting was not applied, exit with a non-zero exit code
cli_error('');
}
break;
case 'category':
//get all courses in category (recursive)
$courselist = get_courses($this->arguments[1], '', 'c.id');
$succeeded = 0;
$failed = 0;
foreach ($courselist as $course) {
if (self::setCourseSetting($course->id, $setting, $value)) {
$succeeded++;
} else {
$failed++;
}
}
if ($failed == 0) {
echo "OK - successfully modified {$succeeded} courses\n";
} else {
echo "WARNING - failed to mofify {$failed} courses (successfully modified {$succeeded})\n";
}
break;
}
}
示例4: execute
public function execute()
{
if (strpos($this->arguments[0], '_') !== false) {
cli_error("Module name can not contain _");
}
//copy newmodule
$modPath = $this->topDir . '/mod/' . $this->arguments[0];
if (file_exists($modPath)) {
cli_problem("Already exists: '{$modPath}'");
cli_problem("Not creating new module " . $this->arguments[0]);
exit(1);
}
run_external_command("cp -r '{$this->mooshDir}/vendor/moodlehq/moodle-mod_newmodule' '{$modPath}'", "Copying from module template failed");
if (file_exists("{$modPath}/.git")) {
run_external_command("rm --interactive=never -r '{$modPath}/.git'", "Removing .git failed");
}
//replace newmodule with $this->arguments[0]
run_external_command("find '{$modPath}' -type f -exec sed 's/newmodule/{$this->arguments[0]}/g' -i {} \\;", "sed command failed");
//rename lang/en/newmodule.php
run_external_command("mv '{$modPath}/lang/en/newmodule.php' '{$modPath}/lang/en/{$this->arguments[0]}.php'", "Renaming lang file failed");
//rename backup files
run_external_command("mv '{$modPath}/backup/moodle2/backup_newmodule_activity_task.class.php' '{$modPath}/backup/moodle2/backup_{$this->arguments[0]}_activity_task.class.php'", "Renaming backup activity task file failed");
run_external_command("mv '{$modPath}/backup/moodle2/backup_newmodule_stepslib.php' '{$modPath}/backup/moodle2/backup_{$this->arguments[0]}_stepslib.php'", "Renaming backup stepslib file failed");
//rename restore files
run_external_command("mv '{$modPath}/backup/moodle2/restore_newmodule_activity_task.class.php' '{$modPath}/backup/moodle2/restore_{$this->arguments[0]}_activity_task.class.php'", "Renaming restore activity task file failed");
run_external_command("mv '{$modPath}/backup/moodle2/restore_newmodule_stepslib.php' '{$modPath}/backup/moodle2/restore_{$this->arguments[0]}_stepslib.php'", "Renaming restore stepslib file failed");
}
示例5: execute
public function execute()
{
global $CFG;
$connstr = '';
switch ($CFG->dbtype) {
case 'mysqli':
case 'mariadb':
$connstr = "mysql -h {$CFG->dbhost} -u {$CFG->dbuser} -p{$CFG->dbpass} {$CFG->dbname}";
break;
case 'pgsql':
$portoption = '';
if (!empty($CFG->dboptions['dbport'])) {
$portoption = '-p ' . $CFG->dboptions['dbport'];
}
putenv("PGPASSWORD={$CFG->dbpass}");
$connstr = "psql -h {$CFG->dbhost} -U {$CFG->dbuser} {$portoption} {$CFG->dbname}";
break;
default:
cli_error("Sorry, database type '{$CFG->dbtype}' is not supported yet. Feel free to contribute!");
break;
}
if ($this->verbose) {
echo "Connecting to database using '{$connstr}'";
}
$process = proc_open($connstr, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes);
$proc_status = proc_get_status($process);
$exit_code = proc_close($process);
return $proc_status["running"] ? $exit_code : $proc_status["exitcode"];
}
示例6: execute
public function execute()
{
global $CFG, $DB;
require_once $CFG->libdir . '/csvlib.class.php';
require_once $CFG->libdir . '/moodlelib.php';
$filename = $this->expandedOptions['path'];
if ($filename[0] != '/') {
$filename = $this->cwd . DIRECTORY_SEPARATOR . $filename;
}
$categories = $DB->get_records('user_info_category', null, 'sortorder ASC');
$data = array();
foreach ($categories as $category) {
if ($fields = $DB->get_records('user_info_field', array('categoryid' => $category->id), 'sortorder ASC')) {
foreach ($fields as $field) {
$field->categoryname = $category->name;
$field->categorysortorder = $category->sortorder;
$data[] = $field;
}
}
}
// End of $categories foreach.
$header = array('id', 'shortname', 'name', 'datatype', 'description', 'descriptionformat', 'categoryid', 'sortorder', 'required', 'locked', 'visible', 'forceunique', 'signup', 'defaultdata', 'defaultdataformat', 'param1', 'param2', 'param3', 'param4', 'param5', 'categoryname', 'categorysortorder');
$csvexport = new \csv_export_writer();
$csvexport->add_data($header);
foreach ($data as $row) {
$arrayrow = (array) $row;
$csvexport->add_data($arrayrow);
}
try {
file_put_contents($filename, $csvexport->print_csv_data(true));
echo "Userfields exported to: " . $filename . "\n";
} catch (Exception $e) {
cli_error("Unable to save file. Check if file {$filename} is writable");
}
}
示例7: execute
public function execute()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/lib.php';
unset($CFG->passwordpolicy);
$options = $this->expandedOptions;
if ($options['all']) {
//run on the whole mdl_user table
$sql = "UPDATE {user} SET ";
$sqlFragment = array();
$parameters = array();
//we want to use the options that were actually provided on the commandline
if ($this->parsedOptions->has('password')) {
$sqlFragment[] = 'password = ?';
$parameters['password'] = md5($this->parsedOptions['password']->value);
}
if ($this->parsedOptions->has('email')) {
$sqlFragment[] = 'email = ?';
$parameters['email'] = $this->parsedOptions['email']->value;
}
if ($this->parsedOptions->has('auth')) {
$sqlFragment[] = 'auth = ?';
$parameters['auth'] = $this->parsedOptions['auth']->value;
}
if (count($sqlFragment) == 0) {
cli_error('You need to provide at least one option for updating a profile field (password or email)');
}
$sql .= implode(' , ', $sqlFragment);
$DB->execute($sql, $parameters);
exit(0);
}
foreach ($this->arguments as $argument) {
if ($options['id']) {
$user = $DB->get_record('user', array('id' => $argument));
} else {
$user = $DB->get_record('user', array('username' => $argument));
}
if (!$user) {
cli_problem("User '{$argument}' not found'");
continue;
}
if ($this->parsedOptions->has('password')) {
$user->password = md5($this->parsedOptions['password']->value);
}
if ($this->parsedOptions->has('email')) {
$user->email = $this->parsedOptions['email']->value;
}
if ($this->parsedOptions->has('auth')) {
$user->auth = $this->parsedOptions['auth']->value;
}
echo $DB->update_record('user', $user) . "\n";
}
}
示例8: execute
public function execute()
{
global $CFG;
//some variables you may want to use
//$this->cwd - the directory where moosh command was executed
//$this->mooshDir - moosh installation directory
//$this->expandedOptions - commandline provided options, merged with defaults
//$this->topDir - top Moodle directory
//$this->arguments[0] - first argument passed
//$this->pluginInfo - array with information about the current plugin (based on cwd), keys:'type','name','dir'
$options = $this->expandedOptions;
//name of the event
$name = $this->arguments[0];
//json serialized data
$data = $this->arguments[1];
$data = json_decode($data, true);
if (!$data) {
cli_error("Could not decode json data.");
}
//load cache file manually as there seems to be no way to get it using Moodle API
$cachefile = "{$CFG->cachedir}/core_component.php";
include $cachefile;
//match the name of the event
//if was used than assume full namespace was given
if (strpos($name, '\\') !== false) {
$fullname = $name;
} else {
$matches = array();
//first look for single match after last \
foreach ($cache['classmap'] as $k => $class) {
if (preg_match("/\\\\{$name}\$/", $k)) {
$matches[] = $k;
}
}
if (count($matches) > 1) {
print_r($matches);
cli_error("More than one matching event");
}
$fullname = $matches[0];
}
$class = $cache['classmap'][$fullname];
if (!$class) {
cli_error("Class '{$fullname}' not found");
}
if ($this->verbose) {
cli_problem("Loading class {$fullname}");
}
$event = $fullname::create($data);
//$event->set_legacy_logdata(array(666, "course", "report log", "report/log/index.php?id=666", 666));
$event->trigger();
}
示例9: execute
public function execute()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/course/lib.php';
$moduleid = intval($this->arguments[0]);
if ($moduleid <= 0) {
cli_error("Argument 'moduleid' must be bigger than 0.");
}
if (!$DB->get_record('course_modules', array('id' => $this->arguments[0]))) {
cli_error("There is no such activity to delete.");
}
course_delete_module($moduleid);
echo "Deleted activity {$moduleid}\n";
}
示例10: execute
public function execute()
{
global $CFG, $DB;
require_once $CFG->libdir . '/csvlib.class.php';
require_once $CFG->libdir . '/moodlelib.php';
$csvfilepath = $this->arguments[0];
if ($csvfilepath[0] != '/') {
$csvfilepath = $this->cwd . DIRECTORY_SEPARATOR . $csvfilepath;
}
$iid = \csv_import_reader::get_new_iid('userprofile');
$type = 'userprofile';
$csvreader = new \csv_import_reader($iid, $type);
if (false === ($csvfile = file_get_contents($csvfilepath))) {
cli_error('Unable to load csv file. ' . error_get_last()['message']);
}
if (!$csvreader->load_csv_content($csvfile, 'utf-8', 'comma')) {
cli_error('Unalbe to parse csv file. ' . $csvreader->get_error());
}
if (!$csvreader->init()) {
cli_error('Unable to initialise csv reading');
}
$columns = $csvreader->get_columns();
$columnsids = array_flip($columns);
while (false !== ($row = $csvreader->next())) {
$category = $this->get_or_create_category($row[$columnsids['categoryname']], $row[$columnsids['categorysortorder']]);
$userfield = new \stdClass();
$userfield->shortname = $row[$columnsids['shortname']];
$userfield->name = $row[$columnsids['name']];
$userfield->datatype = $row[$columnsids['datatype']];
$userfield->description = $row[$columnsids['description']];
$userfield->descriptionformat = $row[$columnsids['descriptionformat']];
$userfield->categoryid = $category->id;
$userfield->sortorder = $row[$columnsids['sortorder']];
$userfield->required = $row[$columnsids['required']];
$userfield->locked = $row[$columnsids['locked']];
$userfield->visible = $row[$columnsids['visible']];
$userfield->forceunique = $row[$columnsids['forceunique']];
$userfield->signup = $row[$columnsids['signup']];
$userfield->defaultdata = $row[$columnsids['defaultdata']];
$userfield->defaultdataformat = $row[$columnsids['defaultdataformat']];
$userfield->param1 = $row[$columnsids['param1']];
$userfield->param2 = $row[$columnsids['param2']];
$userfield->param3 = $row[$columnsids['param3']];
$userfield->param4 = $row[$columnsids['param4']];
$userfield->param5 = $row[$columnsids['param5']];
$this->get_or_create_userfield($userfield);
}
}
示例11: execute
public function execute()
{
//some variables you may want to use
//$this->cwd - the directory where moosh command was executed
//$this->mooshDir - moosh installation directory
//$this->expandedOptions - commandline provided options, merged with defaults
//$this->topDir - top Moodle directory
//$this->arguments[0] - first argument passed
$options = $this->expandedOptions;
//find main version.php
$path = $this->topDir . '/' . $this->pluginInfo['dir'] . '/' . $this->pluginInfo['name'] . '/version.php';
if (!file_exists($path)) {
cli_error("File does not exist: {$path}");
}
if (!is_writeable($path)) {
cli_error("Can't write to the file: {$path}");
}
if ($this->verbose) {
echo "Updating version.php: {$path}\n";
}
//find line like $module->version = 2010032200
//YYYYMMDDXX
$curdate = date('Ymd');
$content = file($path);
foreach ($content as $k => $line) {
if (preg_match('/^\\s*\\$\\w+->version\\s*=\\s*(\\d+)/', $line, $matches)) {
if (strlen($matches[1]) > 10) {
cli_error('Your version is too big, go and bump it yourself');
}
if (substr($matches[1], 0, 8) == $curdate) {
//bump final XX
$xx = substr($matches[1], 8, 2);
$xx++;
if ($xx < 10) {
$xx = '0' . $xx;
}
} else {
$xx = '00';
}
$version = $curdate . $xx;
echo "Bumped from " . $matches[1] . " to {$version}\n";
$content[$k] = preg_replace('/\\d+/', $version, $line, 1);
}
}
file_put_contents($path, $content);
}
示例12: execute
public function execute()
{
global $CFG;
require_once $CFG->dirroot . '/lib/modinfolib.php';
$options = $this->expandedOptions;
if (!isset($this->arguments[0]) && !$options['all']) {
cli_error("Either run with -a for all courses or provide course id as an argument.");
}
if (isset($this->arguments[0])) {
rebuild_course_cache($this->arguments[0]);
echo "Succesfully rebuilt cache for course " . $this->arguments[0] . "\n";
}
if ($options['all']) {
rebuild_course_cache();
exit("Succesfully rebuilt all course caches\n");
}
}
示例13: execute
public function execute()
{
global $CFG;
require_once "{$CFG->libdir}/datalib.php";
$user = get_admin();
if (!$user) {
cli_error("Unable to find admin user in DB.");
}
$auth = empty($user->auth) ? 'manual' : $user->auth;
if ($auth == 'nologin' or !is_enabled_auth($auth)) {
cli_error(sprintf("User authentication is either 'nologin' or disabled. Check Moodle authentication method for '%s'", $user->username));
}
$authplugin = get_auth_plugin($auth);
$authplugin->sync_roles($user);
login_attempt_valid($user);
complete_user_login($user);
printf("%s:%s\n", session_name(), session_id());
}
示例14: execute
public function execute()
{
$filepath = $this->expandedOptions['path'];
$stat = NULL;
if (file_exists($filepath)) {
$stat = stat($filepath);
}
if (!$stat || time() - $stat['mtime'] > 60 * 60 * 24 || !$stat['size']) {
@unlink($filepath);
file_put_contents($filepath, fopen(self::$APIURL, 'r'));
}
$jsonfile = file_get_contents($filepath);
if ($jsonfile === false) {
die("Can't read json file");
}
$data = json_decode($jsonfile);
if (!$data) {
unlink($filepath);
cli_error("Invalid JSON file, deleted {$filepath}. Run command again.");
}
$fulllist = array();
foreach ($data->plugins as $k => $plugin) {
if (!$plugin->component) {
continue;
}
$fulllist[$plugin->component] = array('releases' => array());
foreach ($plugin->versions as $v => $version) {
if ($this->expandedOptions['versions']) {
$fulllist[$plugin->component]['releases'][$version->version] = $version;
} else {
foreach ($version->supportedmoodles as $supportedmoodle) {
$fulllist[$plugin->component]['releases'][$supportedmoodle->release] = $version;
}
}
$fulllist[$plugin->component]['url'] = $version->downloadurl;
}
}
ksort($fulllist);
foreach ($fulllist as $k => $plugin) {
$versions = array_keys($plugin['releases']);
sort($versions);
echo "{$k}," . implode(",", $versions) . "," . $plugin['url'] . "\n";
}
}
示例15: execute
public function execute()
{
$userprofilename = $this->arguments[0];
if (!preg_match('/[^a-z_0-9]/i', $userprofilename)) {
cli_error('Agrument is not valid userprofile name');
}
$userprofilepath = $this->topDir . '/user/profile/field/' . $userprofilename;
if (file_exists($userprofilepath)) {
cli_error("Already exists: '{$userprofilepath}'");
}
run_external_command("cp -r '{$this->mooshDir}/vendor/moodlehq/moodle-user_profile_field' '{$userprofilepath}'", "Copying from module template failed");
if (file_exists("{$userprofilepath}/.git")) {
run_external_command("rm --interactive=never -r '{$userprofilepath}/.git'", "Removing .git failed");
}
// //replace newblock with $this->arguments[0]
run_external_command("find '{$userprofilepath}' -type f -exec sed 's/myprofilefield/{$this->arguments[0]}/g' -i {} \\;", "sed command failed");
//rename lang/en/block_newblock.php
run_external_command("mv '{$userprofilepath}/lang/en/profilefield_myprofilefield.php' '{$userprofilepath}/lang/en/profilefield_{$this->arguments[0]}.php'", "Renaming lang file failed");
}