Skip to content

Commit 35d94e2

Browse files
committed
moves is_public in file_types table
1 parent 49cad61 commit 35d94e2

File tree

7 files changed

+73
-10
lines changed

7 files changed

+73
-10
lines changed

database/migrations/2017_01_01_112100_create_file_types_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class extends Migration {
98
public function up()
109
{
1110
Schema::create('file_types', function (Blueprint $table) {
@@ -19,6 +18,7 @@ public function up()
1918

2019
$table->text('description')->nullable();
2120

21+
$table->boolean('is_public');
2222
$table->boolean('is_browsable');
2323
$table->boolean('is_system');
2424

src/Forms/Templates/type.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,23 @@
3939
"type": "input",
4040
"content": "text"
4141
}
42+
}
43+
]
44+
},
45+
{
46+
"columns": 3,
47+
"fields": [
48+
{
49+
"label": "Public",
50+
"name": "is_public",
51+
"value": false,
52+
"meta": {
53+
"type": "input",
54+
"content": "checkbox"
55+
}
4256
},
4357
{
44-
"label": "Is Browsable",
58+
"label": "Browsable",
4559
"name": "is_browsable",
4660
"value": false,
4761
"meta": {
@@ -50,7 +64,7 @@
5064
}
5165
},
5266
{
53-
"label": "Is System",
67+
"label": "System",
5468
"name": "is_system",
5569
"value": false,
5670
"meta": {

src/Http/Requests/ValidateType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function rules()
2222
'icon' => 'nullable|required_if:is_browsable,true|string',
2323
'folder' => 'required_with:model|string',
2424
'description' => 'nullable|string',
25+
'is_public' => 'required|boolean',
2526
'is_browsable' => 'required|boolean',
2627
'is_system' => 'required|boolean',
2728
];

src/Models/Type.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Illuminate\Support\Facades\Storage;
1212
use Illuminate\Support\Str;
1313
use LaravelEnso\Files\Contracts\Attachable;
14-
use LaravelEnso\Files\Contracts\PublicFile;
1514
use LaravelEnso\Rememberable\Traits\Rememberable;
1615
use LaravelEnso\Tables\Traits\TableCache;
1716

@@ -23,7 +22,10 @@ class Type extends Model
2322

2423
protected $guarded = [];
2524

26-
protected $casts = ['is_browsable' => 'boolean', 'is_system' => 'boolean'];
25+
protected $casts = [
26+
'is_browsable' => 'boolean', 'is_system' => 'boolean',
27+
'is_public' => 'boolean',
28+
];
2729

2830
protected array $rememberableKeys = ['id', 'model'];
2931

@@ -56,7 +58,7 @@ public function model(): Attachable
5658

5759
public function isPublic(): bool
5860
{
59-
return $this->model() instanceof PublicFile;
61+
return $this->is_public;
6062
}
6163

6264
public static function for(string $model): self

src/Tables/Builders/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function query(): Builder
1414
{
1515
return Model::select([
1616
'id', 'name', 'icon', 'folder', 'model',
17-
'is_browsable', 'is_system',
17+
'is_public', 'is_browsable', 'is_system',
1818
]);
1919
}
2020

src/Tables/Templates/types.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@
4646
]
4747
},
4848
{
49-
"label": "Is Browsable",
49+
"label": "Public",
50+
"name": "is_public",
51+
"data": "file_types.is_public",
52+
"meta": [
53+
"boolean",
54+
"sortable"
55+
]
56+
},
57+
{
58+
"label": "Browsable",
5059
"name": "is_browsable",
5160
"data": "file_types.is_browsable",
5261
"meta": [
@@ -55,7 +64,7 @@
5564
]
5665
},
5766
{
58-
"label": "Is System",
67+
"label": "System",
5968
"name": "is_system",
6069
"data": "file_types.is_system",
6170
"meta": [

src/Upgrades/TypeIsPublic.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace LaravelEnso\Files\Upgrades;
4+
5+
use Illuminate\Support\Facades\Schema;
6+
use LaravelEnso\Files\Contracts\PublicFile;
7+
use LaravelEnso\Files\Models\Type;
8+
use LaravelEnso\Upgrade\Contracts\MigratesData;
9+
use LaravelEnso\Upgrade\Contracts\MigratesTable;
10+
use LaravelEnso\Upgrade\Helpers\Table;
11+
12+
class TypeIsPublic implements MigratesTable, MigratesData
13+
{
14+
public function isMigrated(): bool
15+
{
16+
return ! Table::hasColumn('file_types', 'is_public');
17+
}
18+
19+
public function migrateTable(): void
20+
{
21+
Schema::table('file_types', fn ($table) => $table->boolean('is_public')
22+
->default(false)
23+
->after('description'));
24+
25+
Schema::table('file_types', fn ($table) => $table->boolean('is_public')
26+
->default(null)
27+
->change());
28+
}
29+
30+
public function migrateData(): void
31+
{
32+
Type::whereNotNull('model')->get()
33+
->each(fn ($type) => $type->update([
34+
'is_public' => $type->model() instanceof PublicFile,
35+
]));
36+
}
37+
}

0 commit comments

Comments
 (0)