From d60c682a3ed7ec69c7100dc26c07c531d0c29ab5 Mon Sep 17 00:00:00 2001
From: Lorenz Schori <lo@znerol.ch>
Date: Tue, 8 May 2012 19:31:06 +0200
Subject: [PATCH 2/4] Add hook_requirements implementation which checks for missing mailsystem classes

---
 mailsystem.install |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/mailsystem.install b/mailsystem.install
index 8241918..5a388e1 100644
--- a/mailsystem.install
+++ b/mailsystem.install
@@ -1,6 +1,44 @@
 <?php
 
 /**
+ * Implements hook_requirements().
+ */
+function mailsystem_requirements($phase) {
+  $requirements = array();
+  // Ensure translations don't break at install time
+  $t = get_t();
+
+  if ($phase == 'runtime') {
+    $available_classes = mailsystem_get_classes();
+    $settings = mailsystem_read_settings();
+
+    // Collect missing classes by comparing the classes used in the settings to
+    // the available ones.
+    $missing_classes = array();
+    foreach ($settings as $key => $setting) {
+      foreach ($setting as $classname) {
+        if (!isset($available_classes[$classname])) {
+          $missing_classes[$classname] = $classname;
+        }
+      }
+    }
+
+    if (!empty($missing_classes)) {
+      $requirements['mailsystem_classes'] = array(
+        'title' => $t('Mailsystem'),
+        'value' => $t('Missing mailsystem classes'),
+        'description' => '<p>' . $t('The following classes are configured in your <code>mail_system</code> variable but they seem to be missing from your system. This will prevent sending email from your site and will lead to severe PHP errors. Please install and enable the modules providing the missing classes or fix your configuration by visiting the mailsystem <a href="!mailsystem_settings_link">settings</a> page.', array('!mailsystem_settings_link' => url('admin/config/system/mailsystem'))) . '</p>' .
+          '<p>Missing classes</p>' .
+          theme('item_list', array('items' => $missing_classes)),
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+
+  return $requirements;
+}
+
+/**
  * Remove dynamically generated mailsystem classes and convert configuration.
  */
 function mailsystem_update_7000() {
-- 
1.7.2.5

