diff --git a/application/config/migration.php b/application/config/migration.php index e527bb97e..dedcda982 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 258; +$config['migration_version'] = 259; /* |-------------------------------------------------------------------------- diff --git a/application/migrations/259_randomize.php b/application/migrations/259_randomize.php new file mode 100644 index 000000000..c63fa0037 --- /dev/null +++ b/application/migrations/259_randomize.php @@ -0,0 +1,53 @@ + '7 00 * * *', + 'clublog_upload' => '3 */6 * * *', + ]; + + foreach ($cron_jobs as $id => $default_expression) { + $query = $this->db->query("SELECT expression FROM cron WHERE id=?", [$id]); + $row = $query->row(); + if ($row && $row->expression === $default_expression) { + + $random_minute = mt_rand(0, 59); + + $parts = explode(' ', $default_expression); + $parts[0] = (string)$random_minute; + $new_expression = implode(' ', $parts); + + // all expressions should have the same format + $new_expression = str_replace(' 00 ', ' 0 ', $new_expression); + + $this->dbtry("UPDATE cron SET expression='" . $new_expression . "' WHERE id='" . $id . "'"); + } + } + + } + + public function down() { + // no way back necessary + } + + function dbtry($what) { + try { + $this->db->query($what); + } catch (Exception $e) { + log_message("error", "Something gone wrong while altering a table: ".$e." // Executing: ".$this->db->last_query()); + } + } +}