if async ID would be longer than 64 chars truncate it to 32 chars plus md5 hash of all data

take care of being able to read old, just truncated IDs too
This commit is contained in:
ralf 2024-09-16 13:38:03 +02:00
parent 4747cb2c23
commit 31838415b3

View File

@ -267,9 +267,16 @@ class importexport_schedule_ui
}
/**
* Generate a async key
* Generate an unique async key
*
* If the id is longer than 64 chars (supported in current DB schema), we use the first 32 chars
* plus a md5 hash of the whole data.
*
* @param array $data
* @param bool $old false: generate new id with md5 hash, if otherwise to long, true: generate old, to 64 chars truncated, id
* @return false|string
*/
public static function generate_id($data)
public static function generate_id($data, $old=false)
{
$query = array(
@ -280,8 +287,12 @@ class importexport_schedule_ui
$definition_list = ((array)$definitions->get_definitions());
$id = 'importexport.'.$definition_list[0].'.'.$data['target'];
if (strlen($id) <= 64 || $old)
{
return substr($id, 0, 64);
}
return substr($id, 0, 32).md5($id);
}
/**
* Check that the target is valid for the type (readable or writable)
@ -645,12 +656,12 @@ class importexport_schedule_ui
{
$id = self::generate_id($data);
$async = new Api\Asyncservice();
$jobs = $async->read($id);
$job = $jobs[$id];
$jobs = $async->read($id) ?: $async->read($old_id=self::generate_id($data, true)) ?: [];
$job = array_shift($jobs);
if(is_array($job))
{
$async->cancel_timer($id);
$async->cancel_timer($old_id ?? $id);
$result = $async->set_timer(
$job['times'],
$id,