Passed
Pull Request — master (#2976)
by Serghei
14:27
created
drupal/sites/default/boinc/modules/contrib/elysia_cron/elysia_cron.module 1 patch
Indentation   +514 added lines, -514 removed lines patch added patch discarded remove patch
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
29 29
 require_once('elysia_cron_scheduler.inc');
30 30
 require_once('elysia_cron.admin.inc');
31 31
 if (EC_DRUPAL_VERSION >= 6) {
32
-  require_once('elysia_cron.ctools.inc');
32
+    require_once('elysia_cron.ctools.inc');
33 33
 }
34 34
 
35 35
 
36 36
 $GLOBALS['elysia_cron_default_rules'] = array(
37
-  '*/15 * * * *' => 'Every 15 minutes',
38
-  '*/30 * * * *' => 'Every 30 minutes',
39
-  '0 * * * *' => 'Every hour',
40
-  '0 */6 * * *' => 'Every 6 hours',
41
-  '4 0 * * *' => 'Once a day',
42
-  '4 0 * * 0' => 'Once a week',
43
-  '4 0 1 * *' => 'Once a month',
37
+    '*/15 * * * *' => 'Every 15 minutes',
38
+    '*/30 * * * *' => 'Every 30 minutes',
39
+    '0 * * * *' => 'Every hour',
40
+    '0 */6 * * *' => 'Every 6 hours',
41
+    '4 0 * * *' => 'Once a day',
42
+    '4 0 * * 0' => 'Once a week',
43
+    '4 0 1 * *' => 'Once a month',
44 44
 );
45 45
 
46 46
 function elysia_cron_version() {
47
-  return 20111020;
47
+    return 20111020;
48 48
 }
49 49
 
50 50
 /*******************************************************************************
@@ -52,84 +52,84 @@  discard block
 block discarded – undo
52 52
  ******************************************************************************/
53 53
 
54 54
 function elysia_cron_menu($_dcr_maycache = true) {
55
-  $items = array();
56
-  $items['admin/config/system/cron'] = array(
55
+    $items = array();
56
+    $items['admin/config/system/cron'] = array(
57 57
     'title' => _dcf_t('Cron Settings'),
58 58
     'description' => _dcf_t('View and manage cron table'),
59 59
     'page callback' => 'elysia_cron_admin_page',
60 60
     'access arguments' => array('administer elysia_cron'),
61
-  );
62
-  $items['admin/config/system/cron/status'] = array(
61
+    );
62
+    $items['admin/config/system/cron/status'] = array(
63 63
     'type' => MENU_DEFAULT_LOCAL_TASK,
64 64
     'title' => _dcf_t('Status'),
65 65
     'weight' => 1,
66
-  );
67
-  $items['admin/config/system/cron/settings'] = array(
66
+    );
67
+    $items['admin/config/system/cron/settings'] = array(
68 68
     'type' => MENU_LOCAL_TASK,
69 69
     'title' => _dcf_t('Settings'),
70 70
     'page callback' => 'drupal_get_form',
71 71
     'page arguments' => array('elysia_cron_settings_form'),
72 72
     'access arguments' => array('administer elysia_cron'),
73 73
     'weight' => 2,
74
-  );
75
-  $items['admin/config/system/cron/maintenance'] = array(
74
+    );
75
+    $items['admin/config/system/cron/maintenance'] = array(
76 76
     'type' => MENU_LOCAL_TASK,
77 77
     'title' => _dcf_t('Maintenance'),
78 78
     'page callback' => 'elysia_cron_maintenance_page',
79 79
     'access arguments' => array('administer elysia_cron'),
80 80
     'weight' => 3,
81
-  );
82
-  $items['admin/config/system/cron/execute'] = array(
81
+    );
82
+    $items['admin/config/system/cron/execute'] = array(
83 83
     'type' => MENU_CALLBACK,
84 84
     'page callback' => 'elysia_cron_execute_page',
85 85
     'access arguments' => array('administer elysia_cron'),
86
-  );
87
-  $items['admin/build/cron/ping'] = array(
86
+    );
87
+    $items['admin/build/cron/ping'] = array(
88 88
     'type' => MENU_CALLBACK,
89 89
     'page callback' => 'elysia_cron_ping_page',
90 90
     'access callback' => TRUE,
91
-  );
92
-  return _dcf_hook_menu($items, $_dcr_maycache);
91
+    );
92
+    return _dcf_hook_menu($items, $_dcr_maycache);
93 93
 }
94 94
 
95 95
 if (EC_DRUPAL_VERSION >= 7) {
96
-  // Override standard cron page
97
-  function elysia_cron_menu_alter(&$items) {
96
+    // Override standard cron page
97
+    function elysia_cron_menu_alter(&$items) {
98 98
     $items['admin/config/system/cron'] = array(
99
-      'title' => _dcf_t('Cron Settings'),
100
-      'description' => 'View and manage cron table',
101
-      'page callback' => 'elysia_cron_admin_page',
102
-      'access arguments' => array('administer elysia_cron'),
99
+        'title' => _dcf_t('Cron Settings'),
100
+        'description' => 'View and manage cron table',
101
+        'page callback' => 'elysia_cron_admin_page',
102
+        'access arguments' => array('administer elysia_cron'),
103 103
     );
104
-  }
104
+    }
105 105
 }
106 106
 
107 107
 function elysia_cron_perm() { // For D5-D6
108
-  return array('administer elysia_cron');
108
+    return array('administer elysia_cron');
109 109
 }
110 110
 function elysia_cron_permission() { // For D7
111
-  return array(
111
+    return array(
112 112
     'administer elysia_cron' => array('title' => t('Administer elysia cron'), 'description' => t('Perform changes to cron jobs timings, disable cron or single jobs and access cron execution statistics')),
113
-  );
113
+    );
114 114
 }
115 115
 
116 116
 function elysia_cron_boot() {
117
-  if (!_dcf_hook_boot('elysia_cron')) {
117
+    if (!_dcf_hook_boot('elysia_cron')) {
118 118
     return;
119
-  }
119
+    }
120 120
 
121
-  if (EC_DRUPAL_VERSION < 7) {
121
+    if (EC_DRUPAL_VERSION < 7) {
122 122
     global $conf;
123 123
 
124 124
     // I need to set cron_semaphore always to false. That way standard drupal cron is always bypassed
125 125
     $conf['cron_semaphore'] = false;
126
-  }
126
+    }
127 127
 }
128 128
 
129 129
 function elysia_cron_init() {
130
-  if (!_dcf_hook_init('elysia_cron')) {
130
+    if (!_dcf_hook_init('elysia_cron')) {
131 131
     return;
132
-  }
132
+    }
133 133
 }
134 134
 
135 135
 /**
@@ -137,35 +137,35 @@  discard block
 block discarded – undo
137 137
  * It's used to replace drupal cron.
138 138
  */
139 139
 function elysia_cron_cron() {
140
-  // First cron run is executed in standard drupal way. This is to enable the use of install profiles
141
-  if (variable_get('cron_last', 0) == 0) {
140
+    // First cron run is executed in standard drupal way. This is to enable the use of install profiles
141
+    if (variable_get('cron_last', 0) == 0) {
142 142
     return;
143
-  }
144
-  // If the path is 'admin/*' this is a manual cron run (probably by admin/logs/status)
145
-  $manual_run = (arg(0) == 'admin');
143
+    }
144
+    // If the path is 'admin/*' this is a manual cron run (probably by admin/logs/status)
145
+    $manual_run = (arg(0) == 'admin');
146 146
 
147
-  $result = elysia_cron_run($manual_run);
147
+    $result = elysia_cron_run($manual_run);
148 148
 
149
-  if (EC_DRUPAL_VERSION < 7) {
149
+    if (EC_DRUPAL_VERSION < 7) {
150 150
     // I must check for cron_semaphore and delete it if set (is not always deleted by elysia_cron_run, and this situation is only when called by drupal cron, so a check here is right)
151 151
     if (variable_get('cron_semaphore', false)) {
152
-      global $conf;
153
-      _ec_variable_del('cron_semaphore');
154
-      $conf['cron_semaphore'] = false;
152
+        global $conf;
153
+        _ec_variable_del('cron_semaphore');
154
+        $conf['cron_semaphore'] = false;
155
+    }
155 156
     }
156
-  }
157 157
 
158
-  if ($manual_run) {
158
+    if ($manual_run) {
159 159
     if ($result) {
160
-      drupal_set_message(t('Cron ran successfully'));
160
+        drupal_set_message(t('Cron ran successfully'));
161 161
     }
162 162
     else {
163
-      drupal_set_message(t('Cron run failed, disabled or nothing to do'));
163
+        drupal_set_message(t('Cron run failed, disabled or nothing to do'));
164 164
     }
165 165
     drupal_goto(_dcf_internal_path('admin/reports/status'));
166
-  }
166
+    }
167 167
 
168
-  exit();
168
+    exit();
169 169
 }
170 170
 
171 171
 /**
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
  * If it's not i'll set it and print a message
175 175
  */
176 176
 function elysia_cron_help($section, $arg = false) {
177
-  if ($section == _dcf_internal_path('admin/modules')) {
177
+    if ($section == _dcf_internal_path('admin/modules')) {
178 178
     $min = drupal_module_get_min_weight('elysia_cron');
179 179
     $weight = drupal_module_get_weight('elysia_cron');
180 180
     if ($min <= $weight) {
181
-      drupal_set_message(t('Elysia cron module is not the module with the smallest weight (and it must be). Updating weight...'));
182
-      drupal_module_set_weight('elysia_cron', $min - 1);
181
+        drupal_set_message(t('Elysia cron module is not the module with the smallest weight (and it must be). Updating weight...'));
182
+        drupal_module_set_weight('elysia_cron', $min - 1);
183
+    }
183 184
     }
184
-  }
185 185
 }
186 186
 
187 187
 /*******************************************************************************
@@ -192,30 +192,30 @@  discard block
 block discarded – undo
192 192
 
193 193
 // Variables managed by _ec_variable method, because are setted during cron execution handling (with standard variable_set this will invalidate variable cache in EVERY cron clock)
194 194
 $GLOBALS['_ec_variables_allowed'] = array(
195
-  'elysia_cron_version', // Just for compatibility purpose during elysia_cron_update phase
196
-  'elysia_cron_semaphore', 
197
-  'elysia_cron_last_run',
198
-  'elysia_cron_last_context', 
199
-  'cron_semaphore', 
200
-  'cron_last',
195
+    'elysia_cron_version', // Just for compatibility purpose during elysia_cron_update phase
196
+    'elysia_cron_semaphore', 
197
+    'elysia_cron_last_run',
198
+    'elysia_cron_last_context', 
199
+    'cron_semaphore', 
200
+    'cron_last',
201 201
 );
202 202
 
203 203
 $GLOBALS['_ec_columns'] = array(
204
-  'name', ' disable', ' rule', ' weight', ' context', ' running', ' last_run', ' last_aborted', ' abort_count', ' last_abort_function', ' last_execution_time', ' execution_count', ' avg_execution_time', ' max_execution_time', ' last_shutdown_time'
204
+    'name', ' disable', ' rule', ' weight', ' context', ' running', ' last_run', ' last_aborted', ' abort_count', ' last_abort_function', ' last_execution_time', ' execution_count', ' avg_execution_time', ' max_execution_time', ' last_shutdown_time'
205 205
 );
206 206
  
207 207
 function _ec_variable_init() {
208
-  global $_ec_variables, $_ec_variables_allowed;
209
-  $_ec_variables = array();
210
-  if (EC_DRUPAL_VERSION >= 7) {
208
+    global $_ec_variables, $_ec_variables_allowed;
209
+    $_ec_variables = array();
210
+    if (EC_DRUPAL_VERSION >= 7) {
211 211
     $_ec_variables = array_map('unserialize', db_query("SELECT name, value FROM {variable} where name like '" . implode("' or name like '", $_ec_variables_allowed) . "'")->fetchAllKeyed());
212
-  }
213
-  else {
212
+    }
213
+    else {
214 214
     $result = db_query("select * from {variable} where name like '" . implode("' or name like '", $_ec_variables_allowed) . "'");
215 215
     while ($variable = db_fetch_object($result)) {
216
-      $_ec_variables[$variable->name] = unserialize($variable->value);
216
+        $_ec_variables[$variable->name] = unserialize($variable->value);
217
+    }
217 218
     }
218
-  }
219 219
 }
220 220
 
221 221
 /**
@@ -224,27 +224,27 @@  discard block
 block discarded – undo
224 224
  * WARN_UPGRADE
225 225
  */
226 226
 function _ec_variable_get($name, $default) {
227
-  global $_ec_variables, $_ec_variables_allowed;
228
-  if (!in_array($name, $_ec_variables_allowed)) {
227
+    global $_ec_variables, $_ec_variables_allowed;
228
+    if (!in_array($name, $_ec_variables_allowed)) {
229 229
     _dco_watchdog('cron', 'Wrong variable passed to _ec_variable_get: !var', array('!var' => $name), WATCHDOG_ERROR);
230 230
     return variable_get($name, $default);
231
-  }
231
+    }
232 232
 
233
-  if (!is_array($_ec_variables)) {
233
+    if (!is_array($_ec_variables)) {
234 234
     _ec_variable_init();
235
-  }
235
+    }
236 236
 
237
-  // If there is a $GLOBALS['original_conf'] = $conf; at the end of  settings.php i consider it.
238
-  global $original_conf;
237
+    // If there is a $GLOBALS['original_conf'] = $conf; at the end of  settings.php i consider it.
238
+    global $original_conf;
239 239
 
240
-  if (isset($original_conf[$name])) {
240
+    if (isset($original_conf[$name])) {
241 241
     return $original_conf[$name];
242
-  }
243
-  if (isset($_ec_variables[$name])) {
242
+    }
243
+    if (isset($_ec_variables[$name])) {
244 244
     return $_ec_variables[$name];
245
-  }
245
+    }
246 246
 
247
-  return $default;
247
+    return $default;
248 248
 }
249 249
 
250 250
 /**
@@ -253,33 +253,33 @@  discard block
 block discarded – undo
253 253
  * WARN_UPGRADE
254 254
  */
255 255
 function _ec_variable_set($name, $value) {
256
-  global $_ec_variables, $_ec_variables_allowed;
257
-  if (!in_array($name, $_ec_variables_allowed)) {
256
+    global $_ec_variables, $_ec_variables_allowed;
257
+    if (!in_array($name, $_ec_variables_allowed)) {
258 258
     _dco_watchdog('cron', 'Wrong variable passed to _ec_variable_set: !var', array('!var' => $name), WATCHDOG_ERROR);
259 259
     return variable_set($name, $value);
260
-  }
260
+    }
261 261
 
262
-  if (!is_array($_ec_variables)) {
262
+    if (!is_array($_ec_variables)) {
263 263
     _ec_variable_init();
264
-  }
264
+    }
265 265
 
266
-  if (EC_DRUPAL_VERSION >= 7) {
266
+    if (EC_DRUPAL_VERSION >= 7) {
267 267
     db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();
268 268
 
269
-  }
270
-  else {
269
+    }
270
+    else {
271 271
     if (!variable_get('elysia_cron_alternate_var_handler', false)) {
272
-      db_lock_table('variable');
273
-      db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
274
-      db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
275
-      db_unlock_tables();
272
+        db_lock_table('variable');
273
+        db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
274
+        db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
275
+        db_unlock_tables();
276 276
     }
277 277
     else {
278
-      db_query("REPLACE INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
278
+        db_query("REPLACE INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
279
+    }
279 280
     }
280
-  }
281 281
 
282
-  $_ec_variables[$name] = $value;
282
+    $_ec_variables[$name] = $value;
283 283
 }
284 284
 
285 285
 /**
@@ -288,38 +288,38 @@  discard block
 block discarded – undo
288 288
  * WARN_UPGRADE
289 289
  */
290 290
 function _ec_variable_del($name) {
291
-  global $_ec_variables, $_ec_variables_allowed;
292
-  if (!in_array($name, $_ec_variables_allowed)) {
291
+    global $_ec_variables, $_ec_variables_allowed;
292
+    if (!in_array($name, $_ec_variables_allowed)) {
293 293
     _dco_watchdog('cron', 'Wrong variable passed to _ec_variable_del: !var', array('!var' => $name), WATCHDOG_ERROR);
294 294
     return variable_del($name);
295
-  }
295
+    }
296 296
 
297
-  if (!is_array($_ec_variables)) {
297
+    if (!is_array($_ec_variables)) {
298 298
     _ec_variable_init();
299
-  }
299
+    }
300 300
 
301
-  if (EC_DRUPAL_VERSION >= 7) {
301
+    if (EC_DRUPAL_VERSION >= 7) {
302 302
     db_delete('variable')->condition('name', $name)->execute();
303 303
 
304
-  }
305
-  else {
304
+    }
305
+    else {
306 306
     if (!variable_get('elysia_cron_alternate_var_handler', false)) {
307
-      db_lock_table('variable');
308
-      db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
309
-      db_unlock_tables();
307
+        db_lock_table('variable');
308
+        db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
309
+        db_unlock_tables();
310 310
     }
311 311
     else {
312
-      db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
312
+        db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
313
+    }
313 314
     }
314
-  }
315 315
 
316
-  unset($_ec_variables[$name]);
316
+    unset($_ec_variables[$name]);
317 317
 }
318 318
 
319 319
 if (EC_DRUPAL_VERSION < 7) {
320
-  function _ec_semaphore_get($name = 'elysia_cron_semaphore', $timeout = 120) {
320
+    function _ec_semaphore_get($name = 'elysia_cron_semaphore', $timeout = 120) {
321 321
     if (function_exists('elysia_cron_semaphore_get_alternative')) {
322
-      return elysia_cron_semaphore_get_alternative($name, $timeout);
322
+        return elysia_cron_semaphore_get_alternative($name, $timeout);
323 323
     }
324 324
 
325 325
     db_lock_table('variable');
@@ -328,194 +328,194 @@  discard block
 block discarded – undo
328 328
 
329 329
     $stuck = $semglob && (time() - $semglob > $timeout);
330 330
     if ($stuck || !$semglob) {
331
-      db_query("DELETE FROM {variable} WHERE name = '%s'", 'elysia_cron_semaphore');
332
-      db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'elysia_cron_semaphore', serialize(time()));
333
-      $semglob = false; // We must return TRUE
331
+        db_query("DELETE FROM {variable} WHERE name = '%s'", 'elysia_cron_semaphore');
332
+        db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'elysia_cron_semaphore', serialize(time()));
333
+        $semglob = false; // We must return TRUE
334 334
     }
335 335
     db_unlock_tables();
336 336
 
337 337
     if ($stuck) {
338
-      _dco_watchdog('cron', 'Global semaphore has been active for more than 2 minutes, probably stuck, reset.', array(), WATCHDOG_ERROR);
338
+        _dco_watchdog('cron', 'Global semaphore has been active for more than 2 minutes, probably stuck, reset.', array(), WATCHDOG_ERROR);
339 339
     }
340 340
 
341 341
     return !$semglob;
342
-  }
342
+    }
343 343
 }
344 344
 
345 345
 function _ec_get_name($name) {
346
-  $maxlen = EC_DRUPAL_VERSION >= 6 ? 120 : 40;
347
-  if (strlen($name) < $maxlen) {
346
+    $maxlen = EC_DRUPAL_VERSION >= 6 ? 120 : 40;
347
+    if (strlen($name) < $maxlen) {
348 348
     return $name;
349
-  }
350
-  $border = ($maxlen - 32) / 2;
351
-  return substr($name, 0, $border) . md5($name) . substr($name, -$border);
349
+    }
350
+    $border = ($maxlen - 32) / 2;
351
+    return substr($name, 0, $border) . md5($name) . substr($name, -$border);
352 352
 }
353 353
 
354 354
 function elysia_cron_set($name, $channel = false, $values = array()) {
355
-  if ($channel) {
355
+    if ($channel) {
356 356
     $name = ':' . $name;
357
-  }
357
+    }
358 358
 
359
-  if (EC_DRUPAL_VERSION >= 7) {
359
+    if (EC_DRUPAL_VERSION >= 7) {
360 360
     db_merge('elysia_cron')->key(array('name' => $name))->fields($values)->execute();
361 361
     
362
-  } else {
362
+    } else {
363 363
     $fields = array("name" => "'%s'", "disable" => "%d", "rule" => "'%s'", "weight" => "%d", "context" => "'%s'", "running" => "%d", "last_run" => "%d", "last_aborted" => "%d", "abort_count" => "%d", "last_abort_function" => "'%s'", "last_execution_time" => "%d", "execution_count" => "%d", "avg_execution_time" => "%f", "max_execution_time" => "%d", "last_shutdown_time" => "%d");
364 364
     $ifields = array('disable', 'running', 'last_run', 'last_aborted', 'abort_count', 'last_execution_time', 'execution_count', 'avg_execution_time', 'max_execution_time', 'last_shutdown_time');
365 365
     
366 366
     if (db_result(db_query('SELECT 1 FROM {elysia_cron} WHERE name = "%s"', $name))) {
367
-      $uquery = array();
368
-      $uvalues = array();
369
-      foreach ($values as $k => $v) {
367
+        $uquery = array();
368
+        $uvalues = array();
369
+        foreach ($values as $k => $v) {
370 370
         if (is_null($v) && !in_array($k, $ifields)) {
371
-          $uquery[] =  $k . ' = NULL';
371
+            $uquery[] =  $k . ' = NULL';
372 372
         }
373 373
         else {
374
-          $uquery[] =  $k . ' = ' . $fields[$k];
375
-          $uvalues[] = $v;
374
+            $uquery[] =  $k . ' = ' . $fields[$k];
375
+            $uvalues[] = $v;
376 376
         }
377
-      }
378
-      $uvalues[] = $name;
377
+        }
378
+        $uvalues[] = $name;
379 379
   
380
-      db_query("update {elysia_cron} set " . implode(', ', $uquery) . " where name = '%s'", $uvalues);
380
+        db_query("update {elysia_cron} set " . implode(', ', $uquery) . " where name = '%s'", $uvalues);
381 381
       
382 382
     } else {
383
-      foreach ($ifields as $f) {
383
+        foreach ($ifields as $f) {
384 384
         if (empty($values[$f])) {
385
-          $values[$f] = 0;
385
+            $values[$f] = 0;
386
+        }
386 387
         }
387
-      }
388
-      $values['name'] = $name;
388
+        $values['name'] = $name;
389 389
 
390
-      $iquery1 = array();
391
-      $iquery2 = array();
392
-      $ivalues = array();
393
-      foreach ($values as $k => $v) {
390
+        $iquery1 = array();
391
+        $iquery2 = array();
392
+        $ivalues = array();
393
+        foreach ($values as $k => $v) {
394 394
         if (!is_null($v)) {
395
-          $iquery1[] = $k;
396
-          $iquery2[] = $fields[$k];
397
-          $ivalues[] = $v;
395
+            $iquery1[] = $k;
396
+            $iquery2[] = $fields[$k];
397
+            $ivalues[] = $v;
398
+        }
398 399
         }
399
-      }
400 400
 
401
-      db_query("insert into {elysia_cron} (" . implode(', ', $iquery1) . ") values (" . implode(', ', $iquery2) . ")", $ivalues);
401
+        db_query("insert into {elysia_cron} (" . implode(', ', $iquery1) . ") values (" . implode(', ', $iquery2) . ")", $ivalues);
402
+    }
402 403
     }
403
-  }
404 404
 
405
-  global $elysia_cron_db_cache;
405
+    global $elysia_cron_db_cache;
406 406
 
407
-  unset($elysia_cron_db_cache[$name]);
407
+    unset($elysia_cron_db_cache[$name]);
408 408
 }
409 409
 
410 410
 function elysia_cron_get($name, $channel = false, $key, $default, $refresh = false) {
411
-  global $elysia_cron_db_cache;
412
-  static $elysia_cron_defaults;
411
+    global $elysia_cron_db_cache;
412
+    static $elysia_cron_defaults;
413 413
   
414
-  if (!isset($elysia_cron_defaults)) {
414
+    if (!isset($elysia_cron_defaults)) {
415 415
     $elysia_cron_defaults = function_exists('elysia_cron_get_ctools_defaults') ? elysia_cron_get_ctools_defaults() : array();
416
-  }
416
+    }
417 417
 
418
-  if ($channel) {
418
+    if ($channel) {
419 419
     $name = ':' . $name;
420
-  }
420
+    }
421 421
   
422
-  if ($refresh || !isset($elysia_cron_db_cache[$name])) {
422
+    if ($refresh || !isset($elysia_cron_db_cache[$name])) {
423 423
     if (EC_DRUPAL_VERSION >= 7) {
424
-      $elysia_cron_db_cache[$name] = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = :name", array(':name' => $name))->fetchAssoc();
424
+        $elysia_cron_db_cache[$name] = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = :name", array(':name' => $name))->fetchAssoc();
425 425
     }
426 426
     else {
427
-      $elysia_cron_db_cache[$name] = db_fetch_array(db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = '%s'", $name));
427
+        $elysia_cron_db_cache[$name] = db_fetch_array(db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = '%s'", $name));
428 428
     }
429 429
     
430 430
     if (!$elysia_cron_db_cache[$name] && isset($elysia_cron_defaults[$name])) {
431
-      $elysia_cron_db_cache[$name] = (array)$elysia_cron_defaults[$name];
431
+        $elysia_cron_db_cache[$name] = (array)$elysia_cron_defaults[$name];
432 432
     }
433 433
     elseif ($elysia_cron_db_cache[$name] && isset($elysia_cron_defaults[$name])) {
434
-      foreach($elysia_cron_defaults[$name] as $k => $v) {
434
+        foreach($elysia_cron_defaults[$name] as $k => $v) {
435 435
         if (!isset($elysia_cron_db_cache[$name][$k]) || is_null($elysia_cron_db_cache[$name][$k])) {
436
-          $elysia_cron_db_cache[$name][$k] = $v;
436
+            $elysia_cron_db_cache[$name][$k] = $v;
437
+        }
437 438
         }
438
-      }
439 439
     }
440
-  }
440
+    }
441 441
 
442
-  return !$elysia_cron_db_cache[$name] || !isset($elysia_cron_db_cache[$name][$key]) || is_null($elysia_cron_db_cache[$name][$key]) ? $default : $elysia_cron_db_cache[$name][$key];
442
+    return !$elysia_cron_db_cache[$name] || !isset($elysia_cron_db_cache[$name][$key]) || is_null($elysia_cron_db_cache[$name][$key]) ? $default : $elysia_cron_db_cache[$name][$key];
443 443
 }
444 444
 
445 445
 function elysia_cron_is_channel_disabled($channel, $default = false, $refresh = false) {
446
-  // May be overriden by a static conf
447
-  if (isset($GLOBALS['conf'][$n = 'ecc_' . _ec_get_name($channel) . '_d'])) {
446
+    // May be overriden by a static conf
447
+    if (isset($GLOBALS['conf'][$n = 'ecc_' . _ec_get_name($channel) . '_d'])) {
448 448
     return $GLOBALS['conf'][$n];
449
-  }
450
-  return elysia_cron_get($channel, true, 'disable', $default, $refresh);
449
+    }
450
+    return elysia_cron_get($channel, true, 'disable', $default, $refresh);
451 451
 }
452 452
 
453 453
 function elysia_cron_set_channel_disabled($channel, $v) {
454
-  return elysia_cron_set($channel, true, array('disable' => $v ? 1 : 0));
454
+    return elysia_cron_set($channel, true, array('disable' => $v ? 1 : 0));
455 455
 }
456 456
 
457 457
 function elysia_cron_reset_channel_disabled($channel) {
458
-  return elysia_cron_set($channel, true, array('disable' => 0));
458
+    return elysia_cron_set($channel, true, array('disable' => 0));
459 459
 }
460 460
 
461 461
 function elysia_cron_get_channel_rule($channel, $default = '', $refresh = false) {
462
-  // May be overriden by a static conf
463
-  if (isset($GLOBALS['conf'][$n = 'ecc_' . _ec_get_name($channel) . '_rul'])) {
462
+    // May be overriden by a static conf
463
+    if (isset($GLOBALS['conf'][$n = 'ecc_' . _ec_get_name($channel) . '_rul'])) {
464 464
     return $GLOBALS['conf'][$n];
465
-  }
466
-  return elysia_cron_get($channel, true, 'rule', $default, $refresh);
465
+    }
466
+    return elysia_cron_get($channel, true, 'rule', $default, $refresh);
467 467
 }
468 468
 
469 469
 function elysia_cron_set_channel_rule($channel, $v) {
470
-  return elysia_cron_set($channel, true, array('rule' => $v));
470
+    return elysia_cron_set($channel, true, array('rule' => $v));
471 471
 }
472 472
 
473 473
 function elysia_cron_reset_channel_rule($channel) {
474
-  return elysia_cron_set($channel, true, array('rule' => NULL));
474
+    return elysia_cron_set($channel, true, array('rule' => NULL));
475 475
 }
476 476
 
477 477
 function elysia_cron_is_channel_running($channel, $default = 0, $refresh = false) {
478
-  return elysia_cron_get($channel, true, 'running', $default, $refresh);
478
+    return elysia_cron_get($channel, true, 'running', $default, $refresh);
479 479
 }
480 480
 
481 481
 function elysia_cron_set_channel_running($channel, $v) {
482
-  return elysia_cron_set($channel, true, array('running' => $v));
482
+    return elysia_cron_set($channel, true, array('running' => $v));
483 483
 }
484 484
 
485 485
 function elysia_cron_get_channel_last_run($channel, $default = false, $refresh = false) {
486
-  return elysia_cron_get($channel, true, 'last_run', $default, $refresh);
486
+    return elysia_cron_get($channel, true, 'last_run', $default, $refresh);
487 487
 }
488 488
 
489 489
 function elysia_cron_set_channel_last_run($channel, $v) {
490
-  return elysia_cron_set($channel, true, array('last_run' => $v));
490
+    return elysia_cron_set($channel, true, array('last_run' => $v));
491 491
 }
492 492
 
493 493
 function elysia_cron_get_channel_last_aborted($channel, $default = 0, $refresh = false) {
494
-  return elysia_cron_get($channel, true, 'last_aborted', $default, $refresh);
494
+    return elysia_cron_get($channel, true, 'last_aborted', $default, $refresh);
495 495
 }
496 496
 
497 497
 function elysia_cron_set_channel_last_aborted($channel, $v) {
498
-  return elysia_cron_set($channel, true, array('last_aborted' => $v ? 1 : 0));
498
+    return elysia_cron_set($channel, true, array('last_aborted' => $v ? 1 : 0));
499 499
 }
500 500
 
501 501
 function elysia_cron_get_channel_abort_count($channel, $default = 0, $refresh = false) {
502
-  return elysia_cron_get($channel, true, 'abort_count', $default, $refresh);
502
+    return elysia_cron_get($channel, true, 'abort_count', $default, $refresh);
503 503
 }
504 504
 
505 505
 function elysia_cron_set_channel_abort_count($channel, $v) {
506
-  return elysia_cron_set($channel, true, array('abort_count' => $v));
506
+    return elysia_cron_set($channel, true, array('abort_count' => $v));
507 507
 }
508 508
 
509 509
 function elysia_cron_get_channel_last_abort_function($channel, $default = '', $refresh = false) {
510
-  return elysia_cron_get($channel, true, 'last_abort_function', $default, $refresh);
510
+    return elysia_cron_get($channel, true, 'last_abort_function', $default, $refresh);
511 511
 }
512 512
 
513 513
 function elysia_cron_set_channel_last_abort_function($channel, $job) {
514
-  return elysia_cron_set($channel, true, array('last_abort_function' => $v));
514
+    return elysia_cron_set($channel, true, array('last_abort_function' => $v));
515 515
 }
516 516
 
517 517
 function elysia_cron_get_channel_stats($channel, $refresh = false) {
518
-  return array(
518
+    return array(
519 519
     'last_run' => elysia_cron_get($channel, true, 'last_run', 0, $refresh),
520 520
     'last_execution_time' => elysia_cron_get($channel, true, 'last_execution_time', 0, $refresh),
521 521
     'execution_count' => elysia_cron_get($channel, true, 'execution_count', 0, $refresh),
@@ -525,174 +525,174 @@  discard block
 block discarded – undo
525 525
     'last_aborted' => elysia_cron_get($channel, true, 'last_aborted', 0, $refresh),
526 526
     'abort_count' => elysia_cron_get($channel, true, 'abort_count', 0, $refresh),
527 527
     'last_abort_function' => elysia_cron_get($channel, true, 'last_abort_function', 0, ''),
528
-  );
528
+    );
529 529
 }
530 530
 
531 531
 function elysia_cron_set_channel_stats($channel, $last_run = -1, $last_execution_time = -1, $execution_count = -1,
532 532
     $avg_execution_time = -1, $max_execution_time = -1, $last_shutdown_time = -1, $last_aborted = -1,
533 533
     $abort_count = -1, $last_abort_function = -1, $data = array()) {
534
-  if ($last_run != -1) {
534
+    if ($last_run != -1) {
535 535
     $data['last_run'] = $last_run;
536
-  }
537
-  if ($last_execution_time != -1) {
536
+    }
537
+    if ($last_execution_time != -1) {
538 538
     $data['last_execution_time'] = $last_execution_time;
539
-  }
540
-  if ($execution_count != -1) {
539
+    }
540
+    if ($execution_count != -1) {
541 541
     $data['execution_count'] = $execution_count;
542
-  }
543
-  if ($avg_execution_time != -1) {
542
+    }
543
+    if ($avg_execution_time != -1) {
544 544
     $data['avg_execution_time'] = $avg_execution_time;
545
-  }
546
-  if ($max_execution_time != -1) {
545
+    }
546
+    if ($max_execution_time != -1) {
547 547
     $data['max_execution_time'] = $max_execution_time;
548
-  }
549
-  if ($last_shutdown_time != -1) {
548
+    }
549
+    if ($last_shutdown_time != -1) {
550 550
     $data['last_shutdown_time'] = $last_shutdown_time;
551
-  }
552
-  if ($last_aborted != -1) {
551
+    }
552
+    if ($last_aborted != -1) {
553 553
     $data['last_aborted'] = $last_aborted;
554
-  }
555
-  if ($abort_count != -1) {
554
+    }
555
+    if ($abort_count != -1) {
556 556
     $data['abort_count'] = $abort_count;
557
-  }
558
-  if ($last_abort_function != -1) {
557
+    }
558
+    if ($last_abort_function != -1) {
559 559
     $data['last_abort_function'] = $last_abort_function;
560
-  }
561
-  elysia_cron_set($channel, true, $data);
560
+    }
561
+    elysia_cron_set($channel, true, $data);
562 562
 }
563 563
 
564 564
 function elysia_cron_get_job_rule($job, $default = '', $refresh = false) {
565
-  // May be overriden by a static conf
566
-  if (isset($GLOBALS['conf'][$n = 'ec_' . _ec_get_name($job) . '_rul'])) {
565
+    // May be overriden by a static conf
566
+    if (isset($GLOBALS['conf'][$n = 'ec_' . _ec_get_name($job) . '_rul'])) {
567 567
     return $GLOBALS['conf'][$n];
568
-  }
569
-  return elysia_cron_get($job, false, 'rule', $default, $refresh);
568
+    }
569
+    return elysia_cron_get($job, false, 'rule', $default, $refresh);
570 570
 }
571 571
 
572 572
 function elysia_cron_set_job_rule($job, $v) {
573
-  return elysia_cron_set($job, false, array('rule' => $v));
573
+    return elysia_cron_set($job, false, array('rule' => $v));
574 574
 }
575 575
 
576 576
 function elysia_cron_reset_job_rule($job) {
577
-  return elysia_cron_set($job, false, array('rule' => null));
577
+    return elysia_cron_set($job, false, array('rule' => null));
578 578
 }
579 579
 
580 580
 function elysia_cron_get_job_weight($job, $default = '', $refresh = false) {
581
-  // May be overriden by a static conf
582
-  if (isset($GLOBALS['conf'][$n = 'ec_' . _ec_get_name($job) . '_w'])) {
581
+    // May be overriden by a static conf
582
+    if (isset($GLOBALS['conf'][$n = 'ec_' . _ec_get_name($job) . '_w'])) {
583 583
     return $GLOBALS['conf'][$n];
584
-  }
585
-  return elysia_cron_get($job, false, 'weight', $default, $refresh);
584
+    }
585
+    return elysia_cron_get($job, false, 'weight', $default, $refresh);
586 586
 }
587 587
 
588 588
 function elysia_cron_set_job_weight($job, $v) {
589
-  return elysia_cron_set($job, false, array('weight' => $v));
589
+    return elysia_cron_set($job, false, array('weight' => $v));
590 590
 }
591 591
 
592 592
 function elysia_cron_reset_job_weight($job) {
593
-  return elysia_cron_set($job, false, array('weight' => null));
593
+    return elysia_cron_set($job, false, array('weight' => null));
594 594
 }
595 595
 
596 596
 function elysia_cron_is_job_disabled($job, $default = false, $refresh = false) {
597
-  // May be overriden by a static conf
598
-  if (isset($GLOBALS['conf'][$n = 'ec_' . _ec_get_name($job) . '_d'])) {
597
+    // May be overriden by a static conf
598
+    if (isset($GLOBALS['conf'][$n = 'ec_' . _ec_get_name($job) . '_d'])) {
599 599
     return $GLOBALS['conf'][$n];
600
-  }
601
-  return elysia_cron_get($job, false, 'disable', $default, $refresh);
600
+    }
601
+    return elysia_cron_get($job, false, 'disable', $default, $refresh);
602 602
 }
603 603
 
604 604
 function elysia_cron_set_job_disabled($job, $v) {
605
-  return elysia_cron_set($job, false, array('disable' => $v ? 1 : 0));
605
+    return elysia_cron_set($job, false, array('disable' => $v ? 1 : 0));
606 606
 }
607 607
 
608 608
 function elysia_cron_reset_job_disabled($job) {
609
-  return elysia_cron_set($job, false, array('disable' => null));
609
+    return elysia_cron_set($job, false, array('disable' => null));
610 610
 }
611 611
 
612 612
 function elysia_cron_get_job_channel($job, $default = '', $refresh = false) {
613
-  // May be overriden by a static conf
614
-  if (isset($GLOBALS['conf'][$n = 'ec_' . _ec_get_name($job) . '_c'])) {
613
+    // May be overriden by a static conf
614
+    if (isset($GLOBALS['conf'][$n = 'ec_' . _ec_get_name($job) . '_c'])) {
615 615
     $c = $GLOBALS['conf'][$n];
616
-  }
617
-  else {
616
+    }
617
+    else {
618 618
     $c = elysia_cron_get($job, false, 'context', $default, $refresh);
619
-  }
620
-  return !$c ? $default : $c;
619
+    }
620
+    return !$c ? $default : $c;
621 621
 }
622 622
 
623 623
 function elysia_cron_set_job_channel($job, $v) {
624
-  return elysia_cron_set($job, false, array('context' => $v));
624
+    return elysia_cron_set($job, false, array('context' => $v));
625 625
 }
626 626
 
627 627
 function elysia_cron_reset_job_channel($job) {
628
-  return elysia_cron_set($job, false, array('context' => null));
628
+    return elysia_cron_set($job, false, array('context' => null));
629 629
 }
630 630
 
631 631
 function elysia_cron_is_job_running($job, $default = 0, $refresh = false) {
632
-  return elysia_cron_get($job, false, 'running', $default, $refresh);
632
+    return elysia_cron_get($job, false, 'running', $default, $refresh);
633 633
 }
634 634
 
635 635
 function elysia_cron_set_job_running($job, $v) {
636
-  return elysia_cron_set($job, false, array('running' => $v));
636
+    return elysia_cron_set($job, false, array('running' => $v));
637 637
 }
638 638
 
639 639
 function elysia_cron_get_job_last_run($job, $default = 0, $refresh = false) {
640
-  return elysia_cron_get($job, false, 'last_run', $default, $refresh);
640
+    return elysia_cron_get($job, false, 'last_run', $default, $refresh);
641 641
 }
642 642
 
643 643
 function elysia_cron_set_job_last_run($job, $v) {
644
-  return elysia_cron_set($job, false, array('last_run' => $v));
644
+    return elysia_cron_set($job, false, array('last_run' => $v));
645 645
 }
646 646
 
647 647
 function elysia_cron_get_job_stats($job, $refresh = false) {
648
-  return array(
648
+    return array(
649 649
     'last_run' => elysia_cron_get($job, false, 'last_run', 0, $refresh),
650 650
     'last_execution_time' => elysia_cron_get($job, false, 'last_execution_time', 0, $refresh),
651 651
     'execution_count' => elysia_cron_get($job, false, 'execution_count', 0, $refresh),
652 652
     'avg_execution_time' => elysia_cron_get($job, false, 'avg_execution_time', 0, $refresh),
653 653
     'max_execution_time' => elysia_cron_get($job, false, 'max_execution_time', 0, $refresh),
654
-  );
654
+    );
655 655
 }
656 656
 
657 657
 function elysia_cron_set_job_stats($job, $last_run = -1, $last_execution_time = -1, $execution_count = -1,
658
-  $avg_execution_time = -1, $max_execution_time = -1, $data = array()) {
659
-  if ($last_run != -1) {
658
+    $avg_execution_time = -1, $max_execution_time = -1, $data = array()) {
659
+    if ($last_run != -1) {
660 660
     $data['last_run'] = $last_run;
661
-  }
662
-  if ($last_execution_time != -1) {
661
+    }
662
+    if ($last_execution_time != -1) {
663 663
     $data['last_execution_time'] = $last_execution_time;
664
-  }
665
-  if ($execution_count != -1) {
664
+    }
665
+    if ($execution_count != -1) {
666 666
     $data['execution_count'] = $execution_count;
667
-  }
668
-  if ($avg_execution_time != -1) {
667
+    }
668
+    if ($avg_execution_time != -1) {
669 669
     $data['avg_execution_time'] = $avg_execution_time;
670
-  }
671
-  if ($max_execution_time != -1) {
670
+    }
671
+    if ($max_execution_time != -1) {
672 672
     $data['max_execution_time'] = $max_execution_time;
673
-  }
674
-  elysia_cron_set($job, false, $data);
673
+    }
674
+    elysia_cron_set($job, false, $data);
675 675
 }
676 676
 
677 677
 function elysia_cron_last_channel() {
678
-  return _ec_variable_get('elysia_cron_last_context', '');
678
+    return _ec_variable_get('elysia_cron_last_context', '');
679 679
 }
680 680
 
681 681
 function elysia_cron_set_last_channel($channel) {
682
-  _ec_variable_set('elysia_cron_last_context', $channel);
682
+    _ec_variable_set('elysia_cron_last_context', $channel);
683 683
 }
684 684
 
685 685
 function elysia_cron_reset_stats() {
686
-  global $elysia_cron_settings, $elysia_cron_settings_by_channel;
687
-  elysia_cron_initialize();
686
+    global $elysia_cron_settings, $elysia_cron_settings_by_channel;
687
+    elysia_cron_initialize();
688 688
 
689
-  foreach ($elysia_cron_settings as $job => $conf) {
689
+    foreach ($elysia_cron_settings as $job => $conf) {
690 690
     elysia_cron_set_job_stats($job, -1, 0, 0, 0, 0);
691
-  }
691
+    }
692 692
 
693
-  foreach ($elysia_cron_settings_by_channel as $channel => $conf) {
693
+    foreach ($elysia_cron_settings_by_channel as $channel => $conf) {
694 694
     elysia_cron_set_channel_stats($channel, -1, 0, 0, 0, 0, 0, 0, 0, 0);
695
-  }
695
+    }
696 696
 }
697 697
 
698 698
 /*******************************************************************************
@@ -704,236 +704,236 @@  discard block
 block discarded – undo
704 704
  *******************************************************************************/
705 705
 
706 706
 function elysia_cron_decode_script($text, $apply = true) {
707
-  global $elysia_cron_settings;
707
+    global $elysia_cron_settings;
708 708
 
709
-  $lines = explode("\n", $text);
710
-  $lastcomment = '';
711
-  $errors = array();
712
-  $conf = array();
713
-  foreach ($lines as $line) {
709
+    $lines = explode("\n", $text);
710
+    $lastcomment = '';
711
+    $errors = array();
712
+    $conf = array();
713
+    foreach ($lines as $line) {
714 714
     $line = trim($line);
715 715
     if (!empty($line)) {
716
-      if ($line{0} == '#') {
716
+        if ($line{0} == '#') {
717 717
         $lastcomment = trim(substr($line, 1));
718 718
 
719
-      }
720
-      else if (preg_match('/^(-[ ]*|)([0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+)[ ]+((?:ctx|ch):([a-zA-Z0-9_-]+)[ ]+|)([^(:]+)(\(.*\);|)$/', $line, $r)) {
719
+        }
720
+        else if (preg_match('/^(-[ ]*|)([0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+)[ ]+((?:ctx|ch):([a-zA-Z0-9_-]+)[ ]+|)([^(:]+)(\(.*\);|)$/', $line, $r)) {
721 721
         $c = array(
722
-          'disabled' => !empty($r[1]),
723
-          'rule' => $r[2],
724
-          'description' => $lastcomment,
725
-          'channel' => $r[4] ? $r[4] : 'default',
722
+            'disabled' => !empty($r[1]),
723
+            'rule' => $r[2],
724
+            'description' => $lastcomment,
725
+            'channel' => $r[4] ? $r[4] : 'default',
726 726
         );
727 727
         $lastcomment = '';
728 728
         if (empty($r[6])) {
729
-          if (!isset($elysia_cron_settings[$r[5]])) {
729
+            if (!isset($elysia_cron_settings[$r[5]])) {
730 730
             // Referring a module function that not exists
731 731
             $errors[] = $line;
732 732
             continue;
733
-          }
734
-          $name = $r[5];
733
+            }
734
+            $name = $r[5];
735 735
         }
736 736
         else {
737
-          // custom expression, generate a unique name
738
-          $postfix = '';
739
-          while (isset($elysia_cron_settings[$r[5] . $postfix])) {
737
+            // custom expression, generate a unique name
738
+            $postfix = '';
739
+            while (isset($elysia_cron_settings[$r[5] . $postfix])) {
740 740
             $postfix = ($postfix ? $postfix : 0) + 1;
741
-          }
742
-          $name = $r[5] . $postfix;
743
-          $c['expression'] = $r[5] . $r[6];
741
+            }
742
+            $name = $r[5] . $postfix;
743
+            $c['expression'] = $r[5] . $r[6];
744 744
         }
745 745
         if ($apply) {
746
-          $elysia_cron_settings[$name] = isset($elysia_cron_settings[$name]) ? array_merge($elysia_cron_settings[$name], $c) : $c;
746
+            $elysia_cron_settings[$name] = isset($elysia_cron_settings[$name]) ? array_merge($elysia_cron_settings[$name], $c) : $c;
747 747
         }
748 748
 
749
-      }
750
-      else {
749
+        }
750
+        else {
751 751
         $errors[] = $line;
752
-      }
752
+        }
753 753
     }
754 754
     else {
755
-      $lastcomment = '';
755
+        $lastcomment = '';
756
+    }
756 757
     }
757
-  }
758 758
 
759
-  return count($errors) ? $errors : false;
759
+    return count($errors) ? $errors : false;
760 760
 }
761 761
 
762 762
 function elysia_cron_module_jobs() {
763
-  static $jobs;
764
-  if (!isset($jobs)) {
763
+    static $jobs;
764
+    if (!isset($jobs)) {
765 765
     $jobs = array();
766 766
     foreach (module_implements('cron') as $module) {
767
-      if ($module != 'elysia_cron') {
767
+        if ($module != 'elysia_cron') {
768 768
         $jobs[$module . '_cron'] = array(
769
-          'module' => $module,
770
-          'callback' => $module . '_cron',
771
-          'arguments' => array(),
769
+            'module' => $module,
770
+            'callback' => $module . '_cron',
771
+            'arguments' => array(),
772 772
         );
773
-      }
773
+        }
774 774
     }
775 775
   
776 776
     foreach (module_implements('cronapi') as $module) {
777
-      $fn = $module . '_cronapi';
778
-      $l = $fn('list');
779
-      if (is_array($l)) {
777
+        $fn = $module . '_cronapi';
778
+        $l = $fn('list');
779
+        if (is_array($l)) {
780 780
         foreach ($l as $job => $data) {
781
-          if (is_array($data)) {
781
+            if (is_array($data)) {
782 782
             $jobs[$job] = $data;
783
-          } else {
783
+            } else {
784 784
             // Compatibility with v1.x settings
785 785
             $jobs[$job] = array(
786
-              'description' => $data,
787
-              'rule' => ($d = $fn('rule', $job)) ? $d : false,
788
-              'weight' => ($d = $fn('weight', $job)) ? $d : 0,
786
+                'description' => $data,
787
+                'rule' => ($d = $fn('rule', $job)) ? $d : false,
788
+                'weight' => ($d = $fn('weight', $job)) ? $d : 0,
789 789
             );
790
-          }
791
-          $jobs[$job] = $jobs[$job] + array(
790
+            }
791
+            $jobs[$job] = $jobs[$job] + array(
792 792
             'module' => $module,
793 793
             'callback' => function_exists($job) ? $job : $fn,
794 794
             'arguments' => function_exists($job) ? array() : array('execute', $job),
795
-          );
795
+            );
796
+        }
796 797
         }
797
-      }
798 798
     }
799 799
     if (function_exists('drupal_alter'))
800
-      drupal_alter('cron', $jobs);
801
-  }
800
+        drupal_alter('cron', $jobs);
801
+    }
802 802
 
803
-  return $jobs;
803
+    return $jobs;
804 804
 }
805 805
 
806 806
 function elysia_cron_initialize($skipscript = false) {
807
-  elysia_cron_check_version_update();
807
+    elysia_cron_check_version_update();
808 808
 
809
-  global $elysia_cron_settings, $elysia_cron_settings_by_channel;
810
-  $elysia_cron_settings = array();
811
-  $elysia_cron_settings_by_channel = array();
809
+    global $elysia_cron_settings, $elysia_cron_settings_by_channel;
810
+    $elysia_cron_settings = array();
811
+    $elysia_cron_settings_by_channel = array();
812 812
 
813
-  foreach (elysia_cron_module_jobs() as $job => $jobpars) {
813
+    foreach (elysia_cron_module_jobs() as $job => $jobpars) {
814 814
     $channel = elysia_cron_get_job_channel($job, 'default');
815 815
 
816 816
     $defrule = !empty($jobpars['rule']) ? $jobpars['rule'] : elysia_cron_get_channel_rule($channel);
817 817
     if (!$defrule) {
818
-      $defrule = variable_get('elysia_cron_default_rule', '0 * * * *');
818
+        $defrule = variable_get('elysia_cron_default_rule', '0 * * * *');
819 819
     }
820 820
     
821 821
     $defweight = !empty($jobpars['weight']) ? $jobpars['weight'] : 0;
822 822
     if (!is_numeric($defweight)) {
823
-      $defweight = 0;
823
+        $defweight = 0;
824 824
     }
825 825
 
826 826
     $elysia_cron_settings[$job] = array(
827
-      'key' => $job,
828
-      'channel' => $channel,
829
-      'rule' => elysia_cron_get_job_rule($job, $defrule),
830
-      'default_rule' => $defrule,
831
-      'weight' => elysia_cron_get_job_weight($job, $defweight),
832
-      'default_weight' => $defweight,
833
-      'disabled' => elysia_cron_is_job_disabled($job),
834
-      'running' => elysia_cron_is_job_running($job),
827
+        'key' => $job,
828
+        'channel' => $channel,
829
+        'rule' => elysia_cron_get_job_rule($job, $defrule),
830
+        'default_rule' => $defrule,
831
+        'weight' => elysia_cron_get_job_weight($job, $defweight),
832
+        'default_weight' => $defweight,
833
+        'disabled' => elysia_cron_is_job_disabled($job),
834
+        'running' => elysia_cron_is_job_running($job),
835 835
     ) + $jobpars;
836
-  }
837
-  if (!$skipscript) {
836
+    }
837
+    if (!$skipscript) {
838 838
     $script = variable_get('elysia_cron_script', false);
839 839
     if ($script) {
840
-      elysia_cron_decode_script($script);
840
+        elysia_cron_decode_script($script);
841
+    }
841 842
     }
842
-  }
843 843
 
844
-  uasort($elysia_cron_settings, '_elysia_cron_sort');
845
-  foreach ($elysia_cron_settings as $job => &$conf) {
844
+    uasort($elysia_cron_settings, '_elysia_cron_sort');
845
+    foreach ($elysia_cron_settings as $job => &$conf) {
846 846
     $stats = elysia_cron_get_job_stats($job);
847 847
     foreach ($stats as $sk => $sv) {
848
-      $conf[$sk] = $sv;
848
+        $conf[$sk] = $sv;
849 849
     }
850 850
     $elysia_cron_settings_by_channel[$conf['channel']][$job] = &$elysia_cron_settings[$job];
851
-  }
851
+    }
852 852
 
853
-  foreach ($elysia_cron_settings_by_channel as $channel => $data) {
853
+    foreach ($elysia_cron_settings_by_channel as $channel => $data) {
854 854
     uasort($elysia_cron_settings_by_channel[$channel], '_elysia_cron_sort');
855 855
     $elysia_cron_settings_by_channel[$channel]['#data'] = elysia_cron_get_channel_stats($channel);
856 856
     $elysia_cron_settings_by_channel[$channel]['#data']['disabled'] = elysia_cron_is_channel_disabled($channel);
857
-  }
857
+    }
858 858
 }
859 859
 
860 860
 function _elysia_cron_sort($a, $b) {
861
-  if ((isset($a['weight']) ? $a['weight'] : 0) == (isset($b['weight']) ? $b['weight'] : 0)) {
861
+    if ((isset($a['weight']) ? $a['weight'] : 0) == (isset($b['weight']) ? $b['weight'] : 0)) {
862 862
     return strcmp((isset($a['key']) ? $a['key'] : ''), (isset($b['key']) ? $b['key'] : ''));
863
-  }
864
-  return (isset($a['weight']) ? $a['weight'] : 0) - (isset($b['weight']) ? $b['weight'] : 0);
863
+    }
864
+    return (isset($a['weight']) ? $a['weight'] : 0) - (isset($b['weight']) ? $b['weight'] : 0);
865 865
 }
866 866
 
867 867
 function elysia_cron_run($manual_run = false) {
868
-  global $conf;
868
+    global $conf;
869 869
 
870
-  // Allow execution to continue even if the request gets canceled.
871
-  @ignore_user_abort(true);
870
+    // Allow execution to continue even if the request gets canceled.
871
+    @ignore_user_abort(true);
872 872
 
873
-  // Try to allocate enough time to run all the hook_cron implementations.
874
-  if (!ini_get('safe_mode')) {
873
+    // Try to allocate enough time to run all the hook_cron implementations.
874
+    if (!ini_get('safe_mode')) {
875 875
     set_time_limit(variable_get('elysia_cron_time_limit', 240));
876
-  }
876
+    }
877 877
 
878
-  // Prevent session information from being saved while cron is running.
879
-  if (EC_DRUPAL_VERSION >= 7) {
878
+    // Prevent session information from being saved while cron is running.
879
+    if (EC_DRUPAL_VERSION >= 7) {
880 880
     drupal_save_session(FALSE);
881
-  }
881
+    }
882 882
 
883
-  // If DISABLED block the execution
884
-  if (variable_get('elysia_cron_disabled', false)) {
883
+    // If DISABLED block the execution
884
+    if (variable_get('elysia_cron_disabled', false)) {
885 885
     return;
886
-  }
886
+    }
887 887
 
888
-  // Check for CRON_KEY or ALLOWED_HOSTS
889
-  if (!$manual_run) {
888
+    // Check for CRON_KEY or ALLOWED_HOSTS
889
+    if (!$manual_run) {
890 890
     $cron_key = variable_get('cron_key', '');
891 891
     if ($cron_key && !user_access('administer elysia_cron') && (empty($_GET['cron_key']) || $_GET['cron_key'] != $cron_key)) {
892
-      return;
892
+        return;
893 893
     }
894 894
     $allowed_hosts = variable_get('elysia_cron_allowed_hosts', false);
895 895
     if ($allowed_hosts && !user_access('administer elysia_cron') && !in_array(ip_address(), explode(",", $allowed_hosts))) {
896
-      return;
896
+        return;
897
+    }
897 898
     }
898
-  }
899 899
 
900
-  _ec_variable_set('elysia_cron_last_run', time());
901
-  _ec_variable_set('cron_last', time());
900
+    _ec_variable_set('elysia_cron_last_run', time());
901
+    _ec_variable_set('cron_last', time());
902 902
 
903
-  $execute = true;
904
-  if (EC_DRUPAL_VERSION >= 7) {
903
+    $execute = true;
904
+    if (EC_DRUPAL_VERSION >= 7) {
905 905
     if (!lock_acquire('cron', 240.0)) {
906
-      _dco_watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING);
907
-      $execute = false;
906
+        _dco_watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING);
907
+        $execute = false;
908 908
     }
909
-  }
910
-  else {
909
+    }
910
+    else {
911 911
     // Global Semaphore to avoid concurrent execution of cron preparation code
912 912
     $execute = _ec_semaphore_get('elysia_cron_semaphore', 120);
913
-  }
913
+    }
914 914
 
915
-  // Force the current user to anonymous to ensure consistent permissions on
916
-  // cron runs (only if run by interface)
917
-  if ($manual_run) {
915
+    // Force the current user to anonymous to ensure consistent permissions on
916
+    // cron runs (only if run by interface)
917
+    if ($manual_run) {
918 918
     $original_user = $GLOBALS['user'];
919 919
     $GLOBALS['user'] = drupal_anonymous_user();
920
-  }
920
+    }
921 921
 
922
-  if (EC_DRUPAL_VERSION >= 7) {
922
+    if (EC_DRUPAL_VERSION >= 7) {
923 923
     // D7 Queue processing
924 924
     // Grab the defined cron queues (even if execute = false)
925 925
     $queues = module_invoke_all('cron_queue_info');
926 926
     drupal_alter('cron_queue_info', $queues);
927
-  }
927
+    }
928 928
 
929
-  if ($execute) {
929
+    if ($execute) {
930 930
     if (EC_DRUPAL_VERSION >= 7) {
931
-      // D7 Queue processing
932
-      // Make sure every queue exists. There is no harm in trying to recreate an
933
-      // existing queue.
934
-      foreach ($queues as $queue_name => $info) {
931
+        // D7 Queue processing
932
+        // Make sure every queue exists. There is no harm in trying to recreate an
933
+        // existing queue.
934
+        foreach ($queues as $queue_name => $info) {
935 935
         DrupalQueue::get($queue_name)->createQueue();
936
-      }
936
+        }
937 937
     }
938 938
 
939 939
     elysia_cron_initialize();
@@ -944,48 +944,48 @@  discard block
 block discarded – undo
944 944
 
945 945
     $i = array_search($channel, $channels);
946 946
     if ($i === FALSE) {
947
-      $i = -1;
947
+        $i = -1;
948 948
     }
949 949
     $k = 0;
950 950
     $jobs = false;
951 951
     $stuck_time = variable_get('elysia_cron_stuck_time', 3600);
952 952
     for ($j = ($i + 1) % count($channels); $k < count($channels); $j = ($j + 1) % count($channels)) {
953
-      $sem = elysia_cron_is_channel_running($channels[$j]);
954
-      if ($sem && (time() - $sem > $stuck_time)) {
953
+        $sem = elysia_cron_is_channel_running($channels[$j]);
954
+        if ($sem && (time() - $sem > $stuck_time)) {
955 955
         elysia_cron_set_channel_running($channels[$j], 0);
956 956
         $last_job = elysia_cron_execute_aborted($channels[$j]);
957 957
         unset($sem);
958 958
         _dco_watchdog('cron', 'Cron channel (%channel) has been running for more than an %stuck_time secs and is most likely stuck. Last job executed: %job', array('%channel' => $channels[$j], '%stuck_time' => $stuck_time, '%job' => $last_job), WATCHDOG_ERROR);
959
-      }
960
-      if (empty($sem) && !$elysia_cron_settings_by_channel[$channels[$j]]['#data']['disabled']) {
959
+        }
960
+        if (empty($sem) && !$elysia_cron_settings_by_channel[$channels[$j]]['#data']['disabled']) {
961 961
         $jobs = elysia_cron_active_jobs($channels[$j]);
962 962
         if (count($jobs)) {
963
-          break;
963
+            break;
964
+        }
964 965
         }
965
-      }
966
-      $k++;
966
+        $k++;
967 967
     }
968 968
 
969 969
     if ($jobs && count($jobs)) {
970
-      // There are jobs ready to be executed
970
+        // There are jobs ready to be executed
971 971
 
972
-      $elysia_cron_current_channel = $channels[$j];
973
-      elysia_cron_set_last_channel($elysia_cron_current_channel);
972
+        $elysia_cron_current_channel = $channels[$j];
973
+        elysia_cron_set_last_channel($elysia_cron_current_channel);
974 974
 
975
-      if (variable_get('elysia_cron_debug_messages', 0)) {
975
+        if (variable_get('elysia_cron_debug_messages', 0)) {
976 976
         _dco_watchdog('cron', 'Cron channel %channel run started.', array('%channel' => $elysia_cron_current_channel), WATCHDOG_NOTICE);
977
-      }
977
+        }
978 978
 
979
-      // Register shutdown callback
980
-      register_shutdown_function('elysia_cron_cleanup');
979
+        // Register shutdown callback
980
+        register_shutdown_function('elysia_cron_cleanup');
981 981
 
982
-      elysia_cron_set($elysia_cron_current_channel, true, array(
982
+        elysia_cron_set($elysia_cron_current_channel, true, array(
983 983
         'running' => time(),
984 984
         'last_run' => time(),
985
-      ));
985
+        ));
986 986
 
987
-      // Now I can unlock cron semaphore
988
-      if (EC_DRUPAL_VERSION < 7) {
987
+        // Now I can unlock cron semaphore
988
+        if (EC_DRUPAL_VERSION < 7) {
989 989
         _ec_variable_del('elysia_cron_semaphore');
990 990
 
991 991
         // Some modules (feedapi, ipaper...) uses the internal "cron_semaphore" variable to detect
@@ -993,149 +993,149 @@  discard block
 block discarded – undo
993 993
         // (In normal drupal cron execution that is done by a variable_set just before this call,
994 994
         // but i need to set this manually if drupal cron is bypassed)
995 995
         $conf['cron_semaphore'] = time();
996
-      }
996
+        }
997 997
 
998
-      foreach ($jobs as $job) {
998
+        foreach ($jobs as $job) {
999 999
         $job_running = false;
1000 1000
         if (elysia_cron_is_job_running($job)) {
1001
-          if (time() - elysia_cron_get_job_last_run($job, 0) > variable_get('elysia_cron_stuck_time', 3600)) {
1001
+            if (time() - elysia_cron_get_job_last_run($job, 0) > variable_get('elysia_cron_stuck_time', 3600)) {
1002 1002
             _dco_watchdog('cron', 'Job %job is already running, but is probably stuck, so i consider it as terminated', array('%job' => $job), WATCHDOG_NOTICE);
1003
-          }
1004
-          else {
1003
+            }
1004
+            else {
1005 1005
             _dco_watchdog('cron', 'Job %job is already running', array('%job' => $job), WATCHDOG_NOTICE);
1006 1006
             $job_running = true;
1007
-          }
1007
+            }
1008 1008
         }
1009 1009
 
1010 1010
         if (!$job_running) {
1011
-          elysia_cron_execute($job);
1011
+            elysia_cron_execute($job);
1012
+        }
1012 1013
         }
1013
-      }
1014 1014
 
1015
-      $cron_completed = true;
1016
-      $cron_completed_time = time();
1015
+        $cron_completed = true;
1016
+        $cron_completed_time = time();
1017 1017
 
1018
-      // Cron is really completed after shutdown functions
1019
-      register_shutdown_function('elysia_cron_completed');
1018
+        // Cron is really completed after shutdown functions
1019
+        register_shutdown_function('elysia_cron_completed');
1020 1020
 
1021 1021
     }
1022 1022
     else {
1023
-      // No jobs should be executed, i must unlock cron semaphore
1024
-      if (EC_DRUPAL_VERSION < 7) {
1023
+        // No jobs should be executed, i must unlock cron semaphore
1024
+        if (EC_DRUPAL_VERSION < 7) {
1025 1025
         _ec_variable_del('elysia_cron_semaphore');
1026
-      }
1026
+        }
1027 1027
 
1028
-      if (variable_get('elysia_cron_debug_messages', 0)) {
1028
+        if (variable_get('elysia_cron_debug_messages', 0)) {
1029 1029
         _dco_watchdog('cron', 'No channels ready to be executed, skipping cron.', array(), WATCHDOG_NOTICE);
1030
-      }
1030
+        }
1031 1031
     }
1032 1032
 
1033 1033
     // Release cron lock.
1034 1034
     if (EC_DRUPAL_VERSION >= 7) {
1035
-      lock_release('cron');
1035
+        lock_release('cron');
1036 1036
 
1037 1037
     }
1038 1038
     else {
1039
-      _ec_variable_del('cron_semaphore');
1040
-      $conf['cron_semaphore'] = false;
1039
+        _ec_variable_del('cron_semaphore');
1040
+        $conf['cron_semaphore'] = false;
1041
+    }
1041 1042
     }
1042
-  }
1043 1043
 
1044
-  if (EC_DRUPAL_VERSION >= 7) {
1044
+    if (EC_DRUPAL_VERSION >= 7) {
1045 1045
     // D7 Queue processing
1046 1046
     foreach ($queues as $queue_name => $info) {
1047
-      $function = $info['worker callback'];
1048
-      $end = time() + (isset($info['time']) ? $info['time'] : 15);
1049
-      $queue = DrupalQueue::get($queue_name);
1050
-      while (time() < $end && ($item = $queue->claimItem())) {
1047
+        $function = $info['worker callback'];
1048
+        $end = time() + (isset($info['time']) ? $info['time'] : 15);
1049
+        $queue = DrupalQueue::get($queue_name);
1050
+        while (time() < $end && ($item = $queue->claimItem())) {
1051 1051
         $function($item->data);
1052 1052
         $queue->deleteItem($item);
1053
-      }
1053
+        }
1054
+    }
1054 1055
     }
1055
-  }
1056 1056
 
1057
-  if ($manual_run) {
1057
+    if ($manual_run) {
1058 1058
     // Restore the user.
1059 1059
     $GLOBALS['user'] = $original_user;
1060 1060
     /*if (EC_DRUPAL_VERSION >= 7) {
1061 1061
       drupal_save_session(TRUE);
1062 1062
     }*/
1063
-  }
1063
+    }
1064 1064
 
1065
-  // Return TRUE so other functions can check if it did run successfully
1066
-  return $execute;
1065
+    // Return TRUE so other functions can check if it did run successfully
1066
+    return $execute;
1067 1067
 }
1068 1068
 
1069 1069
 function elysia_cron_execute($job) {
1070
-  global $elysia_cron_settings;
1070
+    global $elysia_cron_settings;
1071 1071
 
1072
-  if (variable_get('elysia_cron_debug_messages', 0)) {
1072
+    if (variable_get('elysia_cron_debug_messages', 0)) {
1073 1073
     _dco_watchdog('cron', 'Cron job %job started.', array('%job' => $job), WATCHDOG_NOTICE);
1074
-  }
1074
+    }
1075 1075
 
1076
-  $time = time();
1077
-  elysia_cron_set($job, false, array(
1076
+    $time = time();
1077
+    elysia_cron_set($job, false, array(
1078 1078
     'running' => $time,
1079 1079
     'last_run' => $time,
1080
-  ));
1080
+    ));
1081 1081
 
1082
-  try {
1082
+    try {
1083 1083
     if (!empty($elysia_cron_settings[$job]['file'])) {
1084
-      include_once((!empty($elysia_cron_settings[$job]['file path']) ? $elysia_cron_settings[$job]['file path'] : drupal_get_path('module', $elysia_cron_settings[$job]['module'])) . DIRECTORY_SEPARATOR . $elysia_cron_settings[$job]['file']);
1084
+        include_once((!empty($elysia_cron_settings[$job]['file path']) ? $elysia_cron_settings[$job]['file path'] : drupal_get_path('module', $elysia_cron_settings[$job]['module'])) . DIRECTORY_SEPARATOR . $elysia_cron_settings[$job]['file']);
1085 1085
     }
1086 1086
     if (!empty($elysia_cron_settings[$job]['expression'])) {
1087
-      eval($elysia_cron_settings[$job]['expression']);
1087
+        eval($elysia_cron_settings[$job]['expression']);
1088 1088
     }
1089 1089
     elseif (!empty($elysia_cron_settings[$job]['callback']) && function_exists($elysia_cron_settings[$job]['callback'])) {
1090
-      call_user_func_array($elysia_cron_settings[$job]['callback'], $elysia_cron_settings[$job]['arguments']);
1090
+        call_user_func_array($elysia_cron_settings[$job]['callback'], $elysia_cron_settings[$job]['arguments']);
1091 1091
     }
1092 1092
     else {
1093
-      _dco_watchdog('cron', 'Execution of ' . $job . ' failed, can\'t find function!', array(), WATCHDOG_ERROR);
1093
+        _dco_watchdog('cron', 'Execution of ' . $job . ' failed, can\'t find function!', array(), WATCHDOG_ERROR);
1094
+    }
1094 1095
     }
1095
-  }
1096
-  catch (Exception $e) {
1096
+    catch (Exception $e) {
1097 1097
     _dco_watchdog('cron', 'Exception: ' . $e, array(), WATCHDOG_ERROR);
1098 1098
     $exception = true;
1099 1099
     //TODO Manage it
1100
-  }
1100
+    }
1101 1101
 
1102
-  $stats = elysia_cron_get_job_stats($job);
1103
-  $time = time() - $time;
1104
-  elysia_cron_set_job_stats($job,
1102
+    $stats = elysia_cron_get_job_stats($job);
1103
+    $time = time() - $time;
1104
+    elysia_cron_set_job_stats($job,
1105 1105
     -1,
1106 1106
     $time,
1107 1107
     ($c = $stats['execution_count'] + 1),
1108 1108
     round((($stats['avg_execution_time'] * ($c - 1)) + $time) / $c, 2),
1109 1109
     $time > $stats['max_execution_time'] ? $time : -1,
1110 1110
     array('running' => 0)
1111
-  );
1111
+    );
1112 1112
 
1113
-  if (variable_get('elysia_cron_debug_messages', 0)) {
1113
+    if (variable_get('elysia_cron_debug_messages', 0)) {
1114 1114
     _dco_watchdog('cron', 'Cron job %job ended.', array('%job' => $job), WATCHDOG_NOTICE);
1115
-  }
1115
+    }
1116 1116
 }
1117 1117
 
1118 1118
 function elysia_cron_execute_aborted($channel) {
1119
-  global $elysia_cron_settings_by_channel;
1119
+    global $elysia_cron_settings_by_channel;
1120 1120
 
1121
-  $last_job = '';
1122
-  foreach ($elysia_cron_settings_by_channel[$channel] as $job => $conf) {
1121
+    $last_job = '';
1122
+    foreach ($elysia_cron_settings_by_channel[$channel] as $job => $conf) {
1123 1123
     if ($job != '#data') {
1124
-      if (elysia_cron_is_job_running($job)) {
1124
+        if (elysia_cron_is_job_running($job)) {
1125 1125
         $last_job .= ' ' . $job;
1126 1126
         elysia_cron_set_job_running($job, 0);
1127
-      }
1127
+        }
1128
+    }
1128 1129
     }
1129
-  }
1130 1130
 
1131
-  elysia_cron_set($channel, true, array(
1131
+    elysia_cron_set($channel, true, array(
1132 1132
     'running' => 0, //time(),
1133 1133
     'last_aborted' => 1,
1134 1134
     'abort_count' => elysia_cron_get_channel_abort_count($channel) + 1,
1135 1135
     'last_abort_function' => $last_job,
1136
-  ));
1136
+    ));
1137 1137
 
1138
-  return trim($last_job);
1138
+    return trim($last_job);
1139 1139
 }
1140 1140
 
1141 1141
 /**
@@ -1144,36 +1144,36 @@  discard block
 block discarded – undo
1144 1144
  * Used for unexpected termination of code.
1145 1145
  */
1146 1146
 function elysia_cron_cleanup() {
1147
-  global $elysia_cron_settings, $elysia_cron_current_channel, $cron_completed, $cron_completed_time;
1147
+    global $elysia_cron_settings, $elysia_cron_current_channel, $cron_completed, $cron_completed_time;
1148 1148
 
1149
-  if ($cron_completed) {
1149
+    if ($cron_completed) {
1150 1150
     return;
1151
-  }
1151
+    }
1152 1152
 
1153
-  // See if the semaphore is still locked.
1154
-  if (elysia_cron_is_channel_running($elysia_cron_current_channel)) {
1153
+    // See if the semaphore is still locked.
1154
+    if (elysia_cron_is_channel_running($elysia_cron_current_channel)) {
1155 1155
     $last_job = elysia_cron_execute_aborted($elysia_cron_current_channel);
1156 1156
     _dco_watchdog('cron', 'Unexpected termination of cron channel %channel, aborted. Last job executed: %job', array('%channel' => $elysia_cron_current_channel, '%job' => $last_job), WATCHDOG_WARNING);
1157
-  }
1157
+    }
1158 1158
 }
1159 1159
 
1160 1160
 /**
1161 1161
  * Successful termination (after all shutdown hooks invoked by cron functions).
1162 1162
  */
1163 1163
 function elysia_cron_completed() {
1164
-  global $elysia_cron_settings, $elysia_cron_current_channel, $cron_completed, $cron_completed_time;
1165
-  //dprint("completed ".$elysia_cron_current_channel);
1164
+    global $elysia_cron_settings, $elysia_cron_current_channel, $cron_completed, $cron_completed_time;
1165
+    //dprint("completed ".$elysia_cron_current_channel);
1166 1166
 
1167
-  // Record cron time
1168
-  _ec_variable_set('cron_last', time());
1167
+    // Record cron time
1168
+    _ec_variable_set('cron_last', time());
1169 1169
 
1170
-  if (variable_get('elysia_cron_debug_messages', 0)) {
1170
+    if (variable_get('elysia_cron_debug_messages', 0)) {
1171 1171
     _dco_watchdog('cron', 'Cron channel %channel run completed.', array('%channel' => $elysia_cron_current_channel), WATCHDOG_NOTICE);
1172
-  }
1172
+    }
1173 1173
 
1174
-  $stats = elysia_cron_get_channel_stats($elysia_cron_current_channel);
1175
-  $time = time() - $stats['last_run'];
1176
-  elysia_cron_set_channel_stats($elysia_cron_current_channel,
1174
+    $stats = elysia_cron_get_channel_stats($elysia_cron_current_channel);
1175
+    $time = time() - $stats['last_run'];
1176
+    elysia_cron_set_channel_stats($elysia_cron_current_channel,
1177 1177
     -1, // last_run
1178 1178
     $time, // last_execution_time
1179 1179
     ($c = $stats['execution_count'] + 1), // execution_count
@@ -1182,24 +1182,24 @@  discard block
 block discarded – undo
1182 1182
     time() - $cron_completed_time, // last_shutdown_time
1183 1183
     0, -1, -1, // last_aborted, abort_count, last_abort_function
1184 1184
     array('running' => 0)
1185
-  );
1185
+    );
1186 1186
 }
1187 1187
 
1188 1188
 /**
1189 1189
  * Get all jobs that needs to be executed in a channel
1190 1190
  */
1191 1191
 function elysia_cron_active_jobs($channel) {
1192
-  global $elysia_cron_settings_by_channel;
1192
+    global $elysia_cron_settings_by_channel;
1193 1193
 
1194
-  $jobs = array();
1195
-  foreach ($elysia_cron_settings_by_channel[$channel] as $job => $conf) {
1194
+    $jobs = array();
1195
+    foreach ($elysia_cron_settings_by_channel[$channel] as $job => $conf) {
1196 1196
     if ($job != '#data') {
1197
-      if (elysia_cron_should_run($conf)) {
1197
+        if (elysia_cron_should_run($conf)) {
1198 1198
         $jobs[] = $job;
1199
-      }
1199
+        }
1200 1200
     }
1201
-  }
1202
-  return $jobs;
1201
+    }
1202
+    return $jobs;
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1207,32 +1207,32 @@  discard block
 block discarded – undo
1207 1207
  * (Not used by elysia_cron, can be used by external modules)
1208 1208
  */
1209 1209
 function elysia_cron_is_running() {
1210
-  global $elysia_cron_settings_by_channel;
1211
-  elysia_cron_initialize();
1210
+    global $elysia_cron_settings_by_channel;
1211
+    elysia_cron_initialize();
1212 1212
 
1213
-  $running = array();
1214
-  foreach ($elysia_cron_settings_by_channel as $channel => $data) {
1213
+    $running = array();
1214
+    foreach ($elysia_cron_settings_by_channel as $channel => $data) {
1215 1215
     if (elysia_cron_is_channel_running($channel)) {
1216
-      $running[] = $channel;
1216
+        $running[] = $channel;
1217
+    }
1217 1218
     }
1218
-  }
1219 1219
 
1220
-  return $running;
1220
+    return $running;
1221 1221
 }
1222 1222
 
1223 1223
 /**
1224 1224
  * Obtain job description (translated)
1225 1225
  */
1226 1226
 function elysia_cron_description($job) {
1227
-  global $elysia_cron_settings;
1227
+    global $elysia_cron_settings;
1228 1228
 
1229
-  if (!empty($elysia_cron_settings[$job]['description'])) {
1229
+    if (!empty($elysia_cron_settings[$job]['description'])) {
1230 1230
     $desc = $elysia_cron_settings[$job]['description'];
1231
-  }
1232
-  else {
1231
+    }
1232
+    else {
1233 1233
     $desc = _dco_theme('elysia_cron_description', array('job' => $job));
1234
-  }
1235
-  return t($desc);
1234
+    }
1235
+    return t($desc);
1236 1236
 }
1237 1237
 
1238 1238
 /*******************************************************************************
@@ -1243,22 +1243,22 @@  discard block
 block discarded – undo
1243 1243
  * Implementation of hook_theme(). [Only D6+D7]
1244 1244
  */
1245 1245
 function elysia_cron_theme() {
1246
-  return _dcr_hook_theme(array(
1246
+    return _dcr_hook_theme(array(
1247 1247
     'elysia_cron_description' => array(
1248
-      'variables' => array('job' => NULL),
1248
+        'variables' => array('job' => NULL),
1249 1249
     ),
1250 1250
     'elysia_cron_settings_form' => array(
1251
-      'render element' => 'form',
1251
+        'render element' => 'form',
1252 1252
     ),
1253
-  ));
1253
+    ));
1254 1254
 }
1255 1255
 
1256 1256
 /**
1257 1257
  * You can theme this function to provide your (untranslated) descriptions for cron functions, if they do not provide one.
1258 1258
  */
1259 1259
 function theme_elysia_cron_description($variables) {
1260
-  extract(_dcf_theme_signature(array('job' => $variables)));
1261
-  switch ($variables['job']) {
1260
+    extract(_dcf_theme_signature(array('job' => $variables)));
1261
+    switch ($variables['job']) {
1262 1262
     case 'search_cron':
1263 1263
       return 'Update search database index';
1264 1264
     case 'activitystream_cron':
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
       return 'Checks for available updates of Drupal core, contributed modules and themes';
1314 1314
     default:
1315 1315
       return '-';
1316
-  }
1316
+    }
1317 1317
 }
1318 1318
 
1319 1319
 /*******************************************************************************
@@ -1324,19 +1324,19 @@  discard block
 block discarded – undo
1324 1324
  * Page callback for ping page.  Throws 404 if cron hasn't been called within configured time period.
1325 1325
  */
1326 1326
 function elysia_cron_ping_page() {
1327
-  $last_run = _ec_variable_get('elysia_cron_last_run', 0);
1328
-  $diff = time() - $last_run;
1329
-  $max_interval = variable_get('elysia_cron_alert_interval', 60) * 60;
1327
+    $last_run = _ec_variable_get('elysia_cron_last_run', 0);
1328
+    $diff = time() - $last_run;
1329
+    $max_interval = variable_get('elysia_cron_alert_interval', 60) * 60;
1330 1330
 
1331
-  if ($diff > $max_interval) {
1331
+    if ($diff > $max_interval) {
1332 1332
     return drupal_not_found();
1333
-  }
1334
-  else {
1333
+    }
1334
+    else {
1335 1335
     $aoutput = array();
1336 1336
     $aoutput[] = array(
1337
-      '#type' => 'markup',
1338
-      '#markup' => t('Cron has been called within maximum lapse time.'),
1337
+        '#type' => 'markup',
1338
+        '#markup' => t('Cron has been called within maximum lapse time.'),
1339 1339
     );
1340 1340
     return _dcr_render_array($aoutput);
1341
-  }
1341
+    }
1342 1342
 }
Please login to merge, or discard this patch.
sites/default/boinc/modules/contrib/elysia_cron/elysia_cron.admin.inc 1 patch
Indentation   +302 added lines, -302 removed lines patch added patch discarded remove patch
@@ -9,91 +9,91 @@  discard block
 block discarded – undo
9 9
  ******************************************************************************/
10 10
 
11 11
 function elysia_cron_admin_page() {
12
-  $aoutput = array();
13
-  $aoutput[] = drupal_get_form('elysia_cron_run_form');
12
+    $aoutput = array();
13
+    $aoutput[] = drupal_get_form('elysia_cron_run_form');
14 14
 
15
-  $output = '';
15
+    $output = '';
16 16
 
17
-  elysia_cron_initialize();
17
+    elysia_cron_initialize();
18 18
 
19
-  global $elysia_cron_settings, $elysia_cron_settings_by_channel, $elysia_cron_current_channel, $cron_completed, $cron_completed_time;
19
+    global $elysia_cron_settings, $elysia_cron_settings_by_channel, $elysia_cron_current_channel, $cron_completed, $cron_completed_time;
20 20
 
21
-  $v = variable_get('elysia_cron_disabled', false);
22
-  $output .= '<p>' . t('Global disable') . ': <i>' . ($v ? '<span class="warn">' . t('YES') . '</span>' : 'no') . '</i></p>';
23
-  $output .= '<p>' . t('Last channel executed') . ': <i>' . (($c = elysia_cron_last_channel()) ? $c : t('n/a')) . '</i></p>';
21
+    $v = variable_get('elysia_cron_disabled', false);
22
+    $output .= '<p>' . t('Global disable') . ': <i>' . ($v ? '<span class="warn">' . t('YES') . '</span>' : 'no') . '</i></p>';
23
+    $output .= '<p>' . t('Last channel executed') . ': <i>' . (($c = elysia_cron_last_channel()) ? $c : t('n/a')) . '</i></p>';
24 24
 
25
-  if (EC_DRUPAL_VERSION < 7) {
25
+    if (EC_DRUPAL_VERSION < 7) {
26 26
     if (_ec_variable_get('elysia_cron_semaphore', 0)) {
27
-      $output .= '<p><span class="warn">' . t('Global semaphore active since !date', array('!date' => elysia_cron_date(_ec_variable_get('elysia_cron_semaphore', 0)))) . '</span></p>';
27
+        $output .= '<p><span class="warn">' . t('Global semaphore active since !date', array('!date' => elysia_cron_date(_ec_variable_get('elysia_cron_semaphore', 0)))) . '</span></p>';
28
+    }
28 29
     }
29
-  }
30 30
 
31
-  $running = '';
32
-  foreach ($elysia_cron_settings_by_channel as $channel => $data) {
31
+    $running = '';
32
+    foreach ($elysia_cron_settings_by_channel as $channel => $data) {
33 33
     if (elysia_cron_is_channel_running($channel)) {
34
-      $running .= $channel . ' ';
34
+        $running .= $channel . ' ';
35 35
     }
36
-  }
37
-  if ($running) {
36
+    }
37
+    if ($running) {
38 38
     $output .= '<p>' . t('Running channels') . ': <span class="warn">' . $running . '</span></p>';
39
-  }
39
+    }
40 40
 
41
-  $output .= '<p>' . t('Last run') . ': ' . elysia_cron_date(_ec_variable_get('elysia_cron_last_run', 0)) . '</p>';
41
+    $output .= '<p>' . t('Last run') . ': ' . elysia_cron_date(_ec_variable_get('elysia_cron_last_run', 0)) . '</p>';
42 42
 
43
-  foreach ($elysia_cron_settings_by_channel as $channel => $data) {
43
+    foreach ($elysia_cron_settings_by_channel as $channel => $data) {
44 44
     $running = elysia_cron_is_channel_running($channel);
45 45
     $output .= '<h3>' . t('Channel') . ': ' . $channel . ($running ? ' (' . t('Running since !date', array('!date' => elysia_cron_date($running))) . ')' : '') . ($data['#data']['disabled'] ? ' <span class="warn">(' . t('DISABLED') . ')</span>' : '') . '</h3>';
46 46
     $output .= '<p>' . t('Last run') . ': ' . elysia_cron_date($data['#data']['last_run']) . '</p>';
47 47
     $output .= '<p>' . t('Last execution time') . ': ' . $data['#data']['last_execution_time'] . 's ' . t('(Shutdown: !shutdown) (Avg total: !avgtotal, Max total: !maxtotal)', array('!shutdown' => $data['#data']['last_shutdown_time'] . 's', '!avgtotal' => $data['#data']['avg_execution_time'] . 's', '!maxtotal' => $data['#data']['max_execution_time'] . 's')) . '</p>';
48 48
     $output .= '<p>' . t('Execution count') . ': ' . $data['#data']['execution_count'] . '</p>';
49 49
     if ($data['#data']['last_aborted']) {
50
-      $output .= '<p>' . t('Last aborted') . ': <span class="warn">' . t('On function !function', array('!function' => $data['#data']['last_abort_function'])) . '</span></p>';
50
+        $output .= '<p>' . t('Last aborted') . ': <span class="warn">' . t('On function !function', array('!function' => $data['#data']['last_abort_function'])) . '</span></p>';
51 51
     }
52 52
     if ($data['#data']['abort_count']) {
53
-      $output .= '<p>' . t('Abort count') . ': <span class="warn">' . $data['#data']['abort_count'] . '</span></p>';
53
+        $output .= '<p>' . t('Abort count') . ': <span class="warn">' . $data['#data']['abort_count'] . '</span></p>';
54 54
     }
55 55
 
56 56
     $rows = array();
57 57
     foreach ($data as $job => $conf) {
58
-      if ($job != '#data') {
58
+        if ($job != '#data') {
59 59
         $rows[] = array(
60
-          (!empty($conf['disabled']) ? '<strike>' . $job . '</strike>' : (empty($conf['running']) ? '<b>' . $job . '</b>' : '<b><u>' . $job . '</u></b> <small title="' . t('Running') . '">(R)</small>')) . (elysia_cron_should_run($conf) ? ' <small title="' . t('Waiting for execution') . '">(w)</small>' : ''),
61
-          array(
60
+            (!empty($conf['disabled']) ? '<strike>' . $job . '</strike>' : (empty($conf['running']) ? '<b>' . $job . '</b>' : '<b><u>' . $job . '</u></b> <small title="' . t('Running') . '">(R)</small>')) . (elysia_cron_should_run($conf) ? ' <small title="' . t('Waiting for execution') . '">(w)</small>' : ''),
61
+            array(
62 62
             'data' => '<i>' . elysia_cron_description($job) . '</i> ' .
63
-          '[' . _dco_l(t('run'), _dcf_internal_path('admin/config/system/cron/execute/') . $job, array('attributes' => array('onclick' => 'return confirm("' . t('Force execution of !job?', array('!job' => $job)) . '");'))) . ']',
63
+            '[' . _dco_l(t('run'), _dcf_internal_path('admin/config/system/cron/execute/') . $job, array('attributes' => array('onclick' => 'return confirm("' . t('Force execution of !job?', array('!job' => $job)) . '");'))) . ']',
64 64
             'colspan' => 4,
65
-          ),
65
+            ),
66 66
         );
67 67
         $rows[] = array(
68
-          check_plain($conf['rule']) . (!empty($conf['weight']) ? ' <small>(' . t('Weight') . ': ' . $conf['weight'] . ')</small>' : ''),
69
-          elysia_cron_date($conf['last_run']),
70
-          $conf['last_execution_time'] . 's',
71
-          $conf['execution_count'],
72
-          $conf['avg_execution_time'] . 's / ' . $conf['max_execution_time'] . 's',
68
+            check_plain($conf['rule']) . (!empty($conf['weight']) ? ' <small>(' . t('Weight') . ': ' . $conf['weight'] . ')</small>' : ''),
69
+            elysia_cron_date($conf['last_run']),
70
+            $conf['last_execution_time'] . 's',
71
+            $conf['execution_count'],
72
+            $conf['avg_execution_time'] . 's / ' . $conf['max_execution_time'] . 's',
73 73
         );
74
-      }
74
+        }
75 75
     }
76 76
     $output .= _dco_theme('table', array('header' => array(t('Job / Rule'), t('Last run'), t('Last exec time'), t('Exec count'), t('Avg/Max Exec time')), 'rows' => $rows));
77
-  }
77
+    }
78 78
 
79
-  $output .= '<p>' . t('Notes: job times don\'t include shutdown times (only shown on channel times).') . '</p>';
80
-  $output .= '<p>' . t('If an abort occours usually the job is not properly terminated, and so job timings can be inaccurate or wrong.') . '</p>';
79
+    $output .= '<p>' . t('Notes: job times don\'t include shutdown times (only shown on channel times).') . '</p>';
80
+    $output .= '<p>' . t('If an abort occours usually the job is not properly terminated, and so job timings can be inaccurate or wrong.') . '</p>';
81 81
 
82
-  $aoutput[] = array(
82
+    $aoutput[] = array(
83 83
     '#type' => 'markup',
84 84
     '#markup' => $output,
85
-  );
85
+    );
86 86
 
87
-  return _dcr_render_array($aoutput);
87
+    return _dcr_render_array($aoutput);
88 88
 }
89 89
 
90 90
 function elysia_cron_settings_form() {
91
-  global $elysia_cron_settings, $elysia_cron_settings_by_channel;
92
-  elysia_cron_initialize();
91
+    global $elysia_cron_settings, $elysia_cron_settings_by_channel;
92
+    elysia_cron_initialize();
93 93
 
94
-  $form = array();
94
+    $form = array();
95 95
 
96
-  $form['prefix_1'] = array(
96
+    $form['prefix_1'] = array(
97 97
     '#type' => 'fieldset',
98 98
     '#title' => t('Click for help and cron rules and script syntax'),
99 99
     '#collapsible' => true,
@@ -177,164 +177,164 @@  discard block
 block discarded – undo
177 177
 </pre>
178 178
 EOT
179 179
 ),
180
-  );
180
+    );
181 181
 
182
-  $form['prefix_2'] = array(
182
+    $form['prefix_2'] = array(
183 183
     '#markup' => '<hr>',
184
-  );
184
+    );
185 185
 
186
-  $form['main'] = array(
186
+    $form['main'] = array(
187 187
     '#title' => t('Main'),
188 188
     '#type' => 'fieldset',
189 189
     '#collapsible' => false,
190 190
     '#collapsed' => false,
191
-  );
192
-  $form['main']['elysia_cron_disabled'] = array(
191
+    );
192
+    $form['main']['elysia_cron_disabled'] = array(
193 193
     '#title' => t('Global disable'),
194 194
     '#type' => 'checkbox',
195 195
     '#default_value' => variable_get('elysia_cron_disabled', false),
196
-  );
196
+    );
197 197
 
198
-  $form['installation'] = array(
198
+    $form['installation'] = array(
199 199
     '#title' => t('Installation settings'),
200 200
     '#type' => 'fieldset',
201 201
     '#collapsible' => true,
202 202
     '#collapsed' => true,
203
-  );
203
+    );
204 204
 
205
-  if (EC_DRUPAL_VERSION >= 7) {
205
+    if (EC_DRUPAL_VERSION >= 7) {
206 206
     $form['installation']['cron_safe_threshold'] = array(
207
-      '#type' => 'select',
208
-      '#title' => t('Run cron on visitor\'s requests, every'),
209
-      '#default_value' => variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
210
-      '#description' => t('Setting a time here will enable the "poormanscron" method, which runs the Drupal cron operation using normal browser/page requests instead of having to set up a crontab to request the cron.php script. This approach requires that your site gets regular traffic/visitors in order to trigger the cron request.') . '<br />' .
207
+        '#type' => 'select',
208
+        '#title' => t('Run cron on visitor\'s requests, every'),
209
+        '#default_value' => variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
210
+        '#description' => t('Setting a time here will enable the "poormanscron" method, which runs the Drupal cron operation using normal browser/page requests instead of having to set up a crontab to request the cron.php script. This approach requires that your site gets regular traffic/visitors in order to trigger the cron request.') . '<br />' .
211 211
         t('This way is fine if you don\'t need a great control over job starting times and execution frequency.') . '<br />' .
212 212
         t('If you need a fine grained control over cron timings use the crontab metod, as <a href="!cron_url">described in Drupal installation guide</a>.', array('!cron_url' => url('http://drupal.org/cron'))) . '<br />' .
213 213
         t('If you have a very large site, or you need to execute some jobs very often (more than once an hour) refer to Elysia cron\'s INSTALL.TXT to improve main cron setup.'),
214
-      '#options' => array(0 => t('Never / Use external crontab')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'),
214
+        '#options' => array(0 => t('Never / Use external crontab')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'),
215 215
     );
216
-  }
216
+    }
217 217
 
218
-  $form['installation']['cron_key'] = array(
218
+    $form['installation']['cron_key'] = array(
219 219
     '#title' => t('Cron key'),
220 220
     '#type' => 'textfield',
221 221
     '#default_value' => variable_get('cron_key', ''),
222 222
     '#description' => t('This is used to avoid external cron calling. If you set this cron will by accessible only by calling http://site/cron.php?cron_key=XXX, so you\'ll need to modify system crontab to support this (Logged user with [administer elysia_cron] permission avoid this check).'),
223
-  );
223
+    );
224 224
 
225
-  $form['installation']['elysia_cron_allowed_hosts'] = array(
225
+    $form['installation']['elysia_cron_allowed_hosts'] = array(
226 226
     '#title' => t('Allowed hosts'),
227 227
     '#type' => 'textfield',
228 228
     '#default_value' => variable_get('elysia_cron_allowed_hosts', ''),
229 229
     '#description' => t('Insert a list of ip addresses separated by , that can run cron.php (Logged user with [administer elysia_cron] permission avoid this check).'),
230
-  );
230
+    );
231 231
 
232
-  $form['installation']['elysia_cron_default_rule'] = array(
232
+    $form['installation']['elysia_cron_default_rule'] = array(
233 233
     '#title' => t('Default schedule rule'),
234 234
     '#type' => 'textfield',
235 235
     '#default_value' => variable_get('elysia_cron_default_rule', false),
236 236
     '#description' => t('If you don\'t specify a rule for a process, and if it has not a module specified one, this rule will apply'),
237
-  );
237
+    );
238 238
 
239
-  if (!ini_get('safe_mode')) {
239
+    if (!ini_get('safe_mode')) {
240 240
     $form['installation']['elysia_cron_time_limit'] = array(
241
-      '#title' => t('Time limit'),
242
-      '#type' => 'textfield',
243
-      '#default_value' => variable_get('elysia_cron_time_limit', 240),
244
-      '#description' => t('Set the number of seconds a channel is allowed to run. If you have some jobs that needs more time to execute increase it or set to 0 to disable the limit (WARN: that way a stuck job will block the channel forever!).'),
241
+        '#title' => t('Time limit'),
242
+        '#type' => 'textfield',
243
+        '#default_value' => variable_get('elysia_cron_time_limit', 240),
244
+        '#description' => t('Set the number of seconds a channel is allowed to run. If you have some jobs that needs more time to execute increase it or set to 0 to disable the limit (WARN: that way a stuck job will block the channel forever!).'),
245 245
     );
246
-  }
246
+    }
247 247
 
248
-  $form['installation']['elysia_cron_stuck_time'] = array(
248
+    $form['installation']['elysia_cron_stuck_time'] = array(
249 249
     '#title' => t('Stuck time'),
250 250
     '#type' => 'textfield',
251 251
     '#default_value' => variable_get('elysia_cron_stuck_time', 3600),
252 252
     '#description' => t('How many seconds the process should wait to consider the job as stuck (so the channel can run again)'),
253
-  );
253
+    );
254 254
 
255
-  $form['installation']['elysia_cron_debug_messages'] = array(
255
+    $form['installation']['elysia_cron_debug_messages'] = array(
256 256
     '#title' => t('Debug'),
257 257
     '#type' => 'select',
258 258
     '#default_value' => variable_get('elysia_cron_debug_messages', 0),
259 259
     '#options' => array(
260
-      0 => t('Disabled'),
261
-      1 => t('Enabled'),
260
+        0 => t('Disabled'),
261
+        1 => t('Enabled'),
262 262
     ),
263 263
     '#description' => t('Enable extended logging (in watchdog)'),
264
-  );
264
+    );
265 265
 
266
-  $default_ruless = '';
267
-  $default_rules = variable_get('elysia_cron_default_rules', $GLOBALS['elysia_cron_default_rules']);
268
-  foreach ($default_rules as $dk => $dr) {
266
+    $default_ruless = '';
267
+    $default_rules = variable_get('elysia_cron_default_rules', $GLOBALS['elysia_cron_default_rules']);
268
+    foreach ($default_rules as $dk => $dr) {
269 269
     $default_ruless .= $dr . ' = ' . $dk . "\n";
270
-  }
270
+    }
271 271
 
272
-  $form['installation']['elysia_cron_default_rules'] = array(
272
+    $form['installation']['elysia_cron_default_rules'] = array(
273 273
     '#title' => t('Predefined rules'),
274 274
     '#type' => 'textarea',
275 275
     '#rows' => 5,
276 276
     '#default_value' => $default_ruless,
277 277
     '#description' => t('You can put here standard rules used in your system, each one with its own caption. Put each rule in a separate line, in the form "caption = rule". For example: <i>"every 15 minutes = */15 * * * *"</i>.'),
278
-  );
278
+    );
279 279
 
280
-  $form['installation']['elysia_cron_alert_fieldset'] = array(
280
+    $form['installation']['elysia_cron_alert_fieldset'] = array(
281 281
     '#title' => t('External cron tracking'),
282 282
     '#type' => 'fieldset',
283 283
     '#collapsible' => true,
284 284
     '#collapsed' => true,
285 285
     '#description' => t('This lets you use an external tracking system like <a href="http://www.host-tracker.com/">Host Tracker</a> to be used to monitor the health of cron on your site. Point the tracking service to <a href="!cron-ping-url">!cron-ping-url</a>. If Elysia cron has been called within the time interval specified below, the ping page will return HTTP 200.  If not, the ping page will throw a 404 (page not found).', array('!cron-ping-url' => url('admin/build/cron/ping'))),
286
-  );
287
-  $form['installation']['elysia_cron_alert_fieldset']['elysia_cron_alert_interval'] = array(
286
+    );
287
+    $form['installation']['elysia_cron_alert_fieldset']['elysia_cron_alert_interval'] = array(
288 288
     '#title' => t('Lapse interval (minutes)'),
289 289
     '#type' => 'textfield',
290 290
     '#size' => 20,
291 291
     '#default_value' => variable_get('elysia_cron_alert_interval', 60),
292 292
     '#description' => t('Specify the number of minutes to allow to lapse before the cron ping page returns a 404 (page not found).'),
293
-  );
293
+    );
294 294
 
295
-  $form['elysia_cron_script_fieldset'] = array(
295
+    $form['elysia_cron_script_fieldset'] = array(
296 296
     '#title' => t('Script'),
297 297
     '#type' => 'fieldset',
298 298
     '#collapsible' => true,
299 299
     '#collapsed' => !variable_get('elysia_cron_script', ''),
300
-  );
301
-  $form['elysia_cron_script_fieldset']['elysia_cron_script'] = array(
300
+    );
301
+    $form['elysia_cron_script_fieldset']['elysia_cron_script'] = array(
302 302
     '#type' => 'textarea',
303 303
     '#rows' => 20,
304 304
     '#default_value' => variable_get('elysia_cron_script', ''),
305 305
     '#description' => t('You can specify new cron jobs or modify existing schedules by adding lines to the script.<br>' .
306
-      '<b>Warning</b> All rules specified in the script will OVERRIDE single job settings and channel settings (sections below).'),
307
-  );
306
+        '<b>Warning</b> All rules specified in the script will OVERRIDE single job settings and channel settings (sections below).'),
307
+    );
308 308
   
309
-  $form['single_job'] = array(
309
+    $form['single_job'] = array(
310 310
     '#title' => t('Single job settings'),
311 311
     '#description' => 
312
-      '<b>'.t('Disabled').'</b>: '.t('Flag this to disable job execution').'<br />'.
313
-      '<b>'.t('Schedule rule').'</b>: '.t('Timing rule for the job. Leave empty to use default rule (shown after the field in parenthesis)').'<br />'.
314
-      '<b>'.t('Weight').'</b>: '.t('Use this to specify execution order: low weights are executed before high weights. Default value shown in parenthesis').'<br />'.
315
-      '<b>'.t('Channel').'</b>: '.t('Specify a channel for the job (create the channel if not exists)').'<br /><br />',
312
+        '<b>'.t('Disabled').'</b>: '.t('Flag this to disable job execution').'<br />'.
313
+        '<b>'.t('Schedule rule').'</b>: '.t('Timing rule for the job. Leave empty to use default rule (shown after the field in parenthesis)').'<br />'.
314
+        '<b>'.t('Weight').'</b>: '.t('Use this to specify execution order: low weights are executed before high weights. Default value shown in parenthesis').'<br />'.
315
+        '<b>'.t('Channel').'</b>: '.t('Specify a channel for the job (create the channel if not exists)').'<br /><br />',
316 316
     '#type' => 'fieldset',
317 317
     '#collapsible' => true,
318 318
     //'#collapsed' => true,
319
-  );
319
+    );
320 320
   
321
-  $jobchannels = array(
321
+    $jobchannels = array(
322 322
     '#title' => t('Job channel associations'),
323 323
     '#description' => t('Leave empty for default channel'),
324 324
     '#type' => 'fieldset',
325 325
     '#collapsible' => true,
326 326
     '#collapsed' => true,
327
-  );
327
+    );
328 328
 
329
-  foreach ($elysia_cron_settings_by_channel as $channel => $cconf) {
329
+    foreach ($elysia_cron_settings_by_channel as $channel => $cconf) {
330 330
     foreach ($cconf as $job => $conf) {
331
-      if ($job != '#data' && empty($conf['expression'])) {
331
+        if ($job != '#data' && empty($conf['expression'])) {
332 332
         $form['single_job']['elysia_cron_' . $job] = array(
333
-          '#title' => $job, // t('Job !job', array('!job' => $job)),
334
-          '#description' => elysia_cron_description($job),
335
-          '#type' => 'fieldset',
336
-          '#collapsible' => true,
337
-          '#collapsed' => !elysia_cron_get_job_rule($job) && !elysia_cron_get_job_weight($job) && !elysia_cron_is_job_disabled($job) && !elysia_cron_get_job_channel($job),
333
+            '#title' => $job, // t('Job !job', array('!job' => $job)),
334
+            '#description' => elysia_cron_description($job),
335
+            '#type' => 'fieldset',
336
+            '#collapsible' => true,
337
+            '#collapsed' => !elysia_cron_get_job_rule($job) && !elysia_cron_get_job_weight($job) && !elysia_cron_is_job_disabled($job) && !elysia_cron_get_job_channel($job),
338 338
         );
339 339
         //if (!$form['single_job']['elysia_cron_'.$job]['#collapsed'])
340 340
         //  $form['single_job']['#collapsed'] = false;
@@ -342,125 +342,125 @@  discard block
 block discarded – undo
342 342
         $rule = elysia_cron_get_job_rule($job);
343 343
         $options = array_merge(array('default' => t('Default') . ' (' . (!empty($default_rules[$conf['default_rule']]) ? $default_rules[$conf['default_rule']] : $conf['default_rule']) . ')'), $default_rules);
344 344
         if ($rule && !isset($options[$rule])) {
345
-          $options[$rule] = $rule;
345
+            $options[$rule] = $rule;
346 346
         }
347 347
         $options['custom'] = t('Custom') . ' ...';
348 348
 
349 349
         $form['single_job']['elysia_cron_' . $job]['_elysia_cron_seljob_rule_' . $job] = array(
350
-          '#title' => t('Schedule rule'),
351
-          '#type' => 'select',
352
-          '#options' => $options,
353
-          '#default_value' => $rule ? $rule : 'default',
350
+            '#title' => t('Schedule rule'),
351
+            '#type' => 'select',
352
+            '#options' => $options,
353
+            '#default_value' => $rule ? $rule : 'default',
354 354
         );
355 355
 
356 356
         $form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_rule_' . $job] = array(
357
-          '#title' => t('Schedule rule'),
358
-          '#type' => 'textfield',
359
-          '#size' => 20,
360
-          '#default_value' => $rule ? $rule : $conf['default_rule'],
357
+            '#title' => t('Schedule rule'),
358
+            '#type' => 'textfield',
359
+            '#size' => 20,
360
+            '#default_value' => $rule ? $rule : $conf['default_rule'],
361 361
         );
362 362
 
363 363
         $form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_weight_' . $job] = array(
364
-          '#title' => t('Weight'),
365
-          '#type' => 'textfield',
366
-          '#size' => 4,
367
-          '#default_value' => elysia_cron_get_job_weight($job),
368
-          '#description' => '(' . $conf['default_weight'] . ')',
364
+            '#title' => t('Weight'),
365
+            '#type' => 'textfield',
366
+            '#size' => 4,
367
+            '#default_value' => elysia_cron_get_job_weight($job),
368
+            '#description' => '(' . $conf['default_weight'] . ')',
369 369
         );
370 370
 
371 371
         //$form['single_job']['elysia_cron_'.$job]['elysia_cron_'.$job.'_disabled'] = array(
372 372
         $form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_disabled_' . $job] = array(
373
-          '#title' => t('Disabled'),
374
-          '#type' => 'checkbox',
375
-          '#default_value' => elysia_cron_is_job_disabled($job, false),
373
+            '#title' => t('Disabled'),
374
+            '#type' => 'checkbox',
375
+            '#default_value' => elysia_cron_is_job_disabled($job, false),
376 376
         );
377 377
 
378 378
         //$jobchannels['elysia_cron_'.$job.'_channel'] = array(
379 379
         $form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_channel_' . $job] = array(
380
-          '#title' => t('Channel'), // t('Channel for !job', array('!job' => $job)),
381
-          '#type' => 'textfield',
382
-          '#size' => 20,
383
-          '#default_value' => elysia_cron_get_job_channel($job),
380
+            '#title' => t('Channel'), // t('Channel for !job', array('!job' => $job)),
381
+            '#type' => 'textfield',
382
+            '#size' => 20,
383
+            '#default_value' => elysia_cron_get_job_channel($job),
384 384
         );
385 385
 
386 386
         //if (elysia_cron_get_job_channel($job))
387 387
         //  $jobchannels['#collapsed'] = false;
388
-      }
388
+        }
389
+    }
389 390
     }
390
-  }
391 391
 
392
-  $form['channels'] = array(
392
+    $form['channels'] = array(
393 393
     '#title' => t('Channels settings'),
394 394
     '#type' => 'fieldset',
395 395
     '#collapsible' => true,
396 396
     //'#collapsed' => $jobchannels['#collapsed'],
397
-  );
397
+    );
398 398
 
399
-  foreach ($elysia_cron_settings_by_channel as $channel => $conf) {
399
+    foreach ($elysia_cron_settings_by_channel as $channel => $conf) {
400 400
     $form['channels']['elysia_cron_ch_' . $channel] = array(
401
-      '#title' => $channel, // t('Channel !channel', array('!channel' => $channel)),
402
-      '#type' => 'fieldset',
401
+        '#title' => $channel, // t('Channel !channel', array('!channel' => $channel)),
402
+        '#type' => 'fieldset',
403 403
     );
404 404
     $form['channels']['elysia_cron_ch_' . $channel]['_elysia_cron_ch_disabled_' . $channel] = array(
405
-      '#title' => t('Disabled'),
406
-      '#type' => 'checkbox',
407
-      '#default_value' => elysia_cron_is_channel_disabled($channel, ''),
405
+        '#title' => t('Disabled'),
406
+        '#type' => 'checkbox',
407
+        '#default_value' => elysia_cron_is_channel_disabled($channel, ''),
408 408
     );
409 409
     $form['channels']['elysia_cron_ch_' . $channel]['_elysia_cron_ch_rule_' . $channel] = array(
410
-      '#title' => t('Default schedule rule'),
411
-      '#type' => 'textfield',
412
-      '#size' => 20,
413
-      '#default_value' => elysia_cron_get_channel_rule($channel),
410
+        '#title' => t('Default schedule rule'),
411
+        '#type' => 'textfield',
412
+        '#size' => 20,
413
+        '#default_value' => elysia_cron_get_channel_rule($channel),
414 414
     );
415 415
     //if (elysia_cron_is_channel_disabled($channel))
416 416
     //  $form['channels']['#collapsed'] = false;
417
-  }
417
+    }
418 418
 
419
-  //$form['channels']['jobchannels'] = $jobchannels;
419
+    //$form['channels']['jobchannels'] = $jobchannels;
420 420
 
421
-  $form['buttons'] = array('#type' => 'actions');
422
-  $form['buttons']['submit'] = array(
421
+    $form['buttons'] = array('#type' => 'actions');
422
+    $form['buttons']['submit'] = array(
423 423
     '#type' => 'submit',
424 424
     '#value' => t('Save configuration'),
425
-  );
426
-  $form['buttons']['reset'] = array(
425
+    );
426
+    $form['buttons']['reset'] = array(
427 427
     '#type' => 'submit',
428 428
     '#value' => t('Reset to defaults'),
429
-  );
429
+    );
430 430
 
431
-  if (!empty($_POST) && form_get_errors()) {
431
+    if (!empty($_POST) && form_get_errors()) {
432 432
     drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
433
-  }
433
+    }
434 434
 
435
-  return _dcr_form($form);
435
+    return _dcr_form($form);
436 436
 }
437 437
 
438 438
 function theme_elysia_cron_settings_form($_dco_variables) {
439
-  extract(_dcf_theme_form($_dco_variables));
440
-  $form = &$variables['form'];
439
+    extract(_dcf_theme_form($_dco_variables));
440
+    $form = &$variables['form'];
441 441
 
442
-  $output = '<script type="text/javascript"><!--' . "\n" .
442
+    $output = '<script type="text/javascript"><!--' . "\n" .
443 443
     /*'function _ec_select(editid, select) { if (select.value == \'custom\') {'.
444 444
       '$ = jQuery; $(select).hide();$("#"+editid).show();$("#"+editid).focus();'.
445 445
     '}}'.*/
446 446
     'function _ec_select(key, select) { if (select.value == \'custom\') {' .
447
-      '$ = jQuery; $("#_ec_select_"+key).hide();$("#_ec_custom_"+key).show();$("#_ec_custom_"+key).focus();' .
447
+        '$ = jQuery; $("#_ec_select_"+key).hide();$("#_ec_custom_"+key).show();$("#_ec_custom_"+key).focus();' .
448 448
     '}}' .
449 449
     "\n" . '--></script>';
450 450
 
451
-  $coutput = '<table>';
451
+    $coutput = '<table>';
452 452
 
453
-  $i = 0;
454
-  foreach (element_children($form['single_job']) as $c) {
453
+    $i = 0;
454
+    foreach (element_children($form['single_job']) as $c) {
455 455
     $key = substr($c, 12);
456 456
     //print_r($form['single_job'][$c]);
457 457
     if ($i++ == 0) {
458
-      $coutput .= '<tr>' .
458
+        $coutput .= '<tr>' .
459 459
         '<th>' . $form['single_job'][$c]['_elysia_cron_job_disabled_' . $key]['#title'] . '</th>' .
460 460
         '<th>' . $form['single_job'][$c]['_elysia_cron_job_rule_' . $key]['#title'] . '</th>' .
461 461
         '<th colspan="2">' . $form['single_job'][$c]['_elysia_cron_job_weight_' . $key]['#title'] . '</th>' .
462 462
         '<th>' . $form['single_job'][$c]['_elysia_cron_job_channel_' . $key]['#title'] . '</th>' .
463
-      '</tr>';
463
+        '</tr>';
464 464
     }
465 465
 
466 466
     //$def_rule = $form['single_job'][$c]['_elysia_cron_job_rule_'.$key]['#description'];
@@ -492,30 +492,30 @@  discard block
 block discarded – undo
492 492
 
493 493
     $coutput .= '<tr><td colspan="6"><b>' . $form['single_job'][$c]['#title'] . '</b>' . (($d = $form['single_job'][$c]['#description']) && $d != '-' ? ' <i>(' . $d . ')</i>' : '' ) . '</td></tr>';
494 494
     $coutput .= '<tr>' .
495
-      '<td align="center">' . drupal_render($form['single_job'][$c]['_elysia_cron_job_disabled_' . $key]) . '</td>' .
496
-      '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]) . drupal_render($form['single_job'][$c]['_elysia_cron_job_rule_' . $key]) . '</td>' .//'<td><small>'.$def_rule.'</small></td>'.
497
-      '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_job_weight_' . $key]) . '</td><td><small>' . $def_weight . '</small></td>' .
498
-      '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_job_channel_' . $key]) . '</td>' .
495
+        '<td align="center">' . drupal_render($form['single_job'][$c]['_elysia_cron_job_disabled_' . $key]) . '</td>' .
496
+        '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]) . drupal_render($form['single_job'][$c]['_elysia_cron_job_rule_' . $key]) . '</td>' .//'<td><small>'.$def_rule.'</small></td>'.
497
+        '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_job_weight_' . $key]) . '</td><td><small>' . $def_weight . '</small></td>' .
498
+        '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_job_channel_' . $key]) . '</td>' .
499 499
     '</tr>';
500 500
     drupal_render($form['single_job'][$c]);
501
-  }
502
-  $coutput .= '</table>';
501
+    }
502
+    $coutput .= '</table>';
503 503
 
504
-  $form['single_job']['#children'] = $coutput;
505
-  //$form['single_job'][] = array('#type' => 'markup', '#markup' => $output);
504
+    $form['single_job']['#children'] = $coutput;
505
+    //$form['single_job'][] = array('#type' => 'markup', '#markup' => $output);
506 506
 
507
-  $coutput = '<table>';
507
+    $coutput = '<table>';
508 508
 
509
-  $i = 0;
509
+    $i = 0;
510 510
 
511
-  foreach (element_children($form['channels']) as $c) {
511
+    foreach (element_children($form['channels']) as $c) {
512 512
     $key = substr($c, 15);
513 513
     if ($i++ == 0) {
514
-      $coutput .= '<tr>' .
514
+        $coutput .= '<tr>' .
515 515
         '<th>' . t('Name') . '</th>' .
516 516
         '<th>' . $form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]['#title'] . '</th>' .
517 517
         '<th>' . $form['channels'][$c]['_elysia_cron_ch_rule_' . $key]['#title'] . '</th>' .
518
-      '</tr>';
518
+        '</tr>';
519 519
     }
520 520
 
521 521
     $form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]['#title'] = NULL;
@@ -524,221 +524,221 @@  discard block
 block discarded – undo
524 524
     $form['channels'][$c]['_elysia_cron_ch_rule_' . $key]['#attributes']['style'] = 'margin: 0';
525 525
 
526 526
     $coutput .= '<tr>' .
527
-      '<td><b>' . $form['channels'][$c]['#title'] . '</b></td>' .
528
-      '<td>' . drupal_render($form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]) . '</td>' .
529
-      '<td>' . drupal_render($form['channels'][$c]['_elysia_cron_ch_rule_' . $key]) . '</td>' .
527
+        '<td><b>' . $form['channels'][$c]['#title'] . '</b></td>' .
528
+        '<td>' . drupal_render($form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]) . '</td>' .
529
+        '<td>' . drupal_render($form['channels'][$c]['_elysia_cron_ch_rule_' . $key]) . '</td>' .
530 530
     '</tr>';
531 531
     drupal_render($form['channels'][$c]);
532
-  }
533
-  $coutput .= '</table>';
532
+    }
533
+    $coutput .= '</table>';
534 534
 
535
-  $form['channels']['#children'] = $coutput;
535
+    $form['channels']['#children'] = $coutput;
536 536
 
537
-  return $output . drupal_render_children($form);
538
-  //$form['channels'][] = array('#type' => 'markup', '#markup' => $output);
539
-  //return drupal_render(_dcr_form($form));
537
+    return $output . drupal_render_children($form);
538
+    //$form['channels'][] = array('#type' => 'markup', '#markup' => $output);
539
+    //return drupal_render(_dcr_form($form));
540 540
 }
541 541
 
542 542
 function elysia_cron_settings_form_validate($_dco_form, &$_dco_form_state) {
543
-  extract(_dcf_form_validate($_dco_form, $_dco_form_state));
544
-  global $elysia_cron_settings;
543
+    extract(_dcf_form_validate($_dco_form, $_dco_form_state));
544
+    global $elysia_cron_settings;
545 545
 
546
-  $script = $form_state['values']['elysia_cron_script'];
547
-  if ($script) {
546
+    $script = $form_state['values']['elysia_cron_script'];
547
+    if ($script) {
548 548
     $errors = elysia_cron_decode_script($script, false);
549 549
     if ($errors) {
550
-      form_set_error('elysia_cron_script', t('Invalid lines:') . implode('<br>', $errors));
550
+        form_set_error('elysia_cron_script', t('Invalid lines:') . implode('<br>', $errors));
551
+    }
551 552
     }
552
-  }
553 553
 
554
-  foreach ($form_state['values'] as $key => $value) {
554
+    foreach ($form_state['values'] as $key => $value) {
555 555
     if ($value && preg_match('/^_elysia_cron_([^_]+_[^_]+)_(.*)$/', $key, $r) && ($r[1] == 'job_rule' || $r[1] == 'ch_rule')) {
556
-      if (!preg_match('/^\\s*([0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+)\\s*$/', $value)) {
556
+        if (!preg_match('/^\\s*([0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+)\\s*$/', $value)) {
557 557
         form_set_error($key, t('Invalid rule: %rule', array('%rule' => $value)));
558
-      }
558
+        }
559
+    }
559 560
     }
560
-  }
561 561
 
562
-  if (!empty($form_state['values']['elysia_cron_default_rules'])) {
562
+    if (!empty($form_state['values']['elysia_cron_default_rules'])) {
563 563
     $rules = explode(PHP_EOL, $form_state['values']['elysia_cron_default_rules']);
564 564
     foreach ($rules as $rule) {
565
-      $rule = trim($rule);
566
-      if (empty($rule)) {
565
+        $rule = trim($rule);
566
+        if (empty($rule)) {
567 567
         continue;
568
-      }
568
+        }
569 569
 
570
-      $rule = explode('=', $rule);
571
-      if (empty($rule[1])) {
570
+        $rule = explode('=', $rule);
571
+        if (empty($rule[1])) {
572 572
         form_set_error('elysia_cron_default_rules', t('Invalid rule: %rule', array('%rule' => $rule[0])));
573
-      } 
574
-      elseif (!preg_match('/^\\s*([0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+)\\s*$/', trim($rule[1]))) {
573
+        } 
574
+        elseif (!preg_match('/^\\s*([0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+)\\s*$/', trim($rule[1]))) {
575 575
         form_set_error('elysia_cron_default_rules', t('Invalid rule: %rule', array('%rule' => $rule[0])));
576
-      }
576
+        }
577
+    }
577 578
     }
578
-  }
579 579
 }
580 580
 
581 581
 function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
582
-  extract(_dcf_form_validate($_dco_form, $_dco_form_state));
583
-  $form_values = $form_state['values'];
582
+    extract(_dcf_form_validate($_dco_form, $_dco_form_state));
583
+    $form_values = $form_state['values'];
584 584
 
585
-  $op = isset($form_values['op']) ? $form_values['op'] : '';
585
+    $op = isset($form_values['op']) ? $form_values['op'] : '';
586 586
 
587
-  // Exclude unnecessary elements.
588
-  unset($form_values['submit'], $form_values['reset'], $form_values['form_id'], $form_values['op'], $form_values['form_token']);
587
+    // Exclude unnecessary elements.
588
+    unset($form_values['submit'], $form_values['reset'], $form_values['form_id'], $form_values['op'], $form_values['form_token']);
589 589
 
590
-  $elysia_cron_default_rules = array();
591
-  $rules = explode("\n", $form_values['elysia_cron_default_rules']);
592
-  foreach ($rules as $r) {
590
+    $elysia_cron_default_rules = array();
591
+    $rules = explode("\n", $form_values['elysia_cron_default_rules']);
592
+    foreach ($rules as $r) {
593 593
     if (trim($r)) {
594
-      $rr = explode("=", $r);
595
-      $elysia_cron_default_rules[trim($rr[1])] = trim($rr[0]);
594
+        $rr = explode("=", $r);
595
+        $elysia_cron_default_rules[trim($rr[1])] = trim($rr[0]);
596
+    }
596 597
     }
597
-  }
598
-  variable_set('elysia_cron_default_rules', $elysia_cron_default_rules);
598
+    variable_set('elysia_cron_default_rules', $elysia_cron_default_rules);
599 599
 
600
-  foreach ($form_values as $key => $value) {
600
+    foreach ($form_values as $key => $value) {
601 601
     $value = trim($value);
602 602
     if (!preg_match('/^_elysia_cron_([^_]+_[^_]+)_(.*)$/', $key, $r)) {
603
-      if ($op == t('Reset to defaults') || ($key != 'cron_safe_threshold' && !$value)) {
603
+        if ($op == t('Reset to defaults') || ($key != 'cron_safe_threshold' && !$value)) {
604 604
         variable_del($key);
605
-      }
606
-      elseif ($key != 'elysia_cron_default_rules') {
605
+        }
606
+        elseif ($key != 'elysia_cron_default_rules') {
607 607
         if (is_array($value) && isset($form_values['array_filter'])) {
608
-          $value = array_keys(array_filter($value));
608
+            $value = array_keys(array_filter($value));
609 609
         }
610 610
         variable_set($key, $value);
611
-      }
611
+        }
612 612
     }
613 613
     else {
614
-      $nullvalue = $r[1] != 'job_weight' ? !$value : !$value && $value !== '0';
614
+        $nullvalue = $r[1] != 'job_weight' ? !$value : !$value && $value !== '0';
615 615
 
616
-      //dprint($r[1].' '.$r[1].' '.$r[2]);
617
-      if ($op == t('Reset to defaults') || $nullvalue) {
616
+        //dprint($r[1].' '.$r[1].' '.$r[2]);
617
+        if ($op == t('Reset to defaults') || $nullvalue) {
618 618
         switch ($r[1]) {
619
-          case 'job_channel':
619
+            case 'job_channel':
620 620
             elysia_cron_reset_job_channel($r[2]);
621 621
             break;
622
-          case 'job_rule':
622
+            case 'job_rule':
623 623
             elysia_cron_reset_job_rule($r[2]);
624 624
             break;
625
-          case 'job_weight':
625
+            case 'job_weight':
626 626
             elysia_cron_reset_job_weight($r[2]);
627 627
             break;
628
-          case 'job_disabled':
628
+            case 'job_disabled':
629 629
             elysia_cron_reset_job_disabled($r[2]);
630 630
             break;
631
-          case 'ch_disabled':
631
+            case 'ch_disabled':
632 632
             elysia_cron_reset_channel_disabled($r[2]);
633 633
             break;
634
-          case 'ch_rule':
634
+            case 'ch_rule':
635 635
             elysia_cron_reset_channel_rule($r[2]);
636 636
             break;
637 637
         }
638
-      }
639
-      else {
638
+        }
639
+        else {
640 640
         switch ($r[1]) {
641
-          case 'job_channel':
641
+            case 'job_channel':
642 642
             elysia_cron_set_job_channel($r[2], $value);
643 643
             break;
644
-          case 'job_rule':
644
+            case 'job_rule':
645 645
             if ($form_values['_elysia_cron_seljob_rule_' . $r[2]] == 'custom') {
646
-              elysia_cron_set_job_rule($r[2], $value);
646
+                elysia_cron_set_job_rule($r[2], $value);
647 647
             }
648 648
             break;
649
-          case 'seljob_rule':
649
+            case 'seljob_rule':
650 650
             if ($value != 'custom') {
651
-              if ($value == 'default') {
651
+                if ($value == 'default') {
652 652
                 elysia_cron_reset_job_rule($r[2]);
653
-              }
654
-              else {
653
+                }
654
+                else {
655 655
                 elysia_cron_set_job_rule($r[2], $value);
656
-              }
656
+                }
657 657
             }
658 658
             break;
659
-          case 'job_weight':
659
+            case 'job_weight':
660 660
             elysia_cron_set_job_weight($r[2], $value);
661 661
             break;
662
-          case 'job_disabled':
662
+            case 'job_disabled':
663 663
             elysia_cron_set_job_disabled($r[2], $value);
664 664
             break;
665
-          case 'ch_disabled':
665
+            case 'ch_disabled':
666 666
             elysia_cron_set_channel_disabled($r[2], $value);
667 667
             break;
668
-          case 'ch_rule':
668
+            case 'ch_rule':
669 669
             elysia_cron_set_channel_rule($r[2], $value);
670 670
             break;
671 671
         }
672
-      }
672
+        }
673 673
 
674 674
     }
675
-  }
676
-  if ($op == t('Reset to defaults')) {
675
+    }
676
+    if ($op == t('Reset to defaults')) {
677 677
     drupal_set_message(t('The configuration options have been reset to their default values.'));
678
-  }
679
-  else {
678
+    }
679
+    else {
680 680
     drupal_set_message(t('The configuration options have been saved.'));
681
-  }
681
+    }
682 682
 }
683 683
 
684 684
 function elysia_cron_date($timestamp) {
685
-  return $timestamp > 0 ? format_date($timestamp, EC_DRUPAL_VERSION >= 7 ? 'short' : 'small') : t('n/a');
686
-  //return date(variable_get('date_format_short', 'm/d/Y - H:i'), $timestamp);
685
+    return $timestamp > 0 ? format_date($timestamp, EC_DRUPAL_VERSION >= 7 ? 'short' : 'small') : t('n/a');
686
+    //return date(variable_get('date_format_short', 'm/d/Y - H:i'), $timestamp);
687 687
 }
688 688
 
689 689
 function elysia_cron_run_form() {
690
-  $form = array();
691
-  $form['runf'] = array(
690
+    $form = array();
691
+    $form['runf'] = array(
692 692
     '#type' => 'fieldset',
693
-  );
694
-  $form['runf']['run'] = array(
693
+    );
694
+    $form['runf']['run'] = array(
695 695
     '#type' => 'submit',
696 696
     '#value' => t('Run cron'),
697
-  );
698
-  return $form;
697
+    );
698
+    return $form;
699 699
 }
700 700
 
701 701
 function elysia_cron_run_form_submit($_dco_form, &$_dco_form_state) {
702
-  // Run cron manually from Cron form.
703
-  if (elysia_cron_run()) {
702
+    // Run cron manually from Cron form.
703
+    if (elysia_cron_run()) {
704 704
     drupal_set_message(t('Cron run successfully.'));
705
-  }
706
-  else {
705
+    }
706
+    else {
707 707
     drupal_set_message(t('Cron run failed.'), 'error');
708
-  }
708
+    }
709 709
 
710
-  drupal_goto(_dcf_internal_path('admin/config/system/cron'));
710
+    drupal_goto(_dcf_internal_path('admin/config/system/cron'));
711 711
 }
712 712
 
713 713
 function elysia_cron_execute_page($job = false) {
714
-  global $cron_completed, $cron_executing_job, $conf;
714
+    global $cron_completed, $cron_executing_job, $conf;
715 715
 
716
-  if (!$job) {
716
+    if (!$job) {
717 717
     drupal_set_message(t('No job specified'), 'error');
718 718
     drupal_goto(_dcf_internal_path('admin/config/system/cron'));
719
-  }
719
+    }
720 720
 
721
-  $running = false;
722
-  if (elysia_cron_is_job_running($job, false)) {
721
+    $running = false;
722
+    if (elysia_cron_is_job_running($job, false)) {
723 723
     if (time() - elysia_cron_get_job_last_run($job, 0) > variable_get('elysia_cron_stuck_time', 3600)) {
724
-      drupal_set_message(t('Job %job already running, but is probably stuck, so i consider it as terminated', array('%job' => $job)));
724
+        drupal_set_message(t('Job %job already running, but is probably stuck, so i consider it as terminated', array('%job' => $job)));
725 725
     }
726 726
     else {
727
-      drupal_set_message(t('Job %job already running', array('%job' => $job)));
728
-      $running = true;
727
+        drupal_set_message(t('Job %job already running', array('%job' => $job)));
728
+        $running = true;
729
+    }
729 730
     }
730
-  }
731 731
 
732
-  if (!$running) {
732
+    if (!$running) {
733 733
     $cron_completed = false;
734 734
     $cron_executing_job = $job;
735 735
 
736 736
     if (EC_DRUPAL_VERSION < 7) {
737
-      // Some modules (feedapi, ipaper...) uses the internal "cron_semaphore" variable to detect
738
-      // start time of cron process. I'll set this only in memory for that purpose.
739
-      // (In normal drupal cron execution that is done by a variable_set just before this call,
740
-      // but i need to set this manually if drupal cron is bypassed)
741
-      $conf['cron_semaphore'] = time();
737
+        // Some modules (feedapi, ipaper...) uses the internal "cron_semaphore" variable to detect
738
+        // start time of cron process. I'll set this only in memory for that purpose.
739
+        // (In normal drupal cron execution that is done by a variable_set just before this call,
740
+        // but i need to set this manually if drupal cron is bypassed)
741
+        $conf['cron_semaphore'] = time();
742 742
     }
743 743
 
744 744
     // Register shutdown callback
@@ -748,64 +748,64 @@  discard block
 block discarded – undo
748 748
     elysia_cron_execute($job);
749 749
 
750 750
     if (EC_DRUPAL_VERSION < 7) {
751
-      _ec_variable_del('cron_semaphore');
752
-      $conf['cron_semaphore'] = false;
751
+        _ec_variable_del('cron_semaphore');
752
+        $conf['cron_semaphore'] = false;
753 753
     }
754 754
 
755 755
     $cron_completed = true;
756 756
 
757 757
     drupal_set_message(t('Job executed'));
758
-  }
758
+    }
759 759
 
760
-  drupal_goto(_dcf_internal_path('admin/config/system/cron'));
760
+    drupal_goto(_dcf_internal_path('admin/config/system/cron'));
761 761
 }
762 762
 
763 763
 function elysia_cron_execute_page_cleanup() {
764
-  global $cron_completed, $cron_executing_job;
764
+    global $cron_completed, $cron_executing_job;
765 765
 
766
-  if ($cron_completed) {
766
+    if ($cron_completed) {
767 767
     return;
768
-  }
768
+    }
769 769
 
770
-  // See if the semaphore is still locked.
771
-  if (elysia_cron_is_job_running($cron_executing_job)) {
770
+    // See if the semaphore is still locked.
771
+    if (elysia_cron_is_job_running($cron_executing_job)) {
772 772
     _dco_watchdog('cron', 'Unexpected termination of cron job %job manually started, aborted.', array('%job' => $cron_executing_job), WATCHDOG_WARNING);
773 773
 
774 774
     elysia_cron_set_job_running($cron_executing_job, 0);
775
-  }
775
+    }
776 776
 }
777 777
 
778 778
 function elysia_cron_maintenance_page() {
779
-  $output = array();
780
-  $output[] = drupal_get_form('elysia_cron_reset_statistics_form');
779
+    $output = array();
780
+    $output[] = drupal_get_form('elysia_cron_reset_statistics_form');
781 781
   
782
-  return _dcr_render_array($output);
782
+    return _dcr_render_array($output);
783 783
 }
784 784
 
785 785
 function elysia_cron_reset_statistics_form() {
786
-  $form = array();
787
-  $form['fieldset'] = array(
786
+    $form = array();
787
+    $form['fieldset'] = array(
788 788
     '#type' => 'fieldset',
789 789
     '#title' => t('Reset statistics'),
790 790
     '#description' => t('Deletes all cron execution statitics (Last run, last exec time, exec count, avg/max exec time...). Do not touch cron settings.<br /><b>This operation could not be reverted</b><br />'),
791
-  );
792
-  $form['fieldset']['reset'] = array(
791
+    );
792
+    $form['fieldset']['reset'] = array(
793 793
     '#type' => 'submit',
794 794
     '#value' => t('Reset'),
795 795
     '#attributes' => array(
796
-      'onclick' => 'return confirm(\'' . htmlentities(t('Are you sure you want to reset statistics?')) . '\')',
796
+        'onclick' => 'return confirm(\'' . htmlentities(t('Are you sure you want to reset statistics?')) . '\')',
797 797
     ),
798
-  );
799
-  return $form;
798
+    );
799
+    return $form;
800 800
 }
801 801
 
802 802
 function elysia_cron_reset_statistics_form_submit($_dco_form, &$_dco_form_state) {
803
-  elysia_cron_reset_stats();
803
+    elysia_cron_reset_stats();
804 804
   
805
-  drupal_set_message(t('Reset done.'));
806
-  drupal_goto(_dcf_internal_path('admin/config/system/cron/maintenance'));
805
+    drupal_set_message(t('Reset done.'));
806
+    drupal_goto(_dcf_internal_path('admin/config/system/cron/maintenance'));
807 807
 }
808 808
 
809 809
 function elysia_cron_reset_page() {
810
-  elysia_cron_reset_statistics_form_submit(false, $res = array());
810
+    elysia_cron_reset_statistics_form_submit(false, $res = array());
811 811
 }
Please login to merge, or discard this patch.
sites/default/boinc/modules/contrib/elysia_cron/elysia_drupalconv.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -7,96 +7,96 @@  discard block
 block discarded – undo
7 7
  ***************************************************************/
8 8
 
9 9
 function _dcf_hook_boot($module) {
10
-  return true;
10
+    return true;
11 11
 }
12 12
 
13 13
 function _dcf_hook_init($module) {
14
-  return true;
14
+    return true;
15 15
 }
16 16
 
17 17
 function _dcf_hook_menu($items, $maycache) {
18
-  $new_items = array();
19
-  foreach ($items as $k => $v)
18
+    $new_items = array();
19
+    foreach ($items as $k => $v)
20 20
     $new_items[_dcf_internal_path($k)] = $v;
21
-  return $new_items;
21
+    return $new_items;
22 22
 }
23 23
 
24 24
 function _dcf_convert_render_array(&$a) {
25
-  if (!empty($a['#markup'])) {
25
+    if (!empty($a['#markup'])) {
26 26
     $a['#value'] = $a['#markup'];
27 27
     unset($a['#markup']);
28
-  }
29
-  if (!empty($a['#type']) && $a['#type'] == 'actions')
28
+    }
29
+    if (!empty($a['#type']) && $a['#type'] == 'actions')
30 30
     unset($a['#type']);
31
-  foreach ($a as $k => &$v) 
31
+    foreach ($a as $k => &$v) 
32 32
     if (is_array($v))
33
-      _dcf_convert_render_array($v);
33
+        _dcf_convert_render_array($v);
34 34
 }
35 35
 
36 36
 function _dcr_render_array($output) {
37
-  foreach ($output as $k => &$v)
37
+    foreach ($output as $k => &$v)
38 38
     if ((is_numeric($k) || $k{0} != '#') && is_string($v))
39
-      $v = array( '#type' => 'markup', '#value' => $v, '#weight' => -1 );
40
-  _dcf_convert_render_array($output);
41
-  return drupal_render($output);
39
+        $v = array( '#type' => 'markup', '#value' => $v, '#weight' => -1 );
40
+    _dcf_convert_render_array($output);
41
+    return drupal_render($output);
42 42
 }
43 43
 
44 44
 function _dcr_form(&$form) {
45
-  foreach ($form as $k => &$v)
45
+    foreach ($form as $k => &$v)
46 46
     if ((is_numeric($k) || $k{0} != '#') && is_string($v))
47
-      $v = array( '#type' => 'markup', '#value' => $v, '#weight' => -1 );
48
-  _dcf_convert_render_array($form);
49
-  return $form;
47
+        $v = array( '#type' => 'markup', '#value' => $v, '#weight' => -1 );
48
+    _dcf_convert_render_array($form);
49
+    return $form;
50 50
 }
51 51
 
52 52
 function _dcf_internal_path($path) {
53
-  return str_replace(
53
+    return str_replace(
54 54
     array( 'admin/config/system/cron', 'admin/modules' ),
55 55
     array( 'admin/build/cron', 'admin/build/modules' ),
56 56
     $path
57
-  );
57
+    );
58 58
 }
59 59
   
60 60
 function _dcf_t($string) {
61
-  return t($string);
61
+    return t($string);
62 62
 }
63 63
 
64 64
 function _dco_watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { // WARN d7 changed WATCHDOG_ costants
65
-  return watchdog($type, $message, $variables, $severity, $link);
65
+    return watchdog($type, $message, $variables, $severity, $link);
66 66
 }
67 67
 
68 68
 function _dco_l($text, $path, array $options = array()) {
69
-  return l($text, $path, $options);
69
+    return l($text, $path, $options);
70 70
 }
71 71
 
72 72
 function _dcf_form_validate(&$form, &$form_state) {
73
-  return array('form' => &$form, 'form_state' => &$form_state);
73
+    return array('form' => &$form, 'form_state' => &$form_state);
74 74
 }
75 75
 
76 76
 function _dco_theme($name, $args) {
77
-  return call_user_func_array('theme', array_merge(array($name), array_values($args)));
77
+    return call_user_func_array('theme', array_merge(array($name), array_values($args)));
78 78
 }
79 79
 
80 80
 function _dcf_theme_signature($args) {
81
-  return array( 'variables' => $args );
81
+    return array( 'variables' => $args );
82 82
 }
83 83
 
84 84
 function _dcr_hook_theme($specs) {
85
-  foreach ($specs as $k => $v) {
85
+    foreach ($specs as $k => $v) {
86 86
     if (!empty($v['variables'])) {
87
-      $v['arguments'] = $v['variables'];
88
-      unset($v['variables']);
87
+        $v['arguments'] = $v['variables'];
88
+        unset($v['variables']);
89 89
     }
90 90
     if (!empty($v['render element'])) {
91
-      $v['arguments'] = array ( $v['render element'] => NULL );
92
-      unset($v['render element']);
91
+        $v['arguments'] = array ( $v['render element'] => NULL );
92
+        unset($v['render element']);
93
+    }
93 94
     }
94
-  }
95
-  return $specs;
95
+    return $specs;
96 96
 }
97 97
 
98 98
 function _dcf_theme_form(&$args) {
99
-  return array( 'variables' => array( 'form' => $args ) );
99
+    return array( 'variables' => array( 'form' => $args ) );
100 100
 }
101 101
 
102 102
 /***************************************************************
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
  ***************************************************************/
105 105
 
106 106
 function drupal_render_children($form) {
107
-  return drupal_render(_dcr_form($form));
107
+    return drupal_render(_dcr_form($form));
108 108
 }
109 109
 
110 110
 /***************************************************************
@@ -112,14 +112,14 @@  discard block
 block discarded – undo
112 112
  ***************************************************************/
113 113
 
114 114
 function drupal_module_get_min_weight($except_module = false) {
115
-  return !$except_module ? db_result(db_query("select min(weight) from {system}")) :
115
+    return !$except_module ? db_result(db_query("select min(weight) from {system}")) :
116 116
     db_result(db_query("select min(weight) from {system} where name != '%s'", $except_module));
117 117
 }
118 118
 
119 119
 function drupal_module_get_weight($name) {
120
-  return db_result(db_query("select weight from {system} where name = '%s'", $name));  
120
+    return db_result(db_query("select weight from {system} where name = '%s'", $name));  
121 121
 }
122 122
 
123 123
 function drupal_module_set_weight($name, $weight) {
124
-  db_query("update {system} set weight = %d where name = '%s'", $weight, $name);
124
+    db_query("update {system} set weight = %d where name = '%s'", $weight, $name);
125 125
 }
Please login to merge, or discard this patch.
sites/default/boinc/modules/contrib/elysia_cron/elysia_cron.ctools.inc 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@  discard block
 block discarded – undo
4 4
  * EXPORTABLES
5 5
  ******************************************************************************/
6 6
 
7
- // WARN Features button "Revert components" will reset also statistics 
7
+    // WARN Features button "Revert components" will reset also statistics 
8 8
  
9 9
 function elysia_cron_get_ctools_defaults() {
10
-  if (module_exists('ctools') && function_exists('ctools_include')) {
10
+    if (module_exists('ctools') && function_exists('ctools_include')) {
11 11
     ctools_include('export');
12 12
     if (function_exists('ctools_export_get_schema') && function_exists('_ctools_export_get_defaults') && ($schema = ctools_export_get_schema('elysia_cron'))) {
13
-      $export = $schema['export'];
14
-      return _ctools_export_get_defaults('elysia_cron', $export);
13
+        $export = $schema['export'];
14
+        return _ctools_export_get_defaults('elysia_cron', $export);
15 15
     }
16
-  }
17
-  return array();
16
+    }
17
+    return array();
18 18
 }
19 19
 
20 20
 /**
@@ -22,30 +22,30 @@  discard block
 block discarded – undo
22 22
  * Ctools does not support override of PARTIAL record, this is an elysia cron specific replacement to support it
23 23
  */
24 24
 function elysia_cron_ctools_export_load($name) {
25
-  $schema = ctools_export_get_schema('elysia_cron');
26
-  if (!empty($schema)) {
25
+    $schema = ctools_export_get_schema('elysia_cron');
26
+    if (!empty($schema)) {
27 27
     $export = $schema['export'];
28 28
     
29 29
     if (EC_DRUPAL_VERSION >= 7) {
30
-      $object = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = :name", array(':name' => $name))->fetch();
30
+        $object = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = :name", array(':name' => $name))->fetch();
31 31
     }
32 32
     else {
33
-      $object = db_fetch_object(db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = '%s'", $name));
33
+        $object = db_fetch_object(db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = '%s'", $name));
34 34
     }
35 35
     $default_objects = _ctools_export_get_defaults('elysia_cron', $export);
36 36
     
37 37
     if ($object) {
38
-      if (isset($default_objects[$name])) {
38
+        if (isset($default_objects[$name])) {
39 39
         return _elysia_cron_ctools_export_load_object_db_and_code($object, $default_objects[$name], $export);
40
-      }
41
-      else {
40
+        }
41
+        else {
42 42
         return _elysia_cron_ctools_export_load_object_db($object, $export);
43
-      }
43
+        }
44 44
     }
45 45
     elseif (isset($default_objects[$name])) {
46
-      return _elysia_cron_ctools_export_load_object_code($default_objects[$name], $export);
46
+        return _elysia_cron_ctools_export_load_object_code($default_objects[$name], $export);
47
+    }
47 48
     }
48
-  }
49 49
 }
50 50
 
51 51
 /**
@@ -53,75 +53,75 @@  discard block
 block discarded – undo
53 53
  * Ctools does not support override of PARTIAL record, this is an elysia cron specific replacement to support it
54 54
  */
55 55
 function elysia_cron_ctools_export_load_all() {
56
-  $schema = ctools_export_get_schema('elysia_cron');
57
-  if (empty($schema)) {
56
+    $schema = ctools_export_get_schema('elysia_cron');
57
+    if (empty($schema)) {
58 58
     return array();
59
-  }
60
-  $export = $schema['export'];
59
+    }
60
+    $export = $schema['export'];
61 61
     
62
-  if (EC_DRUPAL_VERSION >= 7) {
62
+    if (EC_DRUPAL_VERSION >= 7) {
63 63
     $objects = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron}")->fetchAll();
64
-  }
65
-  else {
64
+    }
65
+    else {
66 66
     $objects = array();
67 67
     $rs = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron}");
68 68
     while ($o = db_fetch_object($rs)) {
69
-      $objects[] = $o;
69
+        $objects[] = $o;
70
+    }
70 71
     }
71
-  }
72
-  $default_objects = _ctools_export_get_defaults('elysia_cron', $export);
72
+    $default_objects = _ctools_export_get_defaults('elysia_cron', $export);
73 73
   
74
-  $result = array();
75
-  foreach ($objects as $object) {
74
+    $result = array();
75
+    foreach ($objects as $object) {
76 76
     $key = $object->{$export['key']};
77 77
     if (isset($default_objects[$key])) {
78
-      $result[$key] = _elysia_cron_ctools_export_load_object_db_and_code($object, $default_objects[$key], $export);
79
-      unset($default_objects[$key]);
78
+        $result[$key] = _elysia_cron_ctools_export_load_object_db_and_code($object, $default_objects[$key], $export);
79
+        unset($default_objects[$key]);
80 80
     } else {
81
-      $result[$key] = _elysia_cron_ctools_export_load_object_db($object, $export);
81
+        $result[$key] = _elysia_cron_ctools_export_load_object_db($object, $export);
82 82
     } 
83
-  }
84
-  foreach ($default_objects as $key => $object) {
83
+    }
84
+    foreach ($default_objects as $key => $object) {
85 85
     $result[$key] = _elysia_cron_ctools_export_load_object_code($object, $export);
86
-  }
87
-  return $result;
86
+    }
87
+    return $result;
88 88
 }
89 89
 
90 90
 function _elysia_cron_ctools_export_load_object_db_and_code($object, $code_object, $export) {
91
-  $overridden = false;
92
-  foreach ($code_object as $keyd => $value) {
91
+    $overridden = false;
92
+    foreach ($code_object as $keyd => $value) {
93 93
     if (!isset($object->$keyd) || is_null($object->$keyd)) {
94
-      $object->$keyd = $value;
94
+        $object->$keyd = $value;
95 95
     }
96 96
     else if ($object->$keyd !== $value) {
97
-      $overridden = true;
97
+        $overridden = true;
98
+    }
98 99
     }
99
-  }
100
-  $object->table = 'elysia_cron';
101
-  $object->export_type = EXPORT_IN_DATABASE | EXPORT_IN_CODE;
102
-  if (!empty($export['export type string'])) {
100
+    $object->table = 'elysia_cron';
101
+    $object->export_type = EXPORT_IN_DATABASE | EXPORT_IN_CODE;
102
+    if (!empty($export['export type string'])) {
103 103
     $object->{$export['export type string']} = $overridden ? t('Overridden') : t('Normal');
104
-  }
105
-  return $object;
104
+    }
105
+    return $object;
106 106
 }
107 107
 
108 108
 function _elysia_cron_ctools_export_load_object_db($object, $export) {
109
-  $object->table = 'elysia_cron';
110
-  $object->export_type = EXPORT_IN_DATABASE;
111
-  if (!empty($export['export type string'])) {
109
+    $object->table = 'elysia_cron';
110
+    $object->export_type = EXPORT_IN_DATABASE;
111
+    if (!empty($export['export type string'])) {
112 112
     $object->{$export['export type string']} = t('Normal');
113
-  }
114
-  return $object;
113
+    }
114
+    return $object;
115 115
 }
116 116
 
117 117
 function _elysia_cron_ctools_export_load_object_code($object, $export) {
118
-  $object->table = 'elysia_cron';
119
-  $object->export_type = EXPORT_IN_CODE;
120
-  if (!empty($export['export type string'])) {
118
+    $object->table = 'elysia_cron';
119
+    $object->export_type = EXPORT_IN_CODE;
120
+    if (!empty($export['export type string'])) {
121 121
     $object->{$export['export type string']} = t('Default');
122
-  }
123
-  $object->in_code_only = TRUE;
124
-  return $object;
122
+    }
123
+    $object->in_code_only = TRUE;
124
+    return $object;
125 125
 }
126 126
 
127 127
 /**
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
  * This function does not support $schema['join'].
131 131
  */
132 132
 function elysia_cron_ctools_export_object_factory($schema, $data) {
133
-  $object = new stdClass;
133
+    $object = new stdClass;
134 134
 
135
-  foreach ($schema['fields'] as $field => $info) {
135
+    foreach ($schema['fields'] as $field => $info) {
136 136
     $object->$field = isset($data->$field) && !is_null($data->$field) ? (empty($info['serialize']) ? $data->$field : unserialize($data->$field)) : NULL;
137
-  }
137
+    }
138 138
 
139
-  return $object;
139
+    return $object;
140 140
 }
141 141
 
142 142
 /**
@@ -144,33 +144,33 @@  discard block
 block discarded – undo
144 144
  * Handles NULL value (it's not possible to do this with "field" export callback, because null values are rewritten before its call)
145 145
  */
146 146
 function elysia_cron_ctools_export_callback($object, $indent) {
147
-  $table = 'elysia_cron';
148
-  $schema = ctools_export_get_schema($table);
149
-  $identifier = $schema['export']['identifier'];
147
+    $table = 'elysia_cron';
148
+    $schema = ctools_export_get_schema($table);
149
+    $identifier = $schema['export']['identifier'];
150 150
 
151
-  $output = $indent . '$' . $identifier . ' = new ' . get_class($object) . ";\n";
151
+    $output = $indent . '$' . $identifier . ' = new ' . get_class($object) . ";\n";
152 152
 
153
-  if ($schema['export']['can disable']) {
153
+    if ($schema['export']['can disable']) {
154 154
     $output .= $indent . '$' . $identifier . '->disabled = FALSE; /* Edit this to true to make a default ' . $identifier . ' disabled initially */'  . "\n";
155
-  }
156
-  if (!empty($schema['export']['api']['current_version'])) {
155
+    }
156
+    if (!empty($schema['export']['api']['current_version'])) {
157 157
     $output .= $indent . '$' . $identifier . '->api_version = ' . $schema['export']['api']['current_version'] . ";\n";
158
-  }
158
+    }
159 159
 
160
-  $fields = $schema['fields'];
160
+    $fields = $schema['fields'];
161 161
 
162
-  foreach ($fields as $field => $info) {
162
+    foreach ($fields as $field => $info) {
163 163
     if (!empty($info['no export'])) {
164
-      continue;
164
+        continue;
165 165
     }
166 166
     $value = isset($object->$field) ? $object->$field : (isset($info['default']) ? $info['default'] : NULL);
167 167
     if (!is_null($value) && $info['type'] == 'int') {
168
-      $value = (isset($info['size']) && $info['size'] == 'tiny') ? (bool) $value : (int) $value;
168
+        $value = (isset($info['size']) && $info['size'] == 'tiny') ? (bool) $value : (int) $value;
169 169
     }
170 170
     $output .= $indent . '$' . $identifier . '->' . $field . ' = ' . ctools_var_export($value, $indent) . ";\n";
171
-  }
171
+    }
172 172
 
173
-  return $output;  
173
+    return $output;  
174 174
 }
175 175
 
176 176
 /**
@@ -179,25 +179,25 @@  discard block
 block discarded – undo
179 179
  * This code is equal to the original ctools one, but uses specific load callback 
180 180
  */
181 181
 function elysia_cron_ctools_to_hook_code($names, $name) {
182
-  $table = 'elysia_cron';
183
-  $schema = ctools_export_get_schema($table);
184
-  $export = $schema['export'];
185
-  $output = '';
186
-  $objects = elysia_cron_ctools_export_load_all();
187
-  $objects = array_intersect_key($objects, array_flip($names));
188
-  if ($objects) {
182
+    $table = 'elysia_cron';
183
+    $schema = ctools_export_get_schema($table);
184
+    $export = $schema['export'];
185
+    $output = '';
186
+    $objects = elysia_cron_ctools_export_load_all();
187
+    $objects = array_intersect_key($objects, array_flip($names));
188
+    if ($objects) {
189 189
     $output = "/**\n";
190 190
     $output .= " * Implementation of hook_{$export['default hook']}()\n";
191 191
     $output .= " */\n";
192 192
     $output .= "function " . $name . "_{$export['default hook']}() {\n";
193 193
     $output .= "  \${$export['identifier']}s = array();\n\n";
194 194
     foreach ($objects as $object) {
195
-      $output .= ctools_export_crud_export($table, $object, '  ');
196
-      $output .= "  \${$export['identifier']}s['" . check_plain($object->$export['key']) . "'] = \${$export['identifier']};\n\n";
195
+        $output .= ctools_export_crud_export($table, $object, '  ');
196
+        $output .= "  \${$export['identifier']}s['" . check_plain($object->$export['key']) . "'] = \${$export['identifier']};\n\n";
197 197
     }
198 198
     $output .= "  return \${$export['identifier']}s;\n";
199 199
     $output .= "}\n";
200
-  }
200
+    }
201 201
 
202
-  return $output;
202
+    return $output;
203 203
 }
Please login to merge, or discard this patch.
sites/default/boinc/modules/contrib/elysia_cron/elysia_cron_update.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -5,136 +5,136 @@  discard block
 block discarded – undo
5 5
  ******************************************************************************/
6 6
 
7 7
 function elysia_cron_check_version_update() {
8
-  $ver = variable_get('elysia_cron_version', 0);
9
-  if ($ver < 20111012) {
8
+    $ver = variable_get('elysia_cron_version', 0);
9
+    if ($ver < 20111012) {
10 10
     $ver = _ec_variable_get('elysia_cron_version', 0);
11
-  }
11
+    }
12 12
 
13
-  if (!$ver || $ver < 20090218) {
13
+    if (!$ver || $ver < 20090218) {
14 14
 
15 15
     $unchanged = array(
16
-      'elysia_cron_last_context',
17
-      'elysia_cron_last_run',
18
-      'elysia_cron_disabled',
19
-      'elysia_cron_semaphore',
20
-      'elysia_cron_key',
21
-      'elysia_cron_allowed_hosts',
22
-      'elysia_cron_default_rule',
23
-      'elysia_cron_script',
24
-      'elysia_cron_runtime_replacement',
25
-      'elysia_cron_version',
16
+        'elysia_cron_last_context',
17
+        'elysia_cron_last_run',
18
+        'elysia_cron_disabled',
19
+        'elysia_cron_semaphore',
20
+        'elysia_cron_key',
21
+        'elysia_cron_allowed_hosts',
22
+        'elysia_cron_default_rule',
23
+        'elysia_cron_script',
24
+        'elysia_cron_runtime_replacement',
25
+        'elysia_cron_version',
26 26
     );
27 27
 
28 28
     $rs = db_query('select * from {variable} where name like "elysia_cron_%%"');
29 29
     while ($v = db_fetch_object($rs)) {
30
-      if (!in_array($v->name, $unchanged)) {
30
+        if (!in_array($v->name, $unchanged)) {
31 31
         $vn = false;
32 32
         if (preg_match('/^elysia_cron_ctx_(.*)_(running|disabled|last_run|last_aborted|abort_count|execution_count|last_execution_time|avg_execution_time|max_execution_time|last_shutdown_time|last_abort_function)/', $v->name, $r)) {
33
-          switch ($r[2]) {
33
+            switch ($r[2]) {
34 34
             case 'running':
35 35
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_r';
36
-              break;
36
+                break;
37 37
             case 'disabled':
38 38
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_d';
39
-              break;
39
+                break;
40 40
             case 'last_run':
41 41
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_lr';
42
-              break;
42
+                break;
43 43
             case 'last_aborted':
44 44
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_la';
45
-              break;
45
+                break;
46 46
             case 'abort_count':
47 47
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_ac';
48
-              break;
48
+                break;
49 49
             case 'execution_count':
50 50
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_ec';
51
-              break;
51
+                break;
52 52
             case 'last_execution_time':
53 53
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_let';
54
-              break;
54
+                break;
55 55
             case 'avg_execution_time':
56 56
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_aet';
57
-              break;
57
+                break;
58 58
             case 'max_execution_time':
59 59
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_met';
60
-              break;
60
+                break;
61 61
             case 'last_shutdown_time':
62 62
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_lst';
63
-              break;
63
+                break;
64 64
             case 'last_abort_function':
65 65
               $vn = 'ecc_' . _ec_get_name($r[1]) . '_laf';
66
-              break;
67
-          }
66
+                break;
67
+            }
68 68
         }
69 69
         elseif (preg_match('/^elysia_cron_(.*)_(rule|disabled|context|running|last_run|last_execution_time|execution_count|avg_execution_time|max_execution_time)/', $v->name, $r)) {
70
-          switch ($r[2]) {
70
+            switch ($r[2]) {
71 71
             case 'rule':
72 72
               $vn = 'ec_' . _ec_get_name($r[1]) . '_rul';
73
-              break;
73
+                break;
74 74
             case 'disabled':
75 75
               $vn = 'ec_' . _ec_get_name($r[1]) . '_d';
76
-              break;
76
+                break;
77 77
             case 'context':
78 78
               $vn = 'ec_' . _ec_get_name($r[1]) . '_c';
79
-              break;
79
+                break;
80 80
             case 'running':
81 81
               $vn = 'ec_' . _ec_get_name($r[1]) . '_r';
82
-              break;
82
+                break;
83 83
             case 'last_run':
84 84
               $vn = 'ec_' . _ec_get_name($r[1]) . '_lr';
85
-              break;
85
+                break;
86 86
             case 'last_execution_time':
87 87
               $vn = 'ec_' . _ec_get_name($r[1]) . '_let';
88
-              break;
88
+                break;
89 89
             case 'execution_count':
90 90
               $vn = 'ec_' . _ec_get_name($r[1]) . '_ec';
91
-              break;
91
+                break;
92 92
             case 'avg_execution_time':
93 93
               $vn = 'ec_' . _ec_get_name($r[1]) . '_aet';
94
-              break;
94
+                break;
95 95
             case 'max_execution_time':
96 96
               $vn = 'ec_' . _ec_get_name($r[1]) . '_met';
97
-              break;
98
-          }
97
+                break;
98
+            }
99 99
         }
100 100
         if ($vn) {
101
-          variable_set($vn, unserialize($v->value));
101
+            variable_set($vn, unserialize($v->value));
102 102
         }
103 103
         else {
104
-          _dco_watchdog('cron', 'Error in update, cant convert %name (value: %value)', array('%name' => $v->name, '%value' => $v->value), WATCHDOG_ERROR);
104
+            _dco_watchdog('cron', 'Error in update, cant convert %name (value: %value)', array('%name' => $v->name, '%value' => $v->value), WATCHDOG_ERROR);
105 105
         }
106 106
 
107 107
         variable_del($v->name);
108
-      }
108
+        }
109 109
     }
110 110
 
111 111
     variable_set('elysia_cron_version', 20090218);
112
-  }
113
-  if ($ver < 20090920) {
112
+    }
113
+    if ($ver < 20090920) {
114 114
     variable_set('elysia_cron_version', 20090920);
115 115
 
116
-  }
117
-  if ($ver < 20100507) {
116
+    }
117
+    if ($ver < 20100507) {
118 118
     if (EC_DRUPAL_VERSION >= 6) {
119
-      // D6
120
-      drupal_install_schema('elysia_cron');
119
+        // D6
120
+        drupal_install_schema('elysia_cron');
121 121
 
122
-      // In ver 20111020 disabled has been renamed to disable, revert it now
123
-      if (EC_DRUPAL_VERSION >= 7) {
122
+        // In ver 20111020 disabled has been renamed to disable, revert it now
123
+        if (EC_DRUPAL_VERSION >= 7) {
124 124
         // D7
125 125
         // Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here)
126 126
         db_change_field($v = 'elysia_cron', 'disable', 'disabled', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
127 127
 
128
-      }
129
-      elseif (EC_DRUPAL_VERSION >= 6) {
128
+        }
129
+        elseif (EC_DRUPAL_VERSION >= 6) {
130 130
         // D6
131 131
         $ret = array();
132 132
         db_change_field($ret, 'elysia_cron', 'disable', 'disabled', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
133
-      }
133
+        }
134 134
     }
135 135
     else {
136
-      // D5
137
-      switch ($GLOBALS['db_type']) {
136
+        // D5
137
+        switch ($GLOBALS['db_type']) {
138 138
         case 'mysqli':
139 139
         case 'mysql':
140 140
           db_query("create table if not exists {elysia_cron} (
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             last_shutdown_time int(11) not null default '0',
156 156
             primary key (name)
157 157
           )");
158
-          break;
158
+            break;
159 159
         case 'pgsql':
160 160
           db_query("create table {elysia_cron} (
161 161
             name varchar(120) not null,
@@ -175,153 +175,153 @@  discard block
 block discarded – undo
175 175
             last_shutdown_time integer not null default '0',
176 176
             primary key (name)
177 177
           )");
178
-      }
178
+        }
179 179
     }
180 180
 
181 181
     $rs = db_query('select * from {variable} where name like "ec_%%" or name like "ecc_%%"');
182 182
     $data = array();
183 183
     $todelete = array();
184 184
     while ($v = db_fetch_object($rs)) {
185
-      $name = false;
186
-      if (preg_match('/^ecc_(.+)_(r|d|lr|la|ac|ec|let|aet|met|lst|laf)/', $v->name, $r)) {
185
+        $name = false;
186
+        if (preg_match('/^ecc_(.+)_(r|d|lr|la|ac|ec|let|aet|met|lst|laf)/', $v->name, $r)) {
187 187
         $name = ':' . $r[1];
188
-      }
189
-      elseif (preg_match('/^ec_(.+)_(rul|d|c|w|r|lr|let|ec|aet|met)/', $v->name, $r)) {
188
+        }
189
+        elseif (preg_match('/^ec_(.+)_(rul|d|c|w|r|lr|let|ec|aet|met)/', $v->name, $r)) {
190 190
         $name = $r[1];
191
-      }
192
-      if ($name) {
191
+        }
192
+        if ($name) {
193 193
         if (!isset($data[$name])) {
194
-          $data[$name] = array('name' => $name);
194
+            $data[$name] = array('name' => $name);
195 195
         }
196 196
         switch ($r[2]) {
197
-          case 'r':
197
+            case 'r':
198 198
             $f = 'running';
199 199
             break;
200
-          case 'd':
200
+            case 'd':
201 201
             $f = 'disabled';
202 202
             break;
203
-          case 'rul':
203
+            case 'rul':
204 204
             $f = 'rule';
205 205
             break;
206
-          case 'w':
206
+            case 'w':
207 207
             $f = 'weight';
208 208
             break;
209
-          case 'c':
209
+            case 'c':
210 210
             $f = 'context';
211 211
             break;
212
-          case 'lr':
212
+            case 'lr':
213 213
             $f = 'last_run';
214 214
             break;
215
-          case 'la':
215
+            case 'la':
216 216
             $f = 'last_aborted';
217 217
             break;
218
-          case 'ac':
218
+            case 'ac':
219 219
             $f = 'abort_count';
220 220
             break;
221
-          case 'laf':
221
+            case 'laf':
222 222
             $f = 'last_abort_function';
223 223
             break;
224
-          case 'let':
224
+            case 'let':
225 225
             $f = 'last_execution_time';
226 226
             break;
227
-          case 'ec':
227
+            case 'ec':
228 228
             $f = 'execution_count';
229 229
             break;
230
-          case 'aet':
230
+            case 'aet':
231 231
             $f = 'avg_execution_time';
232 232
             break;
233
-          case 'met':
233
+            case 'met':
234 234
             $f = 'max_execution_time';
235 235
             break;
236
-          case 'lst':
236
+            case 'lst':
237 237
             $f = 'last_shutdown_time';
238 238
             break;
239 239
         }
240 240
         $data[$name][$f] = unserialize($v->value);
241 241
         $todelete[] = $v->name;
242
-      }
242
+        }
243 243
     }
244 244
 
245 245
     $ifields = array('disabled', 'weight', 'running', 'last_run', 'last_aborted', 'abort_count', 'last_execution_time', 'execution_count', 'avg_execution_time', 'max_execution_time', 'last_shutdown_time');
246 246
     foreach ($data as $v) {
247
-      foreach ($ifields as $f) {
247
+        foreach ($ifields as $f) {
248 248
         if (empty($v[$f])) {
249
-          $v[$f] = 0;
249
+            $v[$f] = 0;
250
+        }
250 251
         }
251
-      }
252
-      db_query("insert into {elysia_cron} (name, disabled, rule, weight, context, running, last_run, last_aborted, abort_count, last_abort_function, last_execution_time, execution_count, avg_execution_time, max_execution_time, last_shutdown_time)
252
+        db_query("insert into {elysia_cron} (name, disabled, rule, weight, context, running, last_run, last_aborted, abort_count, last_abort_function, last_execution_time, execution_count, avg_execution_time, max_execution_time, last_shutdown_time)
253 253
         values ('%s', %d, '%s', %d, '%s', %d, %d, %d, %d, '%s', %d, %d, %f, %d, %d)",
254 254
         $v['name'], $v['disabled'], $v['rule'], $v['weight'], $v['context'], $v['running'], $v['last_run'], $v['last_aborted'], $v['abort_count'], $v['last_abort_function'], $v['last_execution_time'], $v['execution_count'], $v['avg_execution_time'], $v['max_execution_time'], $v['last_shutdown_time']
255
-      );
255
+        );
256 256
     }
257 257
 
258 258
     db_query("update {elysia_cron} set context = null where context = ''");
259 259
     db_query("update {elysia_cron} set rule = null where rule = ''");
260 260
 
261 261
     foreach ($todelete as $v) {
262
-      variable_del($v);
263
-      db_query("DELETE FROM {variable} WHERE name = '%s'", $v);
262
+        variable_del($v);
263
+        db_query("DELETE FROM {variable} WHERE name = '%s'", $v);
264 264
     }
265 265
 
266 266
     variable_set('elysia_cron_version', 20100507);
267 267
 
268 268
     unset($GLOBALS['_ec_variables']);
269
-  }
270
-  // D7 VERSION FROM NOW ON...
269
+    }
270
+    // D7 VERSION FROM NOW ON...
271 271
 
272
-  if ($ver < 20110323) {
272
+    if ($ver < 20110323) {
273 273
     if (EC_DRUPAL_VERSION >= 7) {
274
-      // D7
275
-      // Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here)
276
-      db_change_field($v = 'elysia_cron', 'weight', 'weight', array('type' => 'int', 'not null' => FALSE));
274
+        // D7
275
+        // Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here)
276
+        db_change_field($v = 'elysia_cron', 'weight', 'weight', array('type' => 'int', 'not null' => FALSE));
277 277
 
278 278
     }
279 279
     elseif (EC_DRUPAL_VERSION >= 6) {
280
-      // D6
281
-      $ret = array();
282
-      db_change_field($ret, 'elysia_cron', 'weight', 'weight', array('type' => 'int', 'not null' => FALSE));
280
+        // D6
281
+        $ret = array();
282
+        db_change_field($ret, 'elysia_cron', 'weight', 'weight', array('type' => 'int', 'not null' => FALSE));
283 283
     }
284 284
     else {
285
-      // D5
286
-      db_query("alter table {elysia_cron} change weight weight int(11)");
285
+        // D5
286
+        db_query("alter table {elysia_cron} change weight weight int(11)");
287 287
     }
288 288
 
289 289
     variable_set('elysia_cron_version', 20110323);
290
-  }
290
+    }
291 291
   
292
-  if ($ver < 20111007) {
292
+    if ($ver < 20111007) {
293 293
     $default_rules = variable_get('elysia_cron_default_rules', $GLOBALS['elysia_cron_default_rules']);
294 294
     if (!empty($default_rules['*/6 * * * *']) && $default_rules['*/6 * * * *'] == 'Every 6 hours') {
295
-      unset($default_rules['*/6 * * * *']);
296
-      $default_rules['0 */6 * * *'] = 'Every 6 hours';
297
-      variable_set('elysia_cron_default_rules', $default_rules);
295
+        unset($default_rules['*/6 * * * *']);
296
+        $default_rules['0 */6 * * *'] = 'Every 6 hours';
297
+        variable_set('elysia_cron_default_rules', $default_rules);
298 298
     }
299 299
     variable_set('elysia_cron_version', 20111007);
300
-  }
300
+    }
301 301
 
302
-  if ($ver < 20111012) {
302
+    if ($ver < 20111012) {
303 303
     // I only need to rebuild variable cache, so i just set the new version
304 304
     variable_set('elysia_cron_version', 20111012);
305
-  }
305
+    }
306 306
 
307
-  if ($ver < 20111020) {
307
+    if ($ver < 20111020) {
308 308
     if (EC_DRUPAL_VERSION >= 7) {
309
-      // D7
310
-      // Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here)
311
-      db_change_field($v = 'elysia_cron', 'disabled', 'disable', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
309
+        // D7
310
+        // Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here)
311
+        db_change_field($v = 'elysia_cron', 'disabled', 'disable', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
312 312
 
313 313
     }
314 314
     elseif (EC_DRUPAL_VERSION >= 6) {
315
-      // D6
316
-      $ret = array();
317
-      db_change_field($ret, 'elysia_cron', 'disabled', 'disable', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
315
+        // D6
316
+        $ret = array();
317
+        db_change_field($ret, 'elysia_cron', 'disabled', 'disable', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
318 318
     }
319 319
     else {
320
-      // D5
321
-      db_query("alter table {elysia_cron} change disabled disable tinyint(1)");
320
+        // D5
321
+        db_query("alter table {elysia_cron} change disabled disable tinyint(1)");
322 322
     }
323 323
     db_query("update {elysia_cron} set disable = NULL where disable = 0");
324 324
 
325 325
     variable_set('elysia_cron_version', 20111020);
326
-  }
326
+    }
327 327
 }
Please login to merge, or discard this patch.
sites/default/boinc/modules/contrib/elysia_cron/elysia_cron_scheduler.inc 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -1,164 +1,164 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 function elysia_cron_should_run($conf, $now = -1) {  $prev_rule_run = 0; // A che ora SAREBBE dovuto essere lanciato l'ultima volta
4
-  if ($conf['disabled']) {
4
+    if ($conf['disabled']) {
5 5
     return false;
6
-  }
7
-  if ($now < 0) {
6
+    }
7
+    if ($now < 0) {
8 8
     $now = time();
9
-  }
10
-  if ((!$conf['last_run']) || ($now - $conf['last_run'] > 365 * 86400)) {
9
+    }
10
+    if ((!$conf['last_run']) || ($now - $conf['last_run'] > 365 * 86400)) {
11 11
     return true;
12
-  }
12
+    }
13 13
 
14
-  $next_run = _elysia_cron_next_run($conf);
15
-  return $now >= $next_run;
14
+    $next_run = _elysia_cron_next_run($conf);
15
+    return $now >= $next_run;
16 16
 }
17 17
 
18 18
 function _elysia_cron_next_run($conf) {
19
-  $ranges = array(
19
+    $ranges = array(
20 20
     array(0, 59),
21 21
     array(0, 23),
22 22
     array(1, 31), // TODO
23 23
     array(1, 12),
24 24
     array(0, 3000),
25 25
     array(0, 6),
26
-  );
26
+    );
27 27
 
28
-  if (!preg_match('/^([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)$/', $conf['rule'], $rules)) {
28
+    if (!preg_match('/^([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)$/', $conf['rule'], $rules)) {
29 29
     _dco_watchdog('cron', 'Invalid rule found: %rule', array('%rule' => $conf['rule']));
30 30
     return false;
31
-  }
31
+    }
32 32
 
33
-  $rule = array($rules[1], $rules[2], array($rules[3], $rules[5]), $rules[4]);
34
-  $ruledec = array();
35
-  $date = __cronDecodeDate($conf['last_run'], 1);
36
-  $expected_date = __cronDecodeDate(!empty($conf['last_run_expected']) ? $conf['last_run_expected'] : 0);
33
+    $rule = array($rules[1], $rules[2], array($rules[3], $rules[5]), $rules[4]);
34
+    $ruledec = array();
35
+    $date = __cronDecodeDate($conf['last_run'], 1);
36
+    $expected_date = __cronDecodeDate(!empty($conf['last_run_expected']) ? $conf['last_run_expected'] : 0);
37 37
   
38
-  for ($i = 0; $i < 4; $i++) {
38
+    for ($i = 0; $i < 4; $i++) {
39 39
     if ($i != 2) {
40
-      // Standard scheme for mins, hours, month
41
-      $ruledec[$i] = __cronDecodeRule($rule[$i], $ranges[$i][0], $ranges[$i][1]);
40
+        // Standard scheme for mins, hours, month
41
+        $ruledec[$i] = __cronDecodeRule($rule[$i], $ranges[$i][0], $ranges[$i][1]);
42 42
     } else {
43
-      // For mday+week we follow another scheme
44
-      $ruledec[$i] = __cronDecodeRuleMday($rule[2], $date[3], $date[4]);
43
+        // For mday+week we follow another scheme
44
+        $ruledec[$i] = __cronDecodeRuleMday($rule[2], $date[3], $date[4]);
45 45
     }
46 46
     $r = $ruledec[$i];
47 47
     $new = $date[$i];
48 48
     if ($r['d']) {
49
-      if ($expected_date[$i] > $date[$i]) {
49
+        if ($expected_date[$i] > $date[$i]) {
50 50
         $expected_date[$i] -= $ranges[$i][1] + 1;
51
-      }
52
-      $new = $expected_date[$i] + ceil(($date[$i] - $expected_date[$i]) / $r['d']) * $r['d'];
51
+        }
52
+        $new = $expected_date[$i] + ceil(($date[$i] - $expected_date[$i]) / $r['d']) * $r['d'];
53 53
     }
54 54
     elseif ($r['n']) {
55
-      $new = __cronNextOrEqual($date[$i], $r['n'], $ranges[$i][0], $ranges[$i][1]);
55
+        $new = __cronNextOrEqual($date[$i], $r['n'], $ranges[$i][0], $ranges[$i][1]);
56 56
     }
57 57
     if ($new != $date[$i]) {
58
-      $date[$i] = $new;
59
-      if ($date[$i] > $ranges[$i][1]) {
58
+        $date[$i] = $new;
59
+        if ($date[$i] > $ranges[$i][1]) {
60 60
         $date[$i + 1]++;
61 61
         $date[$i] = $ranges[$i][0] + $date[$i] - $ranges[$i][1] - 1;
62
-      }
63
-      for ($j = 0; $j < $i; $j++) {
62
+        }
63
+        for ($j = 0; $j < $i; $j++) {
64 64
         if ($j == 2) {
65
-          // For mday+week decoded rule could be changed (by month+year)
66
-          $ruledec[$j] = __cronDecodeRuleMday($rule[2], $date[3], $date[4]);
65
+            // For mday+week decoded rule could be changed (by month+year)
66
+            $ruledec[$j] = __cronDecodeRuleMday($rule[2], $date[3], $date[4]);
67 67
         }
68 68
         $date[$j] = $ruledec[$j]['d'] ? ($ranges[$j][0] == 0 ? 0 : $ruledec[$j]['d']) : ($ruledec[$j]['n'] ? reset($ruledec[$j]['n']) : $ranges[$j][0]);
69 69
         $expected_date[$j] = 0;
70
-      }
70
+        }
71
+    }
71 72
     }
72
-  }
73 73
 
74
-  return __cronEncodeDate($date);
74
+    return __cronEncodeDate($date);
75 75
 }
76 76
 
77 77
 function __cronDecodeDate($timestamp, $min_diff = 0) {
78
-  $time = floor($timestamp / 60);
79
-  $time += $min_diff;
78
+    $time = floor($timestamp / 60);
79
+    $time += $min_diff;
80 80
   
81
-  $date = $time ? getdate($time * 60) : 0;
82
-  $date = array(
81
+    $date = $time ? getdate($time * 60) : 0;
82
+    $date = array(
83 83
     $time ? $date['minutes'] : 0,
84 84
     $time ? $date['hours'] : 0,
85 85
     $time ? $date['mday'] : 0,
86 86
     $time ? $date['mon'] : 0,
87 87
     $time ? $date['year'] : 0,
88
-  );
89
-  return $date;
88
+    );
89
+    return $date;
90 90
 }
91 91
 function __cronEncodeDate($date) {
92
-  return mktime($date[1], $date[0], 0, $date[3], $date[2], $date[4]);
92
+    return mktime($date[1], $date[0], 0, $date[3], $date[2], $date[4]);
93 93
 }
94 94
 
95 95
 function __cronNextOrEqual($el, $arr, $range_start, $range_end) {
96
-  if (empty($arr)) {
96
+    if (empty($arr)) {
97 97
     return $el;
98
-  }
99
-  foreach ($arr as $x) {
98
+    }
99
+    foreach ($arr as $x) {
100 100
     if ($x >= $el) {
101
-      return $x;
101
+        return $x;
102 102
     }
103
-  }
104
-  return $range_end + reset($arr) + 1 - $range_start;
103
+    }
104
+    return $range_end + reset($arr) + 1 - $range_start;
105 105
 }
106 106
 
107 107
 function __cronDecodeRule($rule, $min, $max) {
108
-  if ($rule == '*') {
108
+    if ($rule == '*') {
109 109
     return array('n' => array(), 'd' => 0);
110
-  }
110
+    }
111 111
 
112
-  $result = array('n' => array(), 'd' => 0);
113
-  foreach (explode(',', $rule) as $token) {
112
+    $result = array('n' => array(), 'd' => 0);
113
+    foreach (explode(',', $rule) as $token) {
114 114
     if (preg_match('/^([0-9]+)-([0-9]+)$/', $token, $r)) {
115
-      $result['n'] = array_merge($result['n'], range($r[1], $r[2]));
115
+        $result['n'] = array_merge($result['n'], range($r[1], $r[2]));
116 116
     }
117 117
     elseif (preg_match('/^\*\/([0-9]+)$/', $token, $r)) {
118
-      $result['d'] = $r[1];
118
+        $result['d'] = $r[1];
119 119
     }
120 120
     elseif (is_numeric($token)) {
121
-      $result['n'][] = $token;
121
+        $result['n'][] = $token;
122 122
     }
123
-  }
124
-  sort($result['n']);
125
-  return $result;
123
+    }
124
+    sort($result['n']);
125
+    return $result;
126 126
 }
127 127
 
128 128
 function __cronDecodeRuleMday($rule, $month, $year) {
129
-  $range_from = 1;
130
-  $range_to = $month != 2 ? (in_array($month, array(4,6,9,11)) ? 30 : 31) : ($year % 4 == 0 ? 29 : 28);
131
-  $r1 = __cronDecodeRule($rule[0], $range_from, $range_to);
132
-  $r2 = __cronDecodeRule($rule[1], $range_from, $range_to);
133
-  if ($r2['d']) {
129
+    $range_from = 1;
130
+    $range_to = $month != 2 ? (in_array($month, array(4,6,9,11)) ? 30 : 31) : ($year % 4 == 0 ? 29 : 28);
131
+    $r1 = __cronDecodeRule($rule[0], $range_from, $range_to);
132
+    $r2 = __cronDecodeRule($rule[1], $range_from, $range_to);
133
+    if ($r2['d']) {
134 134
     for ($i = 0; $i < 7; $i++) {
135
-      if ($i % $r2['d'] == 0) {
135
+        if ($i % $r2['d'] == 0) {
136 136
         $r2['n'][] = $i;
137
-      }
137
+        }
138 138
     }
139
-  }
140
-  if ($r2['n']) {
139
+    }
140
+    if ($r2['n']) {
141 141
     $r2['n'] = array_unique($r2['n']);
142 142
     $r1['n'] = array_merge($r1['n'], __cronMonDaysFromWeekDays($year, $month, $r2['n']), __cronMonDaysFromWeekDays($year, $month + 1, $r2['n'], $range_to));
143
-  }
144
-  return $r1;
143
+    }
144
+    return $r1;
145 145
 }
146 146
 
147 147
 // Used by elysia_cron_should_run
148 148
 function __cronMonDaysFromWeekDays($year, $mon, $weekdays, $offset = 0) {
149
-  if ($mon > 12) {
149
+    if ($mon > 12) {
150 150
     $year ++;
151 151
     $mon = $mon - 12;
152
-  }
152
+    }
153 153
   
154
-  $result = array();
155
-  for ($i = 1; checkdate($mon, $i, $year); $i++) {
154
+    $result = array();
155
+    for ($i = 1; checkdate($mon, $i, $year); $i++) {
156 156
     $w = date('w', mktime(12, 00, 00, $mon, $i, $year));
157 157
     if (in_array($w, $weekdays)) {
158
-      $result[] = $i + $offset;
158
+        $result[] = $i + $offset;
159
+    }
159 160
     }
160
-  }
161
-  return $result;
161
+    return $result;
162 162
 }
163 163
 
164 164
 /*******************************************************************************
@@ -166,73 +166,73 @@  discard block
 block discarded – undo
166 166
  ******************************************************************************/
167 167
 
168 168
 function test_elysia_cron_should_run() {
169
-  dprint("Start test");
170
-  $start = microtime(true);
169
+    dprint("Start test");
170
+    $start = microtime(true);
171 171
   
172
-  //mktime: hr min sec mon day yr
173
-  dprint(" 1." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(12, 01, 0, 1, 2, 2008))));
174
-  dprint(" 2." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(15, 00, 0, 1, 2, 2008))));
175
-  dprint(" 3." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(11, 59, 0, 1, 3, 2008))));
176
-  dprint(" 4." . (true  == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(12, 00, 0, 1, 3, 2008))));
177
-  dprint(" 5." . (false == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(0, 00, 0, 1, 3, 2008))));
178
-  dprint(" 6." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(23, 59, 0, 1, 3, 2008))));
179
-  dprint(" 7." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(0, 00, 0, 1, 4, 2008))));
180
-  dprint(" 8." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 58, 0, 1, 2, 2008)), mktime(23, 59, 0, 1, 2, 2008))));
181
-  dprint(" 9." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 58, 0, 1, 2, 2008)), mktime(0, 0, 0, 1, 3, 2008))));
182
-  dprint("10." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
183
-  dprint("11." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(0, 0, 0, 1, 6, 2008))));
184
-  dprint("12." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
185
-  dprint("13." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(00, 00, 0, 1, 7, 2008))));
186
-  dprint("14." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 6, 2008))));
187
-  dprint("15." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
188
-  dprint("16." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
189
-  dprint("17." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 58, 0, 1, 6, 2008))));
190
-  dprint("18." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 28, 0, 1, 6, 2008))));
191
-  dprint("19." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 5, 2008))));
192
-  dprint("20." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 30, 0, 1, 5, 2008))));
193
-  dprint("21." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
194
-  dprint("22." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 6, 2008))));
195
-
196
-  dprint("23." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 28, 2008))));
197
-  dprint("24." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 29, 2008))));
198
-  dprint("25." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(0, 0, 0, 3, 1, 2008))));
199
-
200
-  dprint("26." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(0, 0, 0, 1, 1, 2009))));
201
-  dprint("27." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(0, 0, 0, 1, 7, 2009))));
202
-  dprint("28." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(23, 59, 0, 1, 7, 2009))));
203
-
204
-  dprint("29." . (true  == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 29, 2008))));
205
-  dprint("30." . (true  == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(0, 0, 0, 3, 1, 2008))));
206
-  dprint("31." . (false == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 59, 0, 3, 7, 2008))));
207
-  dprint("32." . (false == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 58, 0, 2, 6, 2009))));
208
-  dprint("33." . (true  == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 59, 0, 2, 6, 2009))));
209
-  dprint("34." . (true  == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 58, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 10, 2008))));
210
-  dprint("35." . (false == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 59, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 11, 2008))));
211
-  dprint("36." . (true  == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 59, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 20, 2008))));
212
-  dprint("37." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
213
-  dprint("38." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
214
-  dprint("39." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
215
-  dprint("40." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 58, 0, 1, 10, 2008))));
216
-  dprint("41." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 10, 2008))));
217
-  dprint("42." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 16, 2008))));
218
-
219
-  dprint("43." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
220
-  dprint("44." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
221
-  dprint("45." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 6, 2008)), mktime(23, 59, 0, 1, 7, 2008))));
222
-  dprint("46." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 6, 2008)), mktime(23, 59, 0, 1, 13, 2008))));
223
-  dprint("47." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 4, 2008)), mktime(23, 59, 0, 2, 5, 2008))));
224
-  dprint("48." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 5, 2008)), mktime(23, 59, 0, 2, 10, 2008))));
225
-  dprint("49." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 10, 2008)), mktime(23, 59, 0, 2, 17, 2008))));
226
-
227
-  dprint("49." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 58, 0, 2, 10, 2008)), mktime(8, 59, 0, 2, 10, 2008))));
228
-  dprint("50." . (false == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(9, 00, 0, 2, 10, 2008))));
229
-  dprint("51." . (false == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(17, 59, 0, 2, 10, 2008))));
230
-  dprint("52." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(18, 00, 0, 2, 10, 2008))));
231
-  dprint("53." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(18, 01, 0, 2, 10, 2008))));
232
-  dprint("54." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(19, 0, 0, 2, 10, 2008))));
233
-  dprint("55." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(9, 0, 0, 3, 10, 2008))));
234
-
235
-  dprint("End test (" . (microtime(true) - $start) . ")");
172
+    //mktime: hr min sec mon day yr
173
+    dprint(" 1." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(12, 01, 0, 1, 2, 2008))));
174
+    dprint(" 2." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(15, 00, 0, 1, 2, 2008))));
175
+    dprint(" 3." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(11, 59, 0, 1, 3, 2008))));
176
+    dprint(" 4." . (true  == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(12, 00, 0, 1, 3, 2008))));
177
+    dprint(" 5." . (false == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(0, 00, 0, 1, 3, 2008))));
178
+    dprint(" 6." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(23, 59, 0, 1, 3, 2008))));
179
+    dprint(" 7." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(0, 00, 0, 1, 4, 2008))));
180
+    dprint(" 8." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 58, 0, 1, 2, 2008)), mktime(23, 59, 0, 1, 2, 2008))));
181
+    dprint(" 9." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 58, 0, 1, 2, 2008)), mktime(0, 0, 0, 1, 3, 2008))));
182
+    dprint("10." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
183
+    dprint("11." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(0, 0, 0, 1, 6, 2008))));
184
+    dprint("12." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
185
+    dprint("13." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(00, 00, 0, 1, 7, 2008))));
186
+    dprint("14." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 6, 2008))));
187
+    dprint("15." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
188
+    dprint("16." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
189
+    dprint("17." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 58, 0, 1, 6, 2008))));
190
+    dprint("18." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 28, 0, 1, 6, 2008))));
191
+    dprint("19." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 5, 2008))));
192
+    dprint("20." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 30, 0, 1, 5, 2008))));
193
+    dprint("21." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
194
+    dprint("22." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 6, 2008))));
195
+
196
+    dprint("23." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 28, 2008))));
197
+    dprint("24." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 29, 2008))));
198
+    dprint("25." . (true  == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(0, 0, 0, 3, 1, 2008))));
199
+
200
+    dprint("26." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(0, 0, 0, 1, 1, 2009))));
201
+    dprint("27." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(0, 0, 0, 1, 7, 2009))));
202
+    dprint("28." . (true  == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(23, 59, 0, 1, 7, 2009))));
203
+
204
+    dprint("29." . (true  == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 29, 2008))));
205
+    dprint("30." . (true  == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(0, 0, 0, 3, 1, 2008))));
206
+    dprint("31." . (false == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 59, 0, 3, 7, 2008))));
207
+    dprint("32." . (false == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 58, 0, 2, 6, 2009))));
208
+    dprint("33." . (true  == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 59, 0, 2, 6, 2009))));
209
+    dprint("34." . (true  == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 58, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 10, 2008))));
210
+    dprint("35." . (false == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 59, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 11, 2008))));
211
+    dprint("36." . (true  == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 59, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 20, 2008))));
212
+    dprint("37." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
213
+    dprint("38." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
214
+    dprint("39." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
215
+    dprint("40." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 58, 0, 1, 10, 2008))));
216
+    dprint("41." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 10, 2008))));
217
+    dprint("42." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 16, 2008))));
218
+
219
+    dprint("43." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
220
+    dprint("44." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
221
+    dprint("45." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 6, 2008)), mktime(23, 59, 0, 1, 7, 2008))));
222
+    dprint("46." . (true  == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 6, 2008)), mktime(23, 59, 0, 1, 13, 2008))));
223
+    dprint("47." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 4, 2008)), mktime(23, 59, 0, 2, 5, 2008))));
224
+    dprint("48." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 5, 2008)), mktime(23, 59, 0, 2, 10, 2008))));
225
+    dprint("49." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 10, 2008)), mktime(23, 59, 0, 2, 17, 2008))));
226
+
227
+    dprint("49." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 58, 0, 2, 10, 2008)), mktime(8, 59, 0, 2, 10, 2008))));
228
+    dprint("50." . (false == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(9, 00, 0, 2, 10, 2008))));
229
+    dprint("51." . (false == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(17, 59, 0, 2, 10, 2008))));
230
+    dprint("52." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(18, 00, 0, 2, 10, 2008))));
231
+    dprint("53." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(18, 01, 0, 2, 10, 2008))));
232
+    dprint("54." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(19, 0, 0, 2, 10, 2008))));
233
+    dprint("55." . (true  == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(9, 0, 0, 3, 10, 2008))));
234
+
235
+    dprint("End test (" . (microtime(true) - $start) . ")");
236 236
 }
237 237
 // Remove comment to run tests
238 238
 //test_elysia_cron_should_run();die();
Please login to merge, or discard this patch.
drupal/sites/default/boinc/modules/contrib/elysia_cron/cron.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@  discard block
 block discarded – undo
6 6
  */
7 7
 
8 8
 if (!file_exists('includes/bootstrap.inc')) {
9
-  if (!empty($_SERVER['DOCUMENT_ROOT']) && file_exists($_SERVER['DOCUMENT_ROOT'] . '/includes/bootstrap.inc')) {
9
+    if (!empty($_SERVER['DOCUMENT_ROOT']) && file_exists($_SERVER['DOCUMENT_ROOT'] . '/includes/bootstrap.inc')) {
10 10
     chdir($_SERVER['DOCUMENT_ROOT']);
11
-  } elseif (preg_match('@^(.*)[\\\\/]sites[\\\\/][^\\\\/]+[\\\\/]modules[\\\\/]([^\\\\/]+[\\\\/])?elysia(_cron)?$@', getcwd(), $r) && file_exists($r[1] . '/includes/bootstrap.inc')) {
11
+    } elseif (preg_match('@^(.*)[\\\\/]sites[\\\\/][^\\\\/]+[\\\\/]modules[\\\\/]([^\\\\/]+[\\\\/])?elysia(_cron)?$@', getcwd(), $r) && file_exists($r[1] . '/includes/bootstrap.inc')) {
12 12
     chdir($r[1]);
13
-  } else {
13
+    } else {
14 14
     die("Cron Fatal Error: Can't locate bootstrap.inc. Check cron.php position.");
15
-  }
15
+    }
16 16
 }
17 17
 
18 18
 include_once './includes/bootstrap.inc';
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
21 21
 
22 22
 if (function_exists('elysia_cron_run')) {
23
-  elysia_cron_run();
23
+    elysia_cron_run();
24 24
 }
25 25
 else {
26
-  drupal_cron_run();
26
+    drupal_cron_run();
27 27
 }
Please login to merge, or discard this patch.
sites/default/boinc/modules/contrib/elysia_cron/elysia_cron.drush.inc 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,15 +8,15 @@  discard block
 block discarded – undo
8 8
  * Implementation of hook_drush_command().
9 9
  */
10 10
 function elysia_cron_drush_command() {
11
-  $items = array();
11
+    $items = array();
12 12
 
13
-  $items['elysia-cron'] = array(
13
+    $items['elysia-cron'] = array(
14 14
     'description' => "Run all cron hooks in all active modules for specified site using elysia cron system. Use this instead of \"core-cron\" if elysia_cron module is installed",
15 15
     'callback'    => 'drush_elysia_cron_run_wrapper',
16 16
     'arguments' => array(),
17
-  );
17
+    );
18 18
 
19
-  return $items;
19
+    return $items;
20 20
 }
21 21
 
22 22
 /**
@@ -25,5 +25,5 @@  discard block
 block discarded – undo
25 25
  * wraps the elysia_cron_run function, passing manual = true
26 26
  */
27 27
 function drush_elysia_cron_run_wrapper() {
28
-  return elysia_cron_run(TRUE);
28
+    return elysia_cron_run(TRUE);
29 29
 }
Please login to merge, or discard this patch.
html/ops/show_log.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
 echo 'Hint: Example greps: "RESULT#106876", "26fe99aa_25636_00119.wu_1", "WU#8152", "too many errors", "2003-07-17", "CRITICAL" <br>';
61 61
 
62 62
 if (strlen($f)) {
63
-	$f = "../log*/". $f;
63
+    $f = "../log*/". $f;
64 64
 } else {
65 65
     $f = "../log*/*.log";
66 66
 }
Please login to merge, or discard this patch.