Version: current

     1 <?php
     2 /**
     3  * This class is responsible for ensuring that members who are on it receive NO email
     4  * communication at all. any correspondance is caught before the email is sent.
     5  * @package sapphire
     6  * @subpackage email
     7  */
     8 class NewsletterEmailBlacklist extends DataObject{
     9     static $db = array(
    10         'BlockedEmail' => 'Varchar',
    11     );
    12
    13     static $has_one = array(
    14         'Member' => 'Member'
    15     );
    16
    17     /**
    18      * Helper function to see if the email being
    19      * sent has specifically been blocked.
    20      */
    21     static function isBlocked($email) {
    22         $blockedEmails = DataObject::get("NewsletterEmailBlacklist")->toDropDownMap("ID","BlockedEmail");
    23         if($blockedEmails) {
    24             if(in_array($email, $blockedEmails)) {
    25                 return true;
    26             }
    27         }
    28
    29         return false;
    30     }
    31
    32     /**
    33      * Migrate data from Email_BlackList (the obsolete table)
    34      * to NewsletterEmailBlacklist.
    35      */
    36     function requireDefaultRecords() {
    37         parent::requireDefaultRecords();
    38
    39         if(in_array('Email_BlackList', DB::getConn()->tableList())) {
    40             DB::query("INSERT INTO \"NewsletterEmailBlacklist\" SELECT * FROM \"Email_BlackList\"");
    41             DB::query("RENAME TABLE \"Email_BlackList\" TO \"_obsolete_Email_BlackList\"");
    42             echo("<div style=\"padding:5px; color:white; background-color:blue;\">Data in Email_BlackList has been moved to the new NewsletterEmailBlacklist table. To drop the obsolete table, issue this SQL command: \"DROP TABLE '_obsolete_Email_BlackList'\".</div>");
    43         }
    44     }
    45
    46 }
    47 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -