diff --git a/importexport/inc/class.importexport_schedule_ui.inc.php b/importexport/inc/class.importexport_schedule_ui.inc.php index ef294ce27f..8c0e3930da 100644 --- a/importexport/inc/class.importexport_schedule_ui.inc.php +++ b/importexport/inc/class.importexport_schedule_ui.inc.php @@ -363,16 +363,37 @@ /** * Execute a scheduled import or export */ - public static function exec($data) { + public static function exec($data) + { ob_start(); - $data['record_count'] = 0; unset($data['errors']); unset($data['warnings']); unset($data['result']); + + if($data['lock']) + { + // Lock expires + if($data['lock'] < time()) + { + unset($data['lock']); + $data['warnings'][][] = lang('Lock expired on previous run'); + } + else + { + // Still running + ob_end_flush(); + return; + } + } + $data['last_run'] = time(); + // Lock job for an hour to prevent multiples overlapping + $data['lock'] = time() + 3600; + self::update_job($data, true); + // check file $file_check = self::check_target($data); if($file_check !== true) { @@ -380,6 +401,7 @@ // Update job with results self::update_job($data); + ob_end_flush(); fwrite(STDERR,'importexport_schedule: ' . date('c') . ": $file_check \n"); return; } @@ -438,6 +460,10 @@ foreach($targets as $target) { + // Update lock timeout + $data['lock'] = time() + 3600; + self::update_job($data, true); + $resource = null; try { if($resource = @fopen( $target, $data['type'] == 'import' ? 'rb' : 'wb' )) { @@ -506,7 +532,10 @@ } // Run time in minutes - $data['run_time'] = (time() - $data['last_run']) / 60; + $data['run_time'] = round((time() - $data['last_run']) / 60,1); + + // Clear lock + $data['lock'] = 0; // Update job with results self::update_job($data); @@ -526,7 +555,7 @@ * Update the async job with current status, and send a notification * to user if there were any errors. */ - private static function update_job($data) { + private static function update_job($data, $no_notification = false) { $id = self::generate_id($data); $async = ExecMethod('phpgwapi.asyncservice.read', $id); $async = $async[$id]; @@ -539,6 +568,7 @@ $data ); } + if($no_notification) return $result; // Send notification to user if($data['warnings'] || $data['errors'])