@@ -32,138 +32,138 @@ |
||
| 32 | 32 | |
| 33 | 33 | // Show warning if a PHP version below 5.6.0 is used |
| 34 | 34 | if (version_compare(PHP_VERSION, '5.6.0') === -1) { |
| 35 | - echo 'This version of Nextcloud requires at least PHP 5.6.0<br/>'; |
|
| 36 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 37 | - return; |
|
| 35 | + echo 'This version of Nextcloud requires at least PHP 5.6.0<br/>'; |
|
| 36 | + echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 37 | + return; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | try { |
| 41 | 41 | |
| 42 | - require_once __DIR__ . '/lib/base.php'; |
|
| 43 | - |
|
| 44 | - if (\OCP\Util::needUpgrade()) { |
|
| 45 | - \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG); |
|
| 46 | - exit; |
|
| 47 | - } |
|
| 48 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 49 | - \OCP\Util::writeLog('cron', 'We are in maintenance mode, skipping cron', \OCP\Util::DEBUG); |
|
| 50 | - exit; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // load all apps to get all api routes properly setup |
|
| 54 | - OC_App::loadApps(); |
|
| 55 | - |
|
| 56 | - \OC::$server->getSession()->close(); |
|
| 57 | - |
|
| 58 | - // initialize a dummy memory session |
|
| 59 | - $session = new \OC\Session\Memory(''); |
|
| 60 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 61 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 62 | - \OC::$server->setSession($session); |
|
| 63 | - |
|
| 64 | - $logger = \OC::$server->getLogger(); |
|
| 65 | - $config = \OC::$server->getConfig(); |
|
| 66 | - |
|
| 67 | - // Don't do anything if ownCloud has not been installed |
|
| 68 | - if (!$config->getSystemValue('installed', false)) { |
|
| 69 | - exit(0); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - \OC::$server->getTempManager()->cleanOld(); |
|
| 73 | - |
|
| 74 | - // Exit if background jobs are disabled! |
|
| 75 | - $appMode = \OCP\BackgroundJob::getExecutionType(); |
|
| 76 | - if ($appMode === 'none') { |
|
| 77 | - if (OC::$CLI) { |
|
| 78 | - echo 'Background Jobs are disabled!' . PHP_EOL; |
|
| 79 | - } else { |
|
| 80 | - OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); |
|
| 81 | - } |
|
| 82 | - exit(1); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (OC::$CLI) { |
|
| 86 | - // set to run indefinitely if needed |
|
| 87 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 88 | - @set_time_limit(0); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // the cron job must be executed with the right user |
|
| 92 | - if (!function_exists('posix_getuid')) { |
|
| 93 | - echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 94 | - exit(1); |
|
| 95 | - } |
|
| 96 | - $user = posix_getpwuid(posix_getuid()); |
|
| 97 | - $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 98 | - if ($user['name'] !== $configUser['name']) { |
|
| 99 | - echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL; |
|
| 100 | - echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 101 | - echo "Web server user: " . $configUser['name'] . PHP_EOL; |
|
| 102 | - exit(1); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // We call ownCloud from the CLI (aka cron) |
|
| 106 | - if ($appMode !== 'cron') { |
|
| 107 | - \OCP\BackgroundJob::setExecutionType('cron'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Work |
|
| 111 | - $jobList = \OC::$server->getJobList(); |
|
| 112 | - |
|
| 113 | - // We only ask for jobs for 14 minutes, because after 15 minutes the next |
|
| 114 | - // system cron task should spawn. |
|
| 115 | - $endTime = time() + 14 * 60; |
|
| 116 | - $currentVersion = $config->getSystemValue('version', ''); |
|
| 117 | - |
|
| 118 | - $executedJobs = []; |
|
| 119 | - while ($job = $jobList->getNext()) { |
|
| 120 | - if (isset($executedJobs[$job->getId()])) { |
|
| 121 | - $jobList->unlockJob($job); |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $job->execute($jobList, $logger); |
|
| 126 | - // clean up after unclean jobs |
|
| 127 | - \OC_Util::tearDownFS(); |
|
| 128 | - |
|
| 129 | - $jobList->setLastJob($job); |
|
| 130 | - $executedJobs[$job->getId()] = true; |
|
| 131 | - unset($job); |
|
| 132 | - |
|
| 133 | - if (time() > $endTime || |
|
| 134 | - $config->getSystemValue('maintenance', false) || |
|
| 135 | - $currentVersion !== $config->getSystemValue('version', '') |
|
| 136 | - ) { |
|
| 137 | - // Time over or there is/was an update, make sure we don't continue with old cached data... |
|
| 138 | - break; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - } else { |
|
| 143 | - // We call cron.php from some website |
|
| 144 | - if ($appMode === 'cron') { |
|
| 145 | - // Cron is cron :-P |
|
| 146 | - OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); |
|
| 147 | - } else { |
|
| 148 | - // Work and success :-) |
|
| 149 | - $jobList = \OC::$server->getJobList(); |
|
| 150 | - $job = $jobList->getNext(); |
|
| 151 | - if ($job != null) { |
|
| 152 | - $job->execute($jobList, $logger); |
|
| 153 | - $jobList->setLastJob($job); |
|
| 154 | - } |
|
| 155 | - OC_JSON::success(); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // Log the successful cron execution |
|
| 160 | - if ($config->getSystemValue('cron_log', true)) { |
|
| 161 | - $config->setAppValue('core', 'lastcron', time()); |
|
| 162 | - } |
|
| 163 | - exit(); |
|
| 42 | + require_once __DIR__ . '/lib/base.php'; |
|
| 43 | + |
|
| 44 | + if (\OCP\Util::needUpgrade()) { |
|
| 45 | + \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG); |
|
| 46 | + exit; |
|
| 47 | + } |
|
| 48 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 49 | + \OCP\Util::writeLog('cron', 'We are in maintenance mode, skipping cron', \OCP\Util::DEBUG); |
|
| 50 | + exit; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // load all apps to get all api routes properly setup |
|
| 54 | + OC_App::loadApps(); |
|
| 55 | + |
|
| 56 | + \OC::$server->getSession()->close(); |
|
| 57 | + |
|
| 58 | + // initialize a dummy memory session |
|
| 59 | + $session = new \OC\Session\Memory(''); |
|
| 60 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 61 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 62 | + \OC::$server->setSession($session); |
|
| 63 | + |
|
| 64 | + $logger = \OC::$server->getLogger(); |
|
| 65 | + $config = \OC::$server->getConfig(); |
|
| 66 | + |
|
| 67 | + // Don't do anything if ownCloud has not been installed |
|
| 68 | + if (!$config->getSystemValue('installed', false)) { |
|
| 69 | + exit(0); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + \OC::$server->getTempManager()->cleanOld(); |
|
| 73 | + |
|
| 74 | + // Exit if background jobs are disabled! |
|
| 75 | + $appMode = \OCP\BackgroundJob::getExecutionType(); |
|
| 76 | + if ($appMode === 'none') { |
|
| 77 | + if (OC::$CLI) { |
|
| 78 | + echo 'Background Jobs are disabled!' . PHP_EOL; |
|
| 79 | + } else { |
|
| 80 | + OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); |
|
| 81 | + } |
|
| 82 | + exit(1); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (OC::$CLI) { |
|
| 86 | + // set to run indefinitely if needed |
|
| 87 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 88 | + @set_time_limit(0); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // the cron job must be executed with the right user |
|
| 92 | + if (!function_exists('posix_getuid')) { |
|
| 93 | + echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 94 | + exit(1); |
|
| 95 | + } |
|
| 96 | + $user = posix_getpwuid(posix_getuid()); |
|
| 97 | + $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 98 | + if ($user['name'] !== $configUser['name']) { |
|
| 99 | + echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL; |
|
| 100 | + echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 101 | + echo "Web server user: " . $configUser['name'] . PHP_EOL; |
|
| 102 | + exit(1); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // We call ownCloud from the CLI (aka cron) |
|
| 106 | + if ($appMode !== 'cron') { |
|
| 107 | + \OCP\BackgroundJob::setExecutionType('cron'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Work |
|
| 111 | + $jobList = \OC::$server->getJobList(); |
|
| 112 | + |
|
| 113 | + // We only ask for jobs for 14 minutes, because after 15 minutes the next |
|
| 114 | + // system cron task should spawn. |
|
| 115 | + $endTime = time() + 14 * 60; |
|
| 116 | + $currentVersion = $config->getSystemValue('version', ''); |
|
| 117 | + |
|
| 118 | + $executedJobs = []; |
|
| 119 | + while ($job = $jobList->getNext()) { |
|
| 120 | + if (isset($executedJobs[$job->getId()])) { |
|
| 121 | + $jobList->unlockJob($job); |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $job->execute($jobList, $logger); |
|
| 126 | + // clean up after unclean jobs |
|
| 127 | + \OC_Util::tearDownFS(); |
|
| 128 | + |
|
| 129 | + $jobList->setLastJob($job); |
|
| 130 | + $executedJobs[$job->getId()] = true; |
|
| 131 | + unset($job); |
|
| 132 | + |
|
| 133 | + if (time() > $endTime || |
|
| 134 | + $config->getSystemValue('maintenance', false) || |
|
| 135 | + $currentVersion !== $config->getSystemValue('version', '') |
|
| 136 | + ) { |
|
| 137 | + // Time over or there is/was an update, make sure we don't continue with old cached data... |
|
| 138 | + break; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + } else { |
|
| 143 | + // We call cron.php from some website |
|
| 144 | + if ($appMode === 'cron') { |
|
| 145 | + // Cron is cron :-P |
|
| 146 | + OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); |
|
| 147 | + } else { |
|
| 148 | + // Work and success :-) |
|
| 149 | + $jobList = \OC::$server->getJobList(); |
|
| 150 | + $job = $jobList->getNext(); |
|
| 151 | + if ($job != null) { |
|
| 152 | + $job->execute($jobList, $logger); |
|
| 153 | + $jobList->setLastJob($job); |
|
| 154 | + } |
|
| 155 | + OC_JSON::success(); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // Log the successful cron execution |
|
| 160 | + if ($config->getSystemValue('cron_log', true)) { |
|
| 161 | + $config->setAppValue('core', 'lastcron', time()); |
|
| 162 | + } |
|
| 163 | + exit(); |
|
| 164 | 164 | |
| 165 | 165 | } catch (Exception $ex) { |
| 166 | - \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 166 | + \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 167 | 167 | } catch (Error $ex) { |
| 168 | - \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 168 | + \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 169 | 169 | } |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | // Show warning if a PHP version below 5.6.0 is used |
| 34 | 34 | if (version_compare(PHP_VERSION, '5.6.0') === -1) { |
| 35 | 35 | echo 'This version of Nextcloud requires at least PHP 5.6.0<br/>'; |
| 36 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 36 | + echo 'You are currently running '.PHP_VERSION.'. Please update your PHP version.'; |
|
| 37 | 37 | return; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | try { |
| 41 | 41 | |
| 42 | - require_once __DIR__ . '/lib/base.php'; |
|
| 42 | + require_once __DIR__.'/lib/base.php'; |
|
| 43 | 43 | |
| 44 | 44 | if (\OCP\Util::needUpgrade()) { |
| 45 | 45 | \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $appMode = \OCP\BackgroundJob::getExecutionType(); |
| 76 | 76 | if ($appMode === 'none') { |
| 77 | 77 | if (OC::$CLI) { |
| 78 | - echo 'Background Jobs are disabled!' . PHP_EOL; |
|
| 78 | + echo 'Background Jobs are disabled!'.PHP_EOL; |
|
| 79 | 79 | } else { |
| 80 | 80 | OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); |
| 81 | 81 | } |
@@ -90,15 +90,15 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | // the cron job must be executed with the right user |
| 92 | 92 | if (!function_exists('posix_getuid')) { |
| 93 | - echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 93 | + echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php".PHP_EOL; |
|
| 94 | 94 | exit(1); |
| 95 | 95 | } |
| 96 | 96 | $user = posix_getpwuid(posix_getuid()); |
| 97 | - $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 97 | + $configUser = posix_getpwuid(fileowner(OC::$configDir.'config.php')); |
|
| 98 | 98 | if ($user['name'] !== $configUser['name']) { |
| 99 | - echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL; |
|
| 100 | - echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 101 | - echo "Web server user: " . $configUser['name'] . PHP_EOL; |
|
| 99 | + echo "Console has to be executed with the same user as the web server is operated".PHP_EOL; |
|
| 100 | + echo "Current user: ".$user['name'].PHP_EOL; |
|
| 101 | + echo "Web server user: ".$configUser['name'].PHP_EOL; |
|
| 102 | 102 | exit(1); |
| 103 | 103 | } |
| 104 | 104 | |