mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 08:23:12 +01:00
Reset warnings before starting import
r38035: - Fix sorting by modification time to handle files changed at the same time - Catch exceptions for logging r38036: Lock import/export job while running, to prevent multiple instances.
This commit is contained in:
parent
0e9631781b
commit
5c843ed783
@ -131,6 +131,7 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
||||
$this->results = array();
|
||||
|
||||
// Failures
|
||||
$this->warnings = array();
|
||||
$this->errors = array();
|
||||
|
||||
while ( $record = $import_csv->get_record() ) {
|
||||
|
@ -372,7 +372,7 @@ class importexport_import_csv implements importexport_iface_import_record { //,
|
||||
// Need to handle format first
|
||||
if($format == 1)
|
||||
{
|
||||
$formatted = egw_time::createFromFormat(egw_time::$user_dateformat, $record[$name]);
|
||||
$formatted = egw_time::createFromFormat('!'.egw_time::$user_dateformat, $record[$name]);
|
||||
if($formatted && $errors = egw_time::getLastErrors() && $errors['error_count'] == 0)
|
||||
{
|
||||
$record[$name] = $formatted->getTimestamp();
|
||||
|
@ -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;
|
||||
}
|
||||
@ -422,7 +444,7 @@
|
||||
unset($target[$key]);
|
||||
continue;
|
||||
}
|
||||
$files[$mod_time] = $target;
|
||||
$files[$mod_time.$target] = $target;
|
||||
}
|
||||
if($files)
|
||||
{
|
||||
@ -438,13 +460,25 @@
|
||||
|
||||
foreach($targets as $target)
|
||||
{
|
||||
if($resource = fopen( $target, $data['type'] == 'import' ? 'r' : 'w' )) {
|
||||
$result = $po->$type( $resource, $definition );
|
||||
// Update lock timeout
|
||||
$data['lock'] = time() + 3600;
|
||||
self::update_job($data, true);
|
||||
|
||||
$resource = null;
|
||||
try {
|
||||
if($resource = @fopen( $target, $data['type'] == 'import' ? 'rb' : 'wb' )) {
|
||||
$result = $po->$type( $resource, $definition );
|
||||
|
||||
fclose($resource);
|
||||
} else {
|
||||
fwrite(STDERR,'importexport_schedule: ' . date('c') . ": File $target not readable! \n");
|
||||
$data['errors'][$target][] = lang('%1 is not readable',$target);
|
||||
}
|
||||
}
|
||||
catch (Exception $i_ex)
|
||||
{
|
||||
fclose($resource);
|
||||
} else {
|
||||
fwrite(STDERR,'importexport_schedule: ' . date('c') . ": File $target not readable! \n");
|
||||
$data['errors'][$target][] = lang('%1 is not readable',$target);
|
||||
$data['errors'][$target][] = $i_ex->getMessage();
|
||||
}
|
||||
|
||||
|
||||
@ -498,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);
|
||||
@ -514,7 +551,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];
|
||||
@ -527,6 +564,7 @@
|
||||
$data
|
||||
);
|
||||
}
|
||||
if($no_notification) return $result;
|
||||
|
||||
// Send notification to user
|
||||
if($data['warnings'] || $data['errors'])
|
||||
|
@ -159,6 +159,7 @@ class infolog_import_infologs_csv implements importexport_iface_import_plugin {
|
||||
|
||||
// Failures
|
||||
$this->errors = array();
|
||||
$this->warnings = array();
|
||||
|
||||
while ( $record = $import_csv->get_record() ) {
|
||||
$success = false;
|
||||
|
Loading…
Reference in New Issue
Block a user