From f183ef664d61c9e707a860d8f88c9177a7c79f7e Mon Sep 17 00:00:00 2001 From: sebastian Date: Tue, 16 Feb 2010 15:16:25 +0000 Subject: [PATCH] #2203 the user's crontab gets erased when the Campcaster database is installed --- .../src/modules/storageServer/var/cron/Crontab.php | 6 +++--- .../modules/storageServer/var/install/installStorage.php | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/campcaster/src/modules/storageServer/var/cron/Crontab.php b/campcaster/src/modules/storageServer/var/cron/Crontab.php index 26796593e..756338a37 100755 --- a/campcaster/src/modules/storageServer/var/cron/Crontab.php +++ b/campcaster/src/modules/storageServer/var/cron/Crontab.php @@ -71,10 +71,10 @@ class Crontab */ function readCrontab() { - // Hmmm...this line looks like it erases the crontab file. -Paul - @exec("echo | crontab -u {$this->user} -", $crons, $return); + // return code is 0 or 1 if crontab was empty, elsewhere stop here + $cmd = "crontab -u {$this->user} -l"; @exec("crontab -u {$this->user} -l", $crons, $return); - if ($return != 0) { + if ($return > 1) { return PEAR::raiseError("*** Can't read crontab ***\n". " Set crontab manually!\n"); } diff --git a/campcaster/src/modules/storageServer/var/install/installStorage.php b/campcaster/src/modules/storageServer/var/install/installStorage.php index b0ff05d0c..1aec96614 100644 --- a/campcaster/src/modules/storageServer/var/install/installStorage.php +++ b/campcaster/src/modules/storageServer/var/install/installStorage.php @@ -86,7 +86,6 @@ echo "done.\n"; //------------------------------------------------------------------------ require_once(dirname(__FILE__).'/../cron/Cron.php'); -echo " * Adding cron job..."; $cron = new Cron(); $access = $cron->openCrontab('write'); if ($access != 'write') { @@ -94,6 +93,14 @@ if ($access != 'write') { $r = $cron->forceWriteable(); } while ($r); } +foreach ($cron->ct->getByType(CRON_CMD) as $line) { + if (preg_match('/transportCron\.php/', $line['command'])) { + $cron->closeCrontab(); + echo " * Storage cron job already exists.\n"; + exit; + } +} +echo " * Adding transport cron job..."; $cron->ct->addCron('*/2', '*', '*', '*', '*', realpath("{$CC_CONFIG['cronDir']}/transportCron.php")); $cron->closeCrontab(); echo "done.\n";