File: /home/xedaptot/ai.naniguide.com/database/seeders/Demo/Stage19_SettingsSeeder.php
<?php
namespace Database\Seeders\Demo;
use App\Model\Currency;
use App\Model\EmailVerificationPlan;
use App\Model\SendingCreditPlan;
use App\Model\Setting;
/**
* Stage 19 — optional feature flags + email verification plans.
*
* Mirrors what _seed.php was doing — flips on the optional features that some
* e2e tests assume are enabled, plus seeds a couple of email verification
* credit plans.
*/
class Stage19_SettingsSeeder extends AbstractDemoSeeder
{
protected int $fakerOffset = 19;
public function run(): void
{
// System default settings (idempotent — writes only missing keys)
Setting::writeDefaultSettings();
$this->log('wrote default settings from config/default.php');
// Ensure default language is English
$enLang = \App\Model\Language::where('code', 'en')->first();
if ($enLang) {
Setting::set('default_language', $enLang->id);
$this->log('set default_language to English (id=' . $enLang->id . ')');
}
// Google Analytics gtag.js — measurement ID from env DEMO_GA_MEASUREMENT_ID
$gaId = getenv('DEMO_GA_MEASUREMENT_ID') ?: env('DEMO_GA_MEASUREMENT_ID');
if (!empty($gaId)) {
$snippet = <<<HTML
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={$gaId}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{$gaId}');
</script>
HTML;
Setting::set('custom_script', $snippet);
$this->log('set custom_script with gtag.js (id=' . $gaId . ')');
} else {
$this->log('skipped custom_script (DEMO_GA_MEASUREMENT_ID not set)');
}
// Reset tour flag for primary customer so e2e-app-tour finds it ready
$primary = Stage03_CustomersSeeder::$created['primary'] ?? null;
if ($primary) {
$primary->update(['app_tour_completed' => 0]);
$this->log('reset app_tour_completed for primary customer');
}
// Email verification plans
if (class_exists(EmailVerificationPlan::class) && EmailVerificationPlan::count() === 0) {
$currency = Currency::first();
if ($currency) {
foreach ([
['Starter Pack', 1000, 9.00],
['Growth Pack', 10000, 49.00],
['Pro Pack', 100000, 299.00],
] as [$name, $credits, $price]) {
$p = new EmailVerificationPlan();
$p->name = $name;
$p->description = "{$credits} email verification credits";
$p->credits = $credits;
$p->visibility = 1;
$p->currency_id = $currency->id;
$p->price = $price;
$p->save();
}
$this->log('seeded 3 email verification plans');
}
}
// Sending credit plans
if (class_exists(SendingCreditPlan::class) && SendingCreditPlan::count() === 0) {
$currency = Currency::first();
if ($currency) {
foreach ([
['Starter Sending', 10000, 19.00],
['Growth Sending', 100000, 99.00],
['Pro Sending', 1000000, 499.00],
] as [$name, $credits, $price]) {
$p = new SendingCreditPlan();
$p->name = $name;
$p->description = "{$credits} sending credits";
$p->credits = $credits;
$p->visibility = 1;
$p->currency_id = $currency->id;
$p->price = $price;
$p->save();
}
$this->log('seeded 3 sending credit plans');
}
}
}
}