Commit eaac6e02 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1840195: add function to check if a cron jobs needs to be executed"

parents cdf8353a a6078c49
......@@ -2599,6 +2599,14 @@ function reset_password($user, $resetpasswordchange=true, $quickhash=false) {
}
}
/*
* Check if we need to set any user login tries to 0
*/
function user_login_tries_to_zero_needs_to_run() {
return (bool)count_records_sql("SELECT COUNT(*) FROM {usr} WHERE logintries >= ?", array(MAXLOGINTRIES));
}
function user_login_tries_to_zero() {
execute_sql('UPDATE {usr} SET logintries = 0 WHERE logintries > 0');
}
......
......@@ -1941,6 +1941,8 @@ class LiveUser extends User {
$this->commit();
update_record('usr', (object) array('id' => $user->id, 'logintries' => 0));
// finally, after all is done, call the (maybe non existant) hook on their auth plugin
$authobj = AuthFactory::create($authinstance);
$authobj->login();
......
......@@ -582,6 +582,12 @@ EOF;
return $forums;
}
/*
* Check if we need to process new forum posts
*/
public static function interaction_forum_new_post_needs_to_run() {
return (bool)count_records_sql('SELECT COUNT(*) FROM {interaction_forum_post} WHERE sent = 0 AND deleted = 0 AND approved = 1');
}
/**
* Process new forum posts.
......
......@@ -102,27 +102,35 @@ foreach (plugin_types() as $plugintype) {
$classname = generate_class_name($plugintype, $job->plugin);
log_info("Running $classname::" . $job->callfunction);
safe_require($plugintype, $job->plugin, 'lib.php', 'require_once');
$droptriggers = in_array($job->callfunction, $jobsneeddroptriggers);
if ($droptriggers) {
drop_elasticsearch_triggers();
}
// check if the cron function needs to run on the DB
if (!method_exists($classname, $job->callfunction . '_needs_to_run') ||
call_static_method($classname, $job->callfunction . '_needs_to_run')) {
try {
call_static_method($classname, $job->callfunction);
}
catch (Exception $e) {
log_message($e->getMessage(), LOG_LEVEL_WARN, true, true, $e->getFile(), $e->getLine(), $e->getTrace());
$output = $e instanceof MaharaException ? $e->render_exception() : $e->getMessage();
echo "$output\n";
// Don't call handle_exception; try to update next run time and free the lock
}
log_info("Running $classname::" . $job->callfunction);
if ($droptriggers) {
create_elasticsearch_triggers();
$droptriggers = in_array($job->callfunction, $jobsneeddroptriggers);
if ($droptriggers) {
drop_elasticsearch_triggers();
}
try {
call_static_method($classname, $job->callfunction);
}
catch (Exception $e) {
log_message($e->getMessage(), LOG_LEVEL_WARN, true, true, $e->getFile(), $e->getLine(), $e->getTrace());
$output = $e instanceof MaharaException ? $e->render_exception() : $e->getMessage();
echo "$output\n";
// Don't call handle_exception; try to update next run time and free the lock
}
if ($droptriggers) {
create_elasticsearch_triggers();
}
}
else {
log_info("Skipping: No need to run $classname::" . $job->callfunction);
}
$nextrun = cron_next_run_time($start, (array)$job);
......@@ -173,27 +181,35 @@ if ($jobs) {
continue;
}
log_info("Running core cron " . $job->callfunction);
$function = $job->callfunction;
$droptriggers = in_array($job->callfunction, $jobsneeddroptriggers);
if ($droptriggers) {
drop_elasticsearch_triggers();
}
// check if the cron function needs to run on the DB
$checkfunction = $job->callfunction . '_needs_to_run';
try {
$function();
}
catch (Exception $e) {
log_message($e->getMessage(), LOG_LEVEL_WARN, true, true, $e->getFile(), $e->getLine(), $e->getTrace());
$output = $e instanceof MaharaException ? $e->render_exception() : $e->getMessage();
echo "$output\n";
// Don't call handle_exception; try to update next run time and free the lock
}
if (!function_exists($checkfunction) || $checkfunction()) {
log_info("Running core cron " . $job->callfunction);
$droptriggers = in_array($job->callfunction, $jobsneeddroptriggers);
if ($droptriggers) {
drop_elasticsearch_triggers();
}
if ($droptriggers) {
create_elasticsearch_triggers();
try {
$function();
}
catch (Exception $e) {
log_message($e->getMessage(), LOG_LEVEL_WARN, true, true, $e->getFile(), $e->getLine(), $e->getTrace());
$output = $e instanceof MaharaException ? $e->render_exception() : $e->getMessage();
echo "$output\n";
// Don't call handle_exception; try to update next run time and free the lock
}
if ($droptriggers) {
create_elasticsearch_triggers();
}
}
else {
log_info("Skipping: No need to run " . $job->callfunction);
}
$nextrun = cron_next_run_time($start, (array)$job);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment