mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +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 = [];
|
||||
ModelsSettings::where('name', $pluginName)->delete();
|
||||
foreach ($values as $key => $value) {
|
||||
@ -81,15 +86,18 @@ class Settings implements \ArrayAccess
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
ModelsSettings::create([
|
||||
'name' => $pluginName,
|
||||
'key' => $key,
|
||||
'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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user