Check for installed state before registering the logrotate background job

This commit is contained in:
Bart Visscher 2013-07-10 18:07:43 +02:00
parent 62560ef859
commit 42f3ecb60f
2 changed files with 16 additions and 2 deletions

View File

@ -491,7 +491,7 @@ class OC {
self::registerCacheHooks(); self::registerCacheHooks();
self::registerFilesystemHooks(); self::registerFilesystemHooks();
self::registerShareHooks(); self::registerShareHooks();
\OCP\BackgroundJob::registerJob('OC\Log\Rotate', OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log'); self::registerLogRotate();
//make sure temporary files are cleaned up //make sure temporary files are cleaned up
register_shutdown_function(array('OC_Helper', 'cleanTmp')); register_shutdown_function(array('OC_Helper', 'cleanTmp'));
@ -553,6 +553,20 @@ class OC {
} }
} }
/**
* register hooks for the cache
*/
public static function registerLogRotate() {
if (OC_Config::getValue('installed', false)) { //don't try to do this before we are properly setup
// register cache cleanup jobs
try { //if this is executed before the upgrade to the new backgroundjob system is completed it will throw an exception
\OCP\BackgroundJob::registerJob('OC\Log\Rotate', OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log');
} catch (Exception $e) {
}
}
}
/** /**
* register hooks for the filesystem * register hooks for the filesystem
*/ */

View File

@ -16,7 +16,7 @@ namespace OC\Log;
* location and manage that with your own tools. * location and manage that with your own tools.
*/ */
class Rotate extends \OC\BackgroundJob\Job { class Rotate extends \OC\BackgroundJob\Job {
const LOG_SIZE_LIMIT = 104857600; // 100 MB const LOG_SIZE_LIMIT = 104857600; // 100 MiB
public function run($logFile) { public function run($logFile) {
$filesize = @filesize($logFile); $filesize = @filesize($logFile);
if ($filesize >= self::LOG_SIZE_LIMIT) { if ($filesize >= self::LOG_SIZE_LIMIT) {