@@ -13,37 +13,37 @@ class EmailsDAO extends DAO {
1313
1414 /**
1515 */
16- public function __construct ($ database , $ tableName = '#__mail_queue ' , $ modelClass = 'TgEmail \\Email ' , $ idColumn = 'uid ' ) {
17- parent ::__construct ($ database , $ tableName , $ modelClass , $ idColumn );
18- $ this ->checkTable ();
16+ public function __construct ($ database , $ tableName = '#__mail_queue ' , $ modelClass = 'TgEmail \\Email ' , $ idColumn = 'uid ' , $ checkTable = FALSE ) {
17+ parent ::__construct ($ database , $ tableName , $ modelClass , $ idColumn , $ checkTable );
1918 }
20-
21- public function checkTable () {
22- $ res = $ this ->database ->query ('SELECT * FROM ' .$ this ->tableName );
23- if ($ res === FALSE ) {
24- // Create it (try)
25- $ sql =
26- 'CREATE TABLE ` ' .$ this ->tableName .'` ( ' .
27- '` ' .$ this ->idColumn .'` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT \'ID of queue element \', ' .
28- '`sender` VARCHAR(200) NOT NULL COMMENT \'sender address \', ' .
29- '`reply_to` VARCHAR(200) NULL COMMENT \'Reply-To address \', ' .
30- '`recipients` TEXT COLLATE utf8mb4_bin NOT NULL COMMENT \'email recipients \', ' .
31- '`subject` VARCHAR(200) NOT NULL COMMENT \'email subject \', ' .
32- '`body` TEXT COLLATE utf8mb4_bin NOT NULL COMMENT \'email bodies \', ' .
33- '`attachments` TEXT COLLATE utf8mb4_bin NOT NULL COMMENT \'attachment data \', ' .
34- '`queued_time` DATETIME NOT NULL COMMENT \'Time the email was queued \', ' .
35- '`status` VARCHAR(20) NOT NULL COMMENT \'email subject \', ' .
36- '`sent_time` DATETIME NULL COMMENT \'Time the email was sent successfully \', ' .
37- '`failed_attempts` INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT \'Number of failed sending attempts \', ' .
38- 'PRIMARY KEY (` ' .$ this ->idColumn .'`) ' .
39- ') ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT = \'Email Queue \'' ;
40-
41- $ res = $ this ->database ->query ($ sql );
42- if ($ res === FALSE ) {
43- throw new EmailException ('Cannot create table ' .$ this ->tableName .': ' .$ this ->database ->error ());
44- }
45- }
46-
19+
20+ /**
21+ * Implements the method from base class.
22+ * @return boolean TRUE when table could be created. An exception is thrown when the method fails.
23+ */
24+ public function createTable () {
25+ // Create it (try)
26+ $ sql =
27+ 'CREATE TABLE ` ' .$ this ->tableName .'` ( ' .
28+ '` ' .$ this ->idColumn .'` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT \'ID of queue element \', ' .
29+ '`sender` VARCHAR(200) NOT NULL COMMENT \'sender address \', ' .
30+ '`reply_to` VARCHAR(200) NULL COMMENT \'Reply-To address \', ' .
31+ '`recipients` TEXT COLLATE utf8mb4_bin NOT NULL COMMENT \'email recipients \', ' .
32+ '`subject` VARCHAR(200) NOT NULL COMMENT \'email subject \', ' .
33+ '`body` TEXT COLLATE utf8mb4_bin NOT NULL COMMENT \'email bodies \', ' .
34+ '`attachments` TEXT COLLATE utf8mb4_bin NOT NULL COMMENT \'attachment data \', ' .
35+ '`queued_time` DATETIME NOT NULL COMMENT \'Time the email was queued \', ' .
36+ '`status` VARCHAR(20) NOT NULL COMMENT \'email subject \', ' .
37+ '`sent_time` DATETIME NULL COMMENT \'Time the email was sent successfully \', ' .
38+ '`failed_attempts` INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT \'Number of failed sending attempts \', ' .
39+ 'PRIMARY KEY (` ' .$ this ->idColumn .'`) ' .
40+ ') ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT = \'Email Queue \'' ;
41+
42+ $ res = $ this ->database ->query ($ sql );
43+ if ($ res === FALSE ) {
44+ throw new EmailException ('Cannot create table ' .$ this ->tableName .': ' .$ this ->database ->error ());
45+ }
46+ return TRUE ;
4747 }
4848
4949 public function housekeeping ($ maxSentDays = 90 , $ maxFailedDays = 180 ) {
0 commit comments