mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 09:49:22 +02:00
Save settings in a transaction
This commit is contained in:
parent
28fef952f8
commit
4b6024dc45
@ -72,6 +72,11 @@ class Settings implements \ArrayAccess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$db->beginTransaction();
|
||||||
|
|
||||||
$this->errors = [];
|
$this->errors = [];
|
||||||
ModelsSettings::where('name', $pluginName)->delete();
|
ModelsSettings::where('name', $pluginName)->delete();
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
@ -81,15 +86,18 @@ class Settings implements \ArrayAccess
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
ModelsSettings::create([
|
ModelsSettings::create([
|
||||||
'name' => $pluginName,
|
'name' => $pluginName,
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
} catch (\PDOException $error) {
|
|
||||||
$this->errors[] = 'Error while saving setting (' . $pluginName . ' - ' . $key . '): ' . $error->getMessage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
} catch (\Exception $error) {
|
||||||
|
$db->rollBack();
|
||||||
|
$this->errors[] = 'Error while saving settings (' . $pluginName . ')<br/>' . $error->getMessage();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->clearCache();
|
$this->clearCache();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user