mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Store config data serialized This way we can store null, booleans, and more reliably. * Use model to get the mutated output. * fix whitespace and unused function * use json_encode/decode and casts migration to transfer * json_encode JSON_UNESCAPED_SLASHES * Use JSON_UNESCAPED_SLASHES. That is only relevant if you are printing into an HTML page. * pre-encode the seed... * filter other fields besides config_value
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
class SerializeConfig extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up()
|
|
{
|
|
DB::table('config')->get()->each(function ($config) {
|
|
$value = $config->config_value;
|
|
|
|
if (filter_var($value, FILTER_VALIDATE_INT)) {
|
|
$value = (int)$value;
|
|
} elseif (filter_var($value, FILTER_VALIDATE_FLOAT)) {
|
|
$value = (float)$value;
|
|
} elseif (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null) {
|
|
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
|
}
|
|
|
|
DB::table('config')
|
|
->where('config_id', $config->config_id)
|
|
->update(['config_value' => json_encode($value)]);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function down()
|
|
{
|
|
DB::table('config')->get()->each(function ($config) {
|
|
$value = json_decode($config->config_value);
|
|
$value = is_bool($value) ? var_export($value, true) : (string)$value;
|
|
|
|
DB::table('config')
|
|
->where('config_id', $config->config_id)
|
|
->update(['config_value' => $value]);
|
|
});
|
|
}
|
|
}
|