mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Remove Firefly III's ability to encrypt data in the database.
This commit is contained in:
@@ -54,6 +54,7 @@ class Preference extends Model
|
||||
= [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'data' => 'array',
|
||||
];
|
||||
|
||||
/** @var array Fields that can be filled */
|
||||
@@ -81,54 +82,6 @@ class Preference extends Model
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function getDataAttribute($value)
|
||||
{
|
||||
$result = null;
|
||||
try {
|
||||
$data = Crypt::decrypt($value);
|
||||
} catch (DecryptException $e) {
|
||||
Log::error(sprintf('Could not decrypt preference: %s', $e->getMessage()), ['id' => $this->id, 'name' => $this->name, 'data' => $value]);
|
||||
throw new FireflyException(
|
||||
sprintf('Could not decrypt preference #%d. If this error persists, please run "php artisan cache:clear" on the command line.', $this->id)
|
||||
);
|
||||
}
|
||||
$serialized = true;
|
||||
try {
|
||||
unserialize($data, ['allowed_classes' => false]);
|
||||
} /** @noinspection BadExceptionsProcessingInspection */ catch (Exception $e) {
|
||||
$serialized = false;
|
||||
}
|
||||
if (!$serialized) {
|
||||
$result = json_decode($data, true);
|
||||
}
|
||||
if ($serialized) {
|
||||
Log::error(sprintf('Preference #%d ("%s") was stored as serialised object. It will be deleted and recreated.', $this->id, $this->name));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
||||
*/
|
||||
public function setDataAttribute($value): void
|
||||
{
|
||||
$this->attributes['data'] = Crypt::encrypt(json_encode($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return BelongsTo
|
||||
|
Reference in New Issue
Block a user