Merge pull request #10103 from snipe/fixes/make_boolean_fields_nullable

Fixed issue when creating a status label via API - default_label and show_in_nav being not nullable
This commit is contained in:
snipe 2021-09-26 13:41:52 -07:00 committed by GitHub
commit d88c0ae5ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 5 deletions

View file

@ -74,7 +74,7 @@ class StatuslabelsController extends Controller
$statuslabel->archived = $statusType['archived'];
$statuslabel->color = $request->input('color');
$statuslabel->show_in_nav = $request->input('show_in_nav', 0);
$statuslabel->default_label = $request->input('default_label');
$statuslabel->default_label = $request->input('default_label', 0);
if ($statuslabel->save()) {
@ -127,8 +127,8 @@ class StatuslabelsController extends Controller
$statuslabel->pending = $statusType['pending'];
$statuslabel->archived = $statusType['archived'];
$statuslabel->color = $request->input('color');
$statuslabel->show_in_nav = $request->input('show_in_nav');
$statuslabel->default_label = $request->input('default_label');
$statuslabel->show_in_nav = $request->input('show_in_nav', 0);
$statuslabel->default_label = $request->input('default_label', 0);
if ($statuslabel->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $statuslabel, trans('admin/statuslabels/message.update.success')));

View file

@ -13,7 +13,7 @@ class AddShowInNavToStatusLabels extends Migration
public function up()
{
Schema::table('status_labels', function (Blueprint $table) {
$table->boolean('show_in_nav')->default(0);
$table->boolean('show_in_nav')->nullable()->default(0);
});
}

View file

@ -14,7 +14,7 @@ class AddDefaultFlagOnStatuslabels extends Migration
public function up()
{
Schema::table('status_labels', function (Blueprint $table) {
$table->boolean('default_label')->default(0);
$table->boolean('default_label')->nullable()->default(0);
});
}

View file

@ -0,0 +1,46 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\Statuslabel;
class ChangeDefaultLabelToNullable extends Migration
{
/**
* Run the migrations.
*
* This is stupid because it has a default valuye of 0 so it *should*
* default to 0, but it doesn't on some versions of MySQL.
*
* @return void
*/
public function up()
{
Statuslabel::whereNull('default_label')
->update(['default_label' => 0]);
Statuslabel::whereNull('show_in_nav')
->update(['show_in_nav' => 0]);
Schema::table('status_labels', function (Blueprint $table) {
$table->boolean('default_label')->nullable()->default(0)->change();
$table->boolean('show_in_nav')->nullable()->default(0)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}