Dev: update shield:setup command for set config/Emal::$mailType With `html`
datamweb opened this issue · comments
Pooya Parsa commented
Shield uses html format to send emails. Therefore, it is better for command Setup to perform the settings related to public string $mailType = 'html';
.
Lines 346 to 402 in 4cd5c07
private function setupEmail(): void | |
{ | |
$file = 'Config/Email.php'; | |
$path = $this->distPath . $file; | |
$cleanPath = clean_path($path); | |
if (! is_file($path)) { | |
$this->error(" Not found file '{$cleanPath}'."); | |
return; | |
} | |
$config = config(EmailConfig::class); | |
$fromEmail = (string) $config->fromEmail; // Old Config may return null. | |
$fromName = (string) $config->fromName; | |
if ($fromEmail !== '' && $fromName !== '') { | |
$this->write(CLI::color(' Email Setup: ', 'green') . 'Everything is fine.'); | |
return; | |
} | |
$content = file_get_contents($path); | |
$output = $content; | |
if ($fromEmail === '') { | |
$set = $this->prompt(' The required Config\Email::$fromEmail is not set. Do you set now?', ['y', 'n']); | |
if ($set === 'y') { | |
// Input from email | |
$fromEmail = $this->prompt(' What is your email?', null, 'required|valid_email'); | |
$pattern = '/^ public .*\$fromEmail\s+= \'\';/mu'; | |
$replace = ' public string $fromEmail = \'' . $fromEmail . '\';'; | |
$output = preg_replace($pattern, $replace, $content); | |
} | |
} | |
if ($fromName === '') { | |
$set = $this->prompt(' The required Config\Email::$fromName is not set. Do you set now?', ['y', 'n']); | |
if ($set === 'y') { | |
$fromName = $this->prompt(' What is your name?', null, 'required'); | |
$pattern = '/^ public .*\$fromName\s+= \'\';/mu'; | |
$replace = ' public string $fromName = \'' . $fromName . '\';'; | |
$output = preg_replace($pattern, $replace, $output); | |
} | |
} | |
if (write_file($path, $output)) { | |
$this->write(CLI::color(' Updated: ', 'green') . $cleanPath); | |
} else { | |
$this->error(" Error updating file '{$cleanPath}'."); | |
} | |
} |
more info see https://forum.codeigniter.com/showthread.php?tid=89321