Skip to content

Commit 692b600

Browse files
committed
[FIX] Idempotent core seeders + prevent missing template/document fatals (safe fallbacks).
1 parent 9d4e813 commit 692b600

15 files changed

+227
-76
lines changed

core/config/cache.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
<?php
2-
use Illuminate\Support\Str;
1+
<?php use Illuminate\Support\Str;
32
return [
4-
53
/*
64
|--------------------------------------------------------------------------
75
| Default Cache Store
@@ -14,7 +12,6 @@
1412
| Supported: "apc", "array", "database", "file", "memcached", "redis"
1513
|
1614
*/
17-
1815
'default' => env('CACHE_DRIVER', 'file'),
1916

2017
/*
@@ -27,28 +24,22 @@
2724
| same cache driver to group types of items stored in your caches.
2825
|
2926
*/
30-
3127
'stores' => [
32-
3328
'apc' => [
3429
'driver' => 'apc',
3530
],
36-
3731
'array' => [
3832
'driver' => 'array',
3933
],
40-
4134
'database' => [
4235
'driver' => 'database',
4336
'table' => 'cache',
4437
'connection' => null,
4538
],
46-
4739
'file' => [
4840
'driver' => 'file',
4941
'path' => EVO_STORAGE_PATH . 'cache/',
5042
],
51-
5243
'memcached' => [
5344
'driver' => 'memcached',
5445
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
@@ -67,12 +58,10 @@
6758
],
6859
],
6960
],
70-
7161
'redis' => [
7262
'driver' => 'redis',
7363
'connection' => 'default',
7464
],
75-
7665
],
7766

7867
/*
@@ -85,10 +74,8 @@
8574
| value to get prefixed to all our keys so we can avoid collisions.
8675
|
8776
*/
88-
8977
'prefix' => env(
9078
'CACHE_PREFIX',
91-
Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'
79+
Str::slug(env('APP_NAME', 'evo'), '_').'_cache'
9280
),
93-
9481
];

core/config/database.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
return [
1+
<?php return [
42
'default' => 'default',
53
'redis' => [
64
'client' => env('REDIS_CLIENT', 'phpredis'),

core/config/filesystems.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?php
2-
return [
1+
<?php return [
32
/*
43
|--------------------------------------------------------------------------
54
| Default Filesystem Disk
@@ -11,6 +10,7 @@
1110
|
1211
*/
1312
'default' => 'public',
13+
1414
/*
1515
|--------------------------------------------------------------------------
1616
| Filesystem Disks

core/config/logging.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
| one of the channels defined in the "channels" configuration array.
1414
|
1515
*/
16-
1716
'default' => env('LOG_CHANNEL', 'daily'),
1817

1918
/*
@@ -30,19 +29,16 @@
3029
| "custom", "stack"
3130
|
3231
*/
33-
3432
'channels' => [
3533
'stack' => [
3634
'driver' => 'stack',
3735
'channels' => ['single'],
3836
],
39-
4037
'single' => [
4138
'driver' => 'single',
4239
'path' => EVO_STORAGE_PATH . 'logs/evo.log',
4340
'level' => 'debug',
4441
],
45-
4642
'daily' => [
4743
'driver' => 'daily',
4844
'name' => env('APP_NAME', 'evo'),
@@ -51,28 +47,24 @@
5147
'days' => env('LOG_DAILY_DAYS', 14),
5248
'replace_placeholders' => true,
5349
],
54-
5550
'slack' => [
5651
'driver' => 'slack',
5752
'url' => env('LOG_SLACK_WEBHOOK_URL'),
5853
'username' => 'EVO Log',
5954
'emoji' => ':boom:',
6055
'level' => 'critical',
6156
],
62-
6357
'stderr' => [
6458
'driver' => 'monolog',
6559
'handler' => StreamHandler::class,
6660
'with' => [
6761
'stream' => 'php://stderr',
6862
],
6963
],
70-
7164
'syslog' => [
7265
'driver' => 'syslog',
7366
'level' => 'debug',
7467
],
75-
7668
'errorlog' => [
7769
'driver' => 'errorlog',
7870
'level' => 'debug',

core/config/session.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use Illuminate\Support\Str;
44

55
return [
6-
76
/*
87
|--------------------------------------------------------------------------
98
| Default Session Driver
@@ -17,7 +16,6 @@
1716
| "memcached", "redis", "dynamodb", "array"
1817
|
1918
*/
20-
2119
'driver' => env('SESSION_DRIVER', 'file'),
2220

2321
/*
@@ -30,9 +28,7 @@
3028
| to immediately expire on the browser closing, set that option.
3129
|
3230
*/
33-
3431
'lifetime' => env('SESSION_LIFETIME', 120),
35-
3632
'expire_on_close' => false,
3733

3834
/*
@@ -45,7 +41,6 @@
4541
| automatically by Laravel and you can use the Session like normal.
4642
|
4743
*/
48-
4944
'encrypt' => false,
5045

5146
/*
@@ -58,7 +53,6 @@
5853
| location may be specified. This is only needed for file sessions.
5954
|
6055
*/
61-
6256
'files' => storage_path('sessions'),
6357

6458
/*
@@ -71,7 +65,6 @@
7165
| correspond to a connection in your database configuration options.
7266
|
7367
*/
74-
7568
'connection' => env('SESSION_CONNECTION', null),
7669

7770
/*
@@ -84,7 +77,6 @@
8477
| provided for you; however, you are free to change this as needed.
8578
|
8679
*/
87-
8880
'table' => 'sessions',
8981

9082
/*
@@ -97,7 +89,6 @@
9789
| must match with one of the application's configured cache "stores".
9890
|
9991
*/
100-
10192
'store' => env('SESSION_STORE', null),
10293

10394
/*
@@ -110,7 +101,6 @@
110101
| happen on a given request. By default, the odds are 2 out of 100.
111102
|
112103
*/
113-
114104
'lottery' => [2, 100],
115105

116106
/*
@@ -123,7 +113,6 @@
123113
| new session cookie is created by the framework for every driver.
124114
|
125115
*/
126-
127116
'cookie' => env(
128117
'SESSION_COOKIE',
129118
'evo_session'
@@ -139,7 +128,6 @@
139128
| your application but you are free to change this when necessary.
140129
|
141130
*/
142-
143131
'path' => '/',
144132

145133
/*
@@ -152,7 +140,6 @@
152140
| available to in your application. A sensible default has been set.
153141
|
154142
*/
155-
156143
'domain' => env('SESSION_DOMAIN', null),
157144

158145
/*
@@ -165,7 +152,6 @@
165152
| the cookie from being sent to you if it can not be done securely.
166153
|
167154
*/
168-
169155
'secure' => env('SESSION_SECURE_COOKIE', false),
170156

171157
/*
@@ -178,7 +164,6 @@
178164
| the HTTP protocol. You are free to modify this option if needed.
179165
|
180166
*/
181-
182167
'http_only' => true,
183168

184169
/*
@@ -193,7 +178,5 @@
193178
| Supported: "lax", "strict"
194179
|
195180
*/
196-
197181
'same_site' => null,
198-
199182
];

core/database/seeders/AdminUserTableSeeder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@
44
use Illuminate\Support\Facades\DB;
55
use Illuminate\Support\Facades\Schema;
66

7+
/**
8+
* Seeds the initial administrator user (if missing).
9+
*
10+
* Safety:
11+
* - Does not delete or overwrite existing users.
12+
* - Creates the user only if a user with the configured username does not exist.
13+
* - Creates `user_attributes` only if missing for the user.
14+
*/
715
class AdminUserTableSeeder extends Seeder
816
{
17+
/**
18+
* Execute the database seeder.
19+
*
20+
* Creates the admin user (and its attributes) only if the user does not already exist.
21+
*/
922
public function run(): void
1023
{
1124
if (!Schema::hasTable('users') || !Schema::hasTable('user_attributes')) {

core/database/seeders/SiteContentTableSeeder.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33
use Illuminate\Database\Seeder;
44
use Illuminate\Support\Facades\DB;
55
use EvolutionCMS\Models\SiteContent;
6+
use Illuminate\Support\Facades\Schema;
67

8+
/**
9+
* Seeds an initial "install success" document for a fresh installation.
10+
*
11+
* Safety: this seeder is idempotent and will not overwrite existing site content.
12+
* If the `site_content` table already contains any rows, it does nothing.
13+
*/
714
class SiteContentTableSeeder extends Seeder
815
{
916
/**
10-
* Run the database seeds.
17+
* Execute the database seeder.
1118
*
12-
* @return void
19+
* Inserts the default "install success" document only when the `site_content` table is empty.
1320
*/
1421
public function run(): void
1522
{
16-
DB::table('site_content')->delete();
23+
if (!Schema::hasTable('site_content')) {
24+
return;
25+
}
26+
27+
if (DB::table('site_content')->count() > 0) {
28+
return;
29+
}
30+
1731
$resource = SiteContent::create(
1832
[
1933
'type' => 'document',

core/database/seeders/SiteTemplatesTableSeeder.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,31 @@
22

33
use Illuminate\Database\Seeder;
44
use Illuminate\Support\Facades\DB;
5+
use Illuminate\Support\Facades\Schema;
56

7+
/**
8+
* Seeds the minimal default site template for a fresh installation.
9+
*
10+
* Safety: this seeder is idempotent and will not overwrite existing templates.
11+
* If the `site_templates` table already contains any rows, it does nothing.
12+
*/
613
class SiteTemplatesTableSeeder extends Seeder
714
{
815
/**
9-
* Run the database seeds.
16+
* Execute the database seeder.
1017
*
11-
* @return void
18+
* Inserts the default "Minimal Template" only when the `site_templates` table is empty.
1219
*/
1320
public function run(): void
1421
{
15-
DB::table('site_templates')->delete();
22+
if (!Schema::hasTable('site_templates')) {
23+
return;
24+
}
25+
26+
if (DB::table('site_templates')->count() > 0) {
27+
return;
28+
}
29+
1630
DB::table('site_templates')->insert([
1731
[
1832
'templatename' => 'Minimal Template',

core/database/seeders/SystemEventnamesTableSeeder.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,31 @@
22

33
use Illuminate\Database\Seeder;
44
use Illuminate\Support\Facades\DB;
5+
use Illuminate\Support\Facades\Schema;
56

7+
/**
8+
* Seeds the `system_eventnames` table for a fresh installation.
9+
*
10+
* Safety: this seeder is idempotent and will not duplicate/overwrite existing rows.
11+
* If the `system_eventnames` table already contains any rows, it does nothing.
12+
*/
613
class SystemEventnamesTableSeeder extends Seeder
714
{
815
/**
9-
* Run the database seeds.
16+
* Execute the database seeder.
1017
*
11-
* @return void
18+
* Inserts the default system event names only when the `system_eventnames` table is empty.
1219
*/
1320
public function run(): void
1421
{
15-
DB::table('system_eventnames')->delete();
22+
if (!Schema::hasTable('system_eventnames')) {
23+
return;
24+
}
25+
26+
if (DB::table('system_eventnames')->count() > 0) {
27+
return;
28+
}
29+
1630
DB::table('system_eventnames')->insert([
1731
[
1832
'name' => 'OnDocPublished',

0 commit comments

Comments
 (0)