From 54c093a34267533ba75d4ac8072655e0554c2a9a Mon Sep 17 00:00:00 2001 From: colemanw Date: Wed, 23 Aug 2023 14:47:35 -0400 Subject: [PATCH] Add pseudoconstant for base template and regenerate DAOs --- CRM/Mosaico/BAO/MosaicoTemplate.php | 40 ++++---- CRM/Mosaico/DAO/MessageTemplate.php | 69 +++++++++++-- CRM/Mosaico/DAO/MosaicoTemplate.php | 109 ++++++++++++++++++--- sql/auto_install.sql | 74 +++++--------- sql/auto_uninstall.sql | 6 +- xml/schema/CRM/Mosaico/MosaicoTemplate.xml | 5 +- xml/schema/CRM/Mosaico/files.xml | 6 -- 7 files changed, 211 insertions(+), 98 deletions(-) delete mode 100644 xml/schema/CRM/Mosaico/files.xml diff --git a/CRM/Mosaico/BAO/MosaicoTemplate.php b/CRM/Mosaico/BAO/MosaicoTemplate.php index 77f407185e..06fcb0b5fd 100644 --- a/CRM/Mosaico/BAO/MosaicoTemplate.php +++ b/CRM/Mosaico/BAO/MosaicoTemplate.php @@ -2,26 +2,6 @@ class CRM_Mosaico_BAO_MosaicoTemplate extends CRM_Mosaico_DAO_MosaicoTemplate { - /** - * Create a new MosaicoTemplate based on array-data - * - * @param array $params key-value pairs - * @return CRM_Mosaico_DAO_MosaicoTemplate|NULL - * - public static function create($params) { - $className = 'CRM_Mosaico_DAO_MosaicoTemplate'; - $entityName = 'MosaicoTemplate'; - $hook = empty($params['id']) ? 'create' : 'edit'; - - CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); - $instance = new $className(); - $instance->copyValues($params); - $instance->save(); - CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); - - return $instance; - } */ - /** * Helps updating the URLs in templates so they can be reused * after restoring a dump database in a new server. @@ -158,4 +138,24 @@ public static function findBaseTemplates($ignoreCache = FALSE, $dispatchHooks = return Civi::$statics[__CLASS__]['bases']; } + public static function getBaseTemplateOptions(): array { + $suffixMap = [ + 'id' => 'name', + 'name' => 'name', + 'label' => 'title', + 'url' => 'thumbnail', + ]; + $options = []; + foreach (self::findBaseTemplates() as $template) { + $option = []; + if (empty($template['is_hidden'])) { + foreach ($suffixMap as $suffix => $key) { + $option[$suffix] = $template[$key]; + } + $options[] = $option; + } + } + return $options; + } + } diff --git a/CRM/Mosaico/DAO/MessageTemplate.php b/CRM/Mosaico/DAO/MessageTemplate.php index a226b6b88d..8938faf0db 100644 --- a/CRM/Mosaico/DAO/MessageTemplate.php +++ b/CRM/Mosaico/DAO/MessageTemplate.php @@ -6,7 +6,7 @@ * * Generated from uk.co.vedaconsulting.mosaico/xml/schema/CRM/Mosaico/MessageTemplate.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:295340b4f197a752729e0cbd22579979) + * (GenCodeChecksum:c3ea3729ff2c5399cdaffa9045c47aaa) */ use CRM_Mosaico_ExtensionUtil as E; @@ -34,19 +34,25 @@ class CRM_Mosaico_DAO_MessageTemplate extends CRM_Core_DAO { /** * Unique Settings ID * - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $id; /** * FK to civicrm_msg_template. * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $msg_tpl_id; /** * @var string + * (SQL type: varchar(32)) + * Note that values will be retrieved from the database as a string. */ public $hash_key; @@ -54,27 +60,35 @@ class CRM_Mosaico_DAO_MessageTemplate extends CRM_Core_DAO { * name * * @var string + * (SQL type: varchar(32)) + * Note that values will be retrieved from the database as a string. */ public $name; /** * HTML * - * @var longtext + * @var string + * (SQL type: longtext) + * Note that values will be retrieved from the database as a string. */ public $html; /** * metadata * - * @var longtext + * @var string + * (SQL type: longtext) + * Note that values will be retrieved from the database as a string. */ public $metadata; /** * template * - * @var longtext + * @var string + * (SQL type: longtext) + * Note that values will be retrieved from the database as a string. */ public $template; @@ -122,8 +136,15 @@ public static function &fields() { 'id' => [ 'name' => 'id', 'type' => CRM_Utils_Type::T_INT, + 'title' => E::ts('ID'), 'description' => E::ts('Unique Settings ID'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_msg_template.id', 'table_name' => 'civicrm_mosaico_msg_template', 'entity' => 'MessageTemplate', @@ -138,6 +159,12 @@ public static function &fields() { 'title' => E::ts('message template ID'), 'description' => E::ts('FK to civicrm_msg_template.'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_msg_template.msg_tpl_id', 'table_name' => 'civicrm_mosaico_msg_template', 'entity' => 'MessageTemplate', @@ -161,6 +188,12 @@ public static function &fields() { 'required' => TRUE, 'maxlength' => 32, 'size' => CRM_Utils_Type::MEDIUM, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_msg_template.hash_key', 'table_name' => 'civicrm_mosaico_msg_template', 'entity' => 'MessageTemplate', @@ -176,6 +209,12 @@ public static function &fields() { 'required' => TRUE, 'maxlength' => 32, 'size' => CRM_Utils_Type::MEDIUM, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_msg_template.name', 'table_name' => 'civicrm_mosaico_msg_template', 'entity' => 'MessageTemplate', @@ -189,6 +228,12 @@ public static function &fields() { 'title' => E::ts('HTML'), 'description' => E::ts('HTML'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_msg_template.html', 'table_name' => 'civicrm_mosaico_msg_template', 'entity' => 'MessageTemplate', @@ -205,6 +250,12 @@ public static function &fields() { 'title' => E::ts('metadata'), 'description' => E::ts('metadata'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_msg_template.metadata', 'table_name' => 'civicrm_mosaico_msg_template', 'entity' => 'MessageTemplate', @@ -221,6 +272,12 @@ public static function &fields() { 'title' => E::ts('template'), 'description' => E::ts('template'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_msg_template.template', 'table_name' => 'civicrm_mosaico_msg_template', 'entity' => 'MessageTemplate', diff --git a/CRM/Mosaico/DAO/MosaicoTemplate.php b/CRM/Mosaico/DAO/MosaicoTemplate.php index a77f87746d..c8dee5c519 100644 --- a/CRM/Mosaico/DAO/MosaicoTemplate.php +++ b/CRM/Mosaico/DAO/MosaicoTemplate.php @@ -6,7 +6,7 @@ * * Generated from uk.co.vedaconsulting.mosaico/xml/schema/CRM/Mosaico/MosaicoTemplate.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:16450473094763338ba3f855ec5804e0) + * (GenCodeChecksum:983e32929962fd35c0a4a7072490ca59) */ use CRM_Mosaico_ExtensionUtil as E; @@ -24,6 +24,13 @@ class CRM_Mosaico_DAO_MosaicoTemplate extends CRM_Core_DAO { */ public static $_tableName = 'civicrm_mosaico_template'; + /** + * Field to show when displaying a record. + * + * @var string + */ + public static $_labelField = 'title'; + /** * Should CiviCRM log any modifications to this table in the civicrm_log table. * @@ -34,63 +41,81 @@ class CRM_Mosaico_DAO_MosaicoTemplate extends CRM_Core_DAO { /** * Unique Template ID * - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $id; /** * Title * - * @var string + * @var string|null + * (SQL type: varchar(255)) + * Note that values will be retrieved from the database as a string. */ public $title; /** * Name of the Mosaico base template (e.g. versafix-1) * - * @var string + * @var string|null + * (SQL type: varchar(64)) + * Note that values will be retrieved from the database as a string. */ public $base; /** * Fully renderd HTML * - * @var longtext + * @var string|null + * (SQL type: longtext) + * Note that values will be retrieved from the database as a string. */ public $html; /** * Mosaico metadata (JSON) * - * @var longtext + * @var string|null + * (SQL type: longtext) + * Note that values will be retrieved from the database as a string. */ public $metadata; /** * Mosaico content (JSON) * - * @var longtext + * @var string|null + * (SQL type: longtext) + * Note that values will be retrieved from the database as a string. */ public $content; /** * FK to civicrm_msg_template. * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $msg_tpl_id; /** * ID of the category this mailing template is currently belongs. Foreign key to civicrm_option_value. * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $category_id; /** * Domain ID this message template belongs to. * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $domain_id; @@ -139,8 +164,15 @@ public static function &fields() { 'id' => [ 'name' => 'id', 'type' => CRM_Utils_Type::T_INT, + 'title' => E::ts('ID'), 'description' => E::ts('Unique Template ID'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.id', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', @@ -156,6 +188,12 @@ public static function &fields() { 'description' => E::ts('Title'), 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.title', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', @@ -173,13 +211,22 @@ public static function &fields() { 'description' => E::ts('Name of the Mosaico base template (e.g. versafix-1)'), 'maxlength' => 64, 'size' => CRM_Utils_Type::BIG, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.base', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', 'bao' => 'CRM_Mosaico_DAO_MosaicoTemplate', 'localizable' => 0, 'html' => [ - 'type' => 'Text', + 'type' => 'Select', + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_Mosaico_BAO_MosaicoTemplate::getBaseTemplateOptions', ], 'add' => NULL, ], @@ -188,6 +235,12 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_LONGTEXT, 'title' => E::ts('HTML'), 'description' => E::ts('Fully renderd HTML'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.html', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', @@ -200,6 +253,12 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_LONGTEXT, 'title' => E::ts('metadata'), 'description' => E::ts('Mosaico metadata (JSON)'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.metadata', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', @@ -212,6 +271,12 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_LONGTEXT, 'title' => E::ts('Content'), 'description' => E::ts('Mosaico content (JSON)'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.content', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', @@ -225,6 +290,12 @@ public static function &fields() { 'title' => E::ts('message template ID'), 'description' => E::ts('FK to civicrm_msg_template.'), 'required' => FALSE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.msg_tpl_id', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', @@ -247,6 +318,12 @@ public static function &fields() { 'title' => E::ts('Category ID'), 'description' => E::ts('ID of the category this mailing template is currently belongs. Foreign key to civicrm_option_value.'), 'required' => FALSE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.category_id', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', @@ -265,9 +342,15 @@ public static function &fields() { 'domain_id' => [ 'name' => 'domain_id', 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Domain ID'), - 'description' => ts('Domain ID this message template belongs to.'), + 'title' => E::ts('Domain ID'), + 'description' => E::ts('Domain ID this message template belongs to.'), 'required' => FALSE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_mosaico_template.domain_id', 'table_name' => 'civicrm_mosaico_template', 'entity' => 'MosaicoTemplate', diff --git a/sql/auto_install.sql b/sql/auto_install.sql index bad19d2073..6962f089cc 100644 --- a/sql/auto_install.sql +++ b/sql/auto_install.sql @@ -8,22 +8,10 @@ -- -- Generated from schema.tpl -- DO NOT EDIT. Generated by CRM_Core_CodeGen --- - --- +--------------------------------------------------------------------+ --- | Copyright CiviCRM LLC. All rights reserved. | --- | | --- | This work is published under the GNU AGPLv3 license with some | --- | permitted exceptions and without any warranty. For full license | --- | and copyright information, see https://civicrm.org/licensing | --- +--------------------------------------------------------------------+ --- --- Generated from drop.tpl --- DO NOT EDIT. Generated by CRM_Core_CodeGen -- -- /******************************************************* -- * --- * Clean up the existing tables +-- * Clean up the existing tables - this section generated from drop.tpl -- * -- *******************************************************/ @@ -47,21 +35,17 @@ SET FOREIGN_KEY_CHECKS=1; -- * -- *******************************************************/ CREATE TABLE `civicrm_mosaico_msg_template` ( - - - `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Settings ID', - `msg_tpl_id` int unsigned NOT NULL COMMENT 'FK to civicrm_msg_template.', - `hash_key` varchar(32) NOT NULL , - `name` varchar(32) NOT NULL COMMENT 'name', - `html` longtext NOT NULL COMMENT 'HTML', - `metadata` longtext NOT NULL COMMENT 'metadata', - `template` longtext NOT NULL COMMENT 'template' -, - PRIMARY KEY (`id`) - - -, CONSTRAINT FK_civicrm_mosaico_msg_template_msg_tpl_id FOREIGN KEY (`msg_tpl_id`) REFERENCES `civicrm_msg_template`(`id`) ON DELETE CASCADE -) ENGINE=InnoDB ; + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Settings ID', + `msg_tpl_id` int unsigned NOT NULL COMMENT 'FK to civicrm_msg_template.', + `hash_key` varchar(32) NOT NULL, + `name` varchar(32) NOT NULL COMMENT 'name', + `html` longtext NOT NULL COMMENT 'HTML', + `metadata` longtext NOT NULL COMMENT 'metadata', + `template` longtext NOT NULL COMMENT 'template', + PRIMARY KEY (`id`), + CONSTRAINT FK_civicrm_mosaico_msg_template_msg_tpl_id FOREIGN KEY (`msg_tpl_id`) REFERENCES `civicrm_msg_template`(`id`) ON DELETE CASCADE +) +ENGINE=InnoDB; -- /******************************************************* -- * @@ -71,23 +55,17 @@ CREATE TABLE `civicrm_mosaico_msg_template` ( -- * -- *******************************************************/ CREATE TABLE `civicrm_mosaico_template` ( - - - `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Template ID', - `title` varchar(255) COMMENT 'Title', - `base` varchar(64) COMMENT 'Name of the Mosaico base template (e.g. versafix-1)', - `html` longtext COMMENT 'Fully renderd HTML', - `metadata` longtext COMMENT 'Mosaico metadata (JSON)', - `content` longtext COMMENT 'Mosaico content (JSON)', - `msg_tpl_id` int unsigned NULL COMMENT 'FK to civicrm_msg_template.', - `category_id` int(10) UNSIGNED DEFAULT NULL COMMENT 'ID of the category this mailing template is currently belongs. Foreign key to civicrm_option_value.', - `domain_id` int unsigned NULL COMMENT 'FK to civicrm_domain.' -, - PRIMARY KEY (`id`) - - -, CONSTRAINT FK_civicrm_mosaico_template_msg_tpl_id FOREIGN KEY (`msg_tpl_id`) REFERENCES `civicrm_msg_template`(`id`) ON DELETE SET NULL -, CONSTRAINT FK_civicrm_mosaico_template_domain_id FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain`(`id`) ON DELETE SET NULL -) ENGINE=InnoDB ; - - + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Template ID', + `title` varchar(255) COMMENT 'Title', + `base` varchar(64) COMMENT 'Name of the Mosaico base template (e.g. versafix-1)', + `html` longtext COMMENT 'Fully renderd HTML', + `metadata` longtext COMMENT 'Mosaico metadata (JSON)', + `content` longtext COMMENT 'Mosaico content (JSON)', + `msg_tpl_id` int unsigned NULL COMMENT 'FK to civicrm_msg_template.', + `category_id` int unsigned NULL COMMENT 'ID of the category this mailing template is currently belongs. Foreign key to civicrm_option_value.', + `domain_id` int unsigned NULL COMMENT 'Domain ID this message template belongs to.', + PRIMARY KEY (`id`), + CONSTRAINT FK_civicrm_mosaico_template_msg_tpl_id FOREIGN KEY (`msg_tpl_id`) REFERENCES `civicrm_msg_template`(`id`) ON DELETE SET NULL, + CONSTRAINT FK_civicrm_mosaico_template_domain_id FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain`(`id`) ON DELETE SET NULL +) +ENGINE=InnoDB; diff --git a/sql/auto_uninstall.sql b/sql/auto_uninstall.sql index ed30ab7313..51332f2b53 100644 --- a/sql/auto_uninstall.sql +++ b/sql/auto_uninstall.sql @@ -8,11 +8,9 @@ -- -- Generated from drop.tpl -- DO NOT EDIT. Generated by CRM_Core_CodeGen --- --- /******************************************************* --- * --- * Clean up the existing tables +---- /******************************************************* -- * +-- * Clean up the existing tables-- * -- *******************************************************/ SET FOREIGN_KEY_CHECKS=0; diff --git a/xml/schema/CRM/Mosaico/MosaicoTemplate.xml b/xml/schema/CRM/Mosaico/MosaicoTemplate.xml index a3eff0eda9..9044311bbf 100644 --- a/xml/schema/CRM/Mosaico/MosaicoTemplate.xml +++ b/xml/schema/CRM/Mosaico/MosaicoTemplate.xml @@ -36,8 +36,11 @@ Name of the Mosaico base template (e.g. versafix-1) Base Template - Text + Select + + CRM_Mosaico_BAO_MosaicoTemplate::getBaseTemplateOptions + diff --git a/xml/schema/CRM/Mosaico/files.xml b/xml/schema/CRM/Mosaico/files.xml deleted file mode 100644 index d30a859461..0000000000 --- a/xml/schema/CRM/Mosaico/files.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - -