You are here

function _hosting_setup_cron in Hosting 5

Same name and namespace in other branches
  1. 6.2 hosting.module \_hosting_setup_cron()
  2. 7.4 hosting.module \_hosting_setup_cron()
  3. 7.3 hosting.module \_hosting_setup_cron()
1 call to _hosting_setup_cron()
hosting_setup in ./hosting.module

File

./hosting.module, line 373
Hosting module

Code

function _hosting_setup_cron() {
  $existing = FALSE;
  exec('crontab -l 2> /dev/null', $cron);
  variable_set('hosting_cron_backup', $cron);
  if (sizeof($cron)) {
    foreach ($cron as $line => $entry) {
      if (preg_match('/hosting dispatch/', $entry)) {
        $pattern = "+(.*)'(.*)/drush.php'(.*)--root='(.*)'.*+";
        $replace = sprintf("\$1 '%s' --root='\$4' \$3 > /dev/null)", DRUSH_COMMAND);
        $cron[$line] = preg_replace($pattern, $replace, $entry);
        drush_log(dt("Existing hosting dispatch cron entry was found. Replacing"));
        $existing = TRUE;
        break;
      }
    }
  }
  else {
    drush_log("message", t("No existing crontab was found"));
  }
  if (!$existing) {
    $cron[] = hosting_queues_cron_cmd();
  }
  $tmpnam = tempnam('hostmaster', 'hm.cron');
  $fp = fopen($tmpnam, "w");
  foreach ($cron as $line) {
    fwrite($fp, $line . "\n");
  }
  fclose($fp);
  system(sprintf('crontab %s', escapeshellarg($tmpnam)));
  unlink($tmpnam);
  drush_log("Notice", t("Installed hosting dispatch cron entry to run every minute"));
}