SiteWeaver_CMS/database/seeds/DefaultThemesSeed.php

53 lines
1.4 KiB
PHP

<?php
/**
* DefaultThemesSeed.php
*
* Author: Funky Waddle
* Date: 2026-09-06
*
* Purpose: Registers the bundled `SiteWeaver2026` frontend theme in
* `frontend_themes` as the active theme, so a fresh install has a working
* default theme out of the box (per `themes_architecture.notes` -> "Default
* theme (provided by default)..." in APP.yaml). Depends on
* `RolesAndPermissionsSeed` for the primary Admin user id (`created_by` is a
* NOT NULL FK on `frontend_themes`).
*/
declare(strict_types=1);
use Phinx\Seed\AbstractSeed;
final class DefaultThemesSeed extends AbstractSeed
{
public function getDependencies(): array
{
return [RolesAndPermissionsSeed::class];
}
public function run(): void
{
$existing = $this->fetchRow(
"SELECT id FROM frontend_themes WHERE name = 'SiteWeaver2026'",
);
if ($existing !== false) {
return;
}
$admin = $this->fetchRow('SELECT id FROM users ORDER BY id ASC LIMIT 1');
if ($admin === false) {
// RolesAndPermissionsSeed should have already created the
// primary Admin user; nothing to attribute this row to yet.
return;
}
$this->table('frontend_themes')->insert([
'name' => 'SiteWeaver2026',
'enabled' => true,
'created_at' => date('Y-m-d H:i:s'),
'created_by' => (int) $admin['id'],
])->saveData();
}
}