private function clearUnusedData()
 {
     if (self::$layoutId !== false) {
         $layout = new MailtankLayout();
         $layout->id = self::$layoutId;
         $this->assertTrue($layout->delete());
         self::$layoutId = false;
     }
 }
 public static function clearUnusedData()
 {
     foreach (self::$layoutIds as $layoutId) {
         $layout = new MailtankLayout();
         $layout->id = $layoutId;
         $layout->delete();
     }
     self::$layoutIds = [];
 }
 private function clearUnusedData()
 {
     foreach (self::$subscribers as $subscriberId) {
         $subscriber = MailtankSubscriber::findByPk($subscriberId);
         $this->assertTrue($subscriber->delete());
     }
     self::$subscribers = array();
     if (self::$layoutId !== false) {
         $layout = new MailtankLayout();
         $layout->id = self::$layoutId;
         $this->assertTrue($layout->delete());
         self::$layoutId = false;
     }
 }
 /**
  * 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();
     }
 }