From 16f215e1c18af8f173f1df96dbe60d2c60cda978 Mon Sep 17 00:00:00 2001 From: colemanw Date: Sun, 15 Oct 2023 16:48:37 -0400 Subject: [PATCH] Managed - Minor schema fixes Increase size of 'module' column to match civicrm_extension.full_name Makes name required and longer Makes 'cleanup' required and declares explicitly the default value previously implied --- CRM/Core/DAO/Managed.php | 30 +++++++++++-------- CRM/Core/ManagedEntities.php | 2 +- .../Incremental/php/FiveSixtyEight.php | 3 ++ .../Incremental/sql/5.68.alpha1.mysql.tpl | 5 ++++ Civi/Api4/Generic/ExportAction.php | 7 +++-- xml/schema/Core/Managed.xml | 14 ++++++--- 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/CRM/Core/DAO/Managed.php b/CRM/Core/DAO/Managed.php index a82a5cae36..cad889fc02 100644 --- a/CRM/Core/DAO/Managed.php +++ b/CRM/Core/DAO/Managed.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Managed.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:1f1273f734c559351767e25b05b3925e) + * (GenCodeChecksum:43846305220f9d67d37b9a1f910ad085) */ /** @@ -40,10 +40,10 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO { public $id; /** - * Name of the module which declared this object + * Name of the module which declared this object (soft FK to civicrm_extension.full_name) * * @var string - * (SQL type: varchar(127)) + * (SQL type: varchar(255)) * Note that values will be retrieved from the database as a string. */ public $module; @@ -51,8 +51,8 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO { /** * Symbolic name used by the module to identify the object * - * @var string|null - * (SQL type: varchar(127)) + * @var string + * (SQL type: varchar(255)) * Note that values will be retrieved from the database as a string. */ public $name; @@ -78,8 +78,8 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO { /** * Policy on when to cleanup entity (always, never, unused) * - * @var string|null - * (SQL type: varchar(32)) + * @var string + * (SQL type: varchar(16)) * Note that values will be retrieved from the database as a string. */ public $cleanup; @@ -146,9 +146,9 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO { 'name' => 'module', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Module'), - 'description' => ts('Name of the module which declared this object'), + 'description' => ts('Name of the module which declared this object (soft FK to civicrm_extension.full_name)'), 'required' => TRUE, - 'maxlength' => 127, + 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, 'usage' => [ 'import' => FALSE, @@ -161,6 +161,9 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO { 'entity' => 'Managed', 'bao' => 'CRM_Core_BAO_Managed', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_BAO_Managed::getBaseModules', + ], 'add' => '4.2', ], 'name' => [ @@ -168,7 +171,8 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO { 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Name'), 'description' => ts('Symbolic name used by the module to identify the object'), - 'maxlength' => 127, + 'required' => TRUE, + 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, 'usage' => [ 'import' => FALSE, @@ -228,8 +232,9 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO { 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Cleanup Setting'), 'description' => ts('Policy on when to cleanup entity (always, never, unused)'), - 'maxlength' => 32, - 'size' => CRM_Utils_Type::MEDIUM, + 'required' => TRUE, + 'maxlength' => 16, + 'size' => CRM_Utils_Type::TWELVE, 'usage' => [ 'import' => FALSE, 'export' => FALSE, @@ -237,6 +242,7 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO { 'token' => FALSE, ], 'where' => 'civicrm_managed.cleanup', + 'default' => 'always', 'table_name' => 'civicrm_managed', 'entity' => 'Managed', 'bao' => 'CRM_Core_BAO_Managed', diff --git a/CRM/Core/ManagedEntities.php b/CRM/Core/ManagedEntities.php index 82b03bc1f2..27353fd21b 100644 --- a/CRM/Core/ManagedEntities.php +++ b/CRM/Core/ManagedEntities.php @@ -237,7 +237,7 @@ class CRM_Core_ManagedEntities { $dao->name = $item['name']; $dao->entity_type = $item['entity_type']; $dao->entity_id = $id; - $dao->cleanup = $item['cleanup'] ?? NULL; + $dao->cleanup = $item['cleanup'] ?? 'always'; $dao->save(); } diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyEight.php b/CRM/Upgrade/Incremental/php/FiveSixtyEight.php index 66421e9435..9a3f16a4d5 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyEight.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyEight.php @@ -33,6 +33,9 @@ class CRM_Upgrade_Incremental_php_FiveSixtyEight extends CRM_Upgrade_Incremental $this->addTask('Update Tag.name field', 'alterColumn', 'civicrm_tag', 'name', "varchar(64) NOT NULL COMMENT 'Unique machine name'"); $this->addTask('Update Tag.created_date field', 'alterColumn', 'civicrm_tag', 'created_date', "datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time that tag was created.'"); $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask('Update civicrm_managed.module', 'alterColumn', 'civicrm_managed', 'module', "varchar(255) NOT NULL COMMENT 'Name of the module which declared this object (soft FK to civicrm_extension.full_name)'"); + $this->addTask('Update civicrm_managed.name', 'alterColumn', 'civicrm_managed', 'name', "varchar(255) NOT NULL COMMENT 'Symbolic name used by the module to identify the object'"); + $this->addTask('Update civicrm_managed.cleanup', 'alterColumn', 'civicrm_managed', 'cleanup', "varchar(16) NOT NULL DEFAULT 'always' COMMENT 'Policy on when to cleanup entity (always, never, unused)'"); } } diff --git a/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl index 9a2b0a2373..d7d9ad9e55 100644 --- a/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl @@ -1,3 +1,8 @@ {* file to handle db changes in 5.68.alpha1 during upgrade *} UPDATE `civicrm_tag` SET `label` = `name` WHERE `label` = ''; + +{* This column is now required. Delete any null values; a managed entity without a name is useless *} +DELETE FROM civicrm_managed WHERE name IS NULL; +{* This column is now required. Set to default value if null or invalid *} +UPDATE civicrm_managed SET cleanup = 'always' WHERE cleanup IS NULL OR cleanup NOT IN ('always', 'never', 'unused'); diff --git a/Civi/Api4/Generic/ExportAction.php b/Civi/Api4/Generic/ExportAction.php index 13b660ec77..1644b7fae2 100644 --- a/Civi/Api4/Generic/ExportAction.php +++ b/Civi/Api4/Generic/ExportAction.php @@ -140,8 +140,11 @@ class ExportAction extends AbstractAction { } } $name = ($parentName ?? '') . $entityType . '_' . ($record['name'] ?? count($this->exportedEntities[$entityType])); - // Ensure safe characters, max length - $name = \CRM_Utils_String::munge($name, '_', 127); + // Ensure safe characters, max length. + // This is used for the value of `civicrm_managed.name` which has a maxlength of 255, but is also used + // to generate a file by civix, and many filesystems have a maxlength of 255 including the suffix, so + // 255 - strlen('.mgd.php') = 247 + $name = \CRM_Utils_String::munge($name, '_', 247); // Include option group with custom field if ($entityType === 'CustomField') { if ( diff --git a/xml/schema/Core/Managed.xml b/xml/schema/Core/Managed.xml index 43de469c9d..f5af8a98ba 100644 --- a/xml/schema/Core/Managed.xml +++ b/xml/schema/Core/Managed.xml @@ -27,16 +27,20 @@ module Module varchar - 127 + 255 true - Name of the module which declared this object + Name of the module which declared this object (soft FK to civicrm_extension.full_name) + + CRM_Core_BAO_Managed::getBaseModules + 4.2 name Name varchar - 127 + 255 + true Symbolic name used by the module to identify the object 4.2 @@ -67,7 +71,9 @@ cleanup Cleanup Setting varchar - 32 + 16 + true + 'always' Policy on when to cleanup entity (always, never, unused) CRM_Core_ManagedEntities::getCleanupOptions -- 2.25.1