diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-06-10 13:45:19 +0200 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-06-10 13:45:19 +0200 |
commit | 8dc6bdd96b9088b87fe8d11346338343135c77e7 (patch) | |
tree | 2f969c8b9a0572d7e4648c9ad8ff2524bdaf27af /cron.php | |
parent | c0bdbd9d81eb22ded95cd7ea9b26a0c36cfa1be0 (diff) | |
download | nextcloud-server-8dc6bdd96b9088b87fe8d11346338343135c77e7.tar.gz nextcloud-server-8dc6bdd96b9088b87fe8d11346338343135c77e7.zip |
clean up usage of DatabaseSetupException and catch Exceptions in entrypoints
Diffstat (limited to 'cron.php')
-rw-r--r-- | cron.php | 120 |
1 files changed, 63 insertions, 57 deletions
@@ -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 |