db->tableExists('email_templates')) { return; } $fields = $this->db->getFieldNames('email_templates'); $keyField = in_array('code', $fields, true) ? 'code' : 'template_key'; $bodyField = in_array('body_html', $fields, true) ? 'body_html' : 'body'; $nameField = in_array('name', $fields, true) ? 'name' : null; $exists = $this->db->table('email_templates') ->where($keyField, 'registration_opening') ->countAllResults() > 0; if ($exists) { return; } $data = [ $keyField => 'registration_opening', 'subject' => 'Registration is now open for {{school_year}}', $bodyField => $this->bodyHtml(), 'is_active' => 1, ]; if ($nameField !== null) { $data[$nameField] = 'Registration Opening'; } $this->db->table('email_templates')->insert($data); } public function down(): void { if (! $this->db->tableExists('email_templates')) { return; } $fields = $this->db->getFieldNames('email_templates'); $keyField = in_array('code', $fields, true) ? 'code' : 'template_key'; $this->db->table('email_templates') ->where($keyField, 'registration_opening') ->delete(); } private function bodyHtml(): string { return <<<'HTML'

Dear {{name}},

Registration is now open for the {{school_year}} school year.

Please complete your registration through the school portal. The registration deadline is {{registration_deadline}}.

Start registration

If you already have an account, you can also log in here: {{login_url}}

Regards,
{{school_name}}

HTML; } }