From 8dc6bdd96b9088b87fe8d11346338343135c77e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 10 Jun 2013 13:45:19 +0200 Subject: clean up usage of DatabaseSetupException and catch Exceptions in entrypoints --- cron.php | 120 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 63 insertions(+), 57 deletions(-) (limited to 'cron.php') diff --git a/cron.php b/cron.php index 95cedf8bf4c..fbea7f26aed 100644 --- a/cron.php +++ b/cron.php @@ -44,75 +44,81 @@ function handleUnexpectedShutdown() { } } -require_once 'lib/base.php'; +try { -session_write_close(); + require_once 'lib/base.php'; -// Don't do anything if ownCloud has not been installed -if (!OC_Config::getValue('installed', false)) { - exit(0); -} - -// Handle unexpected errors -register_shutdown_function('handleUnexpectedShutdown'); + session_write_close(); -// Delete temp folder -OC_Helper::cleanTmpNoClean(); - -// Exit if background jobs are disabled! -$appmode = OC_BackgroundJob::getExecutionType(); -if ($appmode == 'none') { - TemporaryCronClass::$sent = true; - if (OC::$CLI) { - echo 'Background Jobs are disabled!' . PHP_EOL; - } else { - OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); + // Don't do anything if ownCloud has not been installed + if (!OC_Config::getValue('installed', false)) { + exit(0); } - exit(1); -} -if (OC::$CLI) { - // Create lock file first - TemporaryCronClass::$lockfile = OC_Config::getValue("datadirectory", OC::$SERVERROOT . '/data') . '/cron.lock'; + // Handle unexpected errors + register_shutdown_function('handleUnexpectedShutdown'); - // We call ownCloud from the CLI (aka cron) - if ($appmode != 'cron') { - // Use cron in feature! - OC_BackgroundJob::setExecutionType('cron'); - } + // Delete temp folder + OC_Helper::cleanTmpNoClean(); - // check if backgroundjobs is still running - if (file_exists(TemporaryCronClass::$lockfile)) { - TemporaryCronClass::$keeplock = true; + // Exit if background jobs are disabled! + $appmode = OC_BackgroundJob::getExecutionType(); + if ($appmode == 'none') { TemporaryCronClass::$sent = true; - echo "Another instance of cron.php is still running!"; + if (OC::$CLI) { + echo 'Background Jobs are disabled!' . PHP_EOL; + } else { + OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); + } exit(1); } - // Create a lock file - touch(TemporaryCronClass::$lockfile); + if (OC::$CLI) { + // Create lock file first + TemporaryCronClass::$lockfile = OC_Config::getValue("datadirectory", OC::$SERVERROOT . '/data') . '/cron.lock'; - // Work - $jobList = new \OC\BackgroundJob\JobList(); - $jobs = $jobList->getAll(); - foreach ($jobs as $job) { - $job->execute($jobList); - } -} else { - // We call cron.php from some website - if ($appmode == 'cron') { - // Cron is cron :-P - OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); - } else { - // Work and success :-) + // We call ownCloud from the CLI (aka cron) + if ($appmode != 'cron') { + // Use cron in feature! + OC_BackgroundJob::setExecutionType('cron'); + } + + // check if backgroundjobs is still running + if (file_exists(TemporaryCronClass::$lockfile)) { + TemporaryCronClass::$keeplock = true; + TemporaryCronClass::$sent = true; + echo "Another instance of cron.php is still running!"; + exit(1); + } + + // Create a lock file + touch(TemporaryCronClass::$lockfile); + + // Work $jobList = new \OC\BackgroundJob\JobList(); - $job = $jobList->getNext(); - $job->execute($jobList); - $jobList->setLastJob($job); - OC_JSON::success(); + $jobs = $jobList->getAll(); + foreach ($jobs as $job) { + $job->execute($jobList); + } + } else { + // We call cron.php from some website + if ($appmode == 'cron') { + // Cron is cron :-P + OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); + } else { + // Work and success :-) + $jobList = new \OC\BackgroundJob\JobList(); + $job = $jobList->getNext(); + $job->execute($jobList); + $jobList->setLastJob($job); + OC_JSON::success(); + } } -} -// done! -TemporaryCronClass::$sent = true; -exit(); + // done! + TemporaryCronClass::$sent = true; + exit(); + +} catch (Exception $ex) { + \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); +} \ No newline at end of file -- cgit v1.2.3