public static function createBasicModel() { $model = new MailtankLayout(); $id = uniqid(); $model->setAttributes(['id' => $id, 'name' => 'test Layout ' . $id, 'markup' => 'Hello, {{username}}! {{unsubscribe_link}}', 'subject_markup' => 'Hello, {{username}}!']); return $model; }
/** * Create template on mailtank * @param string $templateName name of template * @param string $basePath path to root directory of mailtank templates * @param string $prefix Unique for project prefix for creating template name */ private function createTemplate($templateName, $basePath, $prefix) { $html = self::renderTemplate($templateName . '.html', $basePath); $textPlain = self::renderTemplate($templateName . '.txt', $basePath); // Check for template errors $html = self::checkTemplate($templateName . '.html', $html); if ($html === false) { return; } $textPlain = self::checkTemplate($templateName . '.txt', $textPlain); if ($textPlain === false) { return; } // Create unique mailtank ID from domain and template name $id = static::createLayoutId($templateName, $prefix); try { $layout = new MailtankLayout(); $layout->setAttributes(['id' => $id]); $layout->delete(); } catch (\Exception $e) { // Do nothing } $layout = new MailtankLayout(); $attr = ['id' => $id, 'name' => $id, 'subject_markup' => '{{subject}}', 'markup' => $html, 'plaintext_markup' => $textPlain]; $layout->setAttributes($attr); if ($layout->save()) { if (self::$useConsoleOut) { Console::outputColored("Template <%g{$templateName}%n> was create, id=" . $layout->id); } } else { $err = []; foreach ($layout->getErrors() as $k => $v) { $err[] = $k . ' : ' . $v; } if (!self::$useConsoleOut) { throw new MailtankException("Template <%m{$templateName}%n> wasn't create" . PHP_EOL . implode(PHP_EOL, $err)); } Console::outputColored("Template <%m{$templateName}%n> wasn't create"); Console::addIndent(); foreach ($err as $v) { Console::error($v); } Console::removeIndent(); } }