2017-03-12 05:00:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
use Pterodactyl\Models\ServiceVariable;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
|
|
|
|
class ChangeServiceVariablesValidationRules extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function up()
|
|
|
|
{
|
|
|
|
Schema::table('service_variables', function (Blueprint $table) {
|
|
|
|
$table->renameColumn('regex', 'rules');
|
|
|
|
});
|
|
|
|
|
|
|
|
DB::transaction(function () {
|
2017-03-12 20:34:43 +00:00
|
|
|
foreach (ServiceVariable::all() as $variable) {
|
2017-03-12 05:00:06 +00:00
|
|
|
$variable->rules = ($variable->required) ? 'required|regex:' . $variable->rules : 'regex:' . $variable->regex;
|
|
|
|
$variable->save();
|
|
|
|
}
|
|
|
|
});
|
2017-03-12 23:34:06 +00:00
|
|
|
|
|
|
|
Schema::table('service_variables', function (Blueprint $table) {
|
|
|
|
$table->dropColumn('required');
|
|
|
|
});
|
2017-03-12 05:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function down()
|
|
|
|
{
|
|
|
|
Schema::table('service_variables', function (Blueprint $table) {
|
|
|
|
$table->renameColumn('rules', 'regex');
|
2017-03-12 23:34:06 +00:00
|
|
|
$table->boolean('required')->default(true)->before('regex');
|
2017-03-12 05:00:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
DB::transaction(function () {
|
2017-03-12 20:34:43 +00:00
|
|
|
foreach (ServiceVariable::all() as $variable) {
|
2017-03-12 05:00:06 +00:00
|
|
|
$variable->regex = str_replace(['required|regex:', 'regex:'], '', $variable->regex);
|
|
|
|
$variable->save();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|