From: colemanw Date: Wed, 18 Oct 2023 11:54:39 +0000 (-0400) Subject: APIv4 - Set default value for Dashboard & Event entities X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=22e1dbeaf56e64b03ee1f8cd9bd61dddc93a7e7d;p=civicrm-core.git APIv4 - Set default value for Dashboard & Event entities --- diff --git a/CRM/Contact/DAO/DashboardContact.php b/CRM/Contact/DAO/DashboardContact.php index 3e298084bb..aff797b875 100644 --- a/CRM/Contact/DAO/DashboardContact.php +++ b/CRM/Contact/DAO/DashboardContact.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/DashboardContact.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:73ab6a9a4f5d372c85b888aae2abe826) + * (GenCodeChecksum:2b31333980964ba3394f0c71cc764a9d) */ /** @@ -67,7 +67,7 @@ class CRM_Contact_DAO_DashboardContact extends CRM_Core_DAO { /** * Is this widget active? * - * @var bool|string|null + * @var bool|string * (SQL type: tinyint) * Note that values will be retrieved from the database as a string. */ @@ -219,6 +219,7 @@ class CRM_Contact_DAO_DashboardContact extends CRM_Core_DAO { 'type' => CRM_Utils_Type::T_BOOLEAN, 'title' => ts('Dashlet is Active?'), 'description' => ts('Is this widget active?'), + 'required' => TRUE, 'usage' => [ 'import' => FALSE, 'export' => FALSE, diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyEight.php b/CRM/Upgrade/Incremental/php/FiveSixtyEight.php index 94b6752112..c1bedfa946 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyEight.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyEight.php @@ -38,6 +38,7 @@ class CRM_Upgrade_Incremental_php_FiveSixtyEight extends CRM_Upgrade_Incremental $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)'"); $this->addTask('Update civicrm_acl.is_active', 'alterColumn', 'civicrm_acl', 'is_active', "tinyint NOT NULL DEFAULT 1 COMMENT 'Is this property active?'"); + $this->addTask('Update civicrm_dashboard_contact.is_active', 'alterColumn', 'civicrm_dashboard_contact', 'is_active', "tinyint NOT NULL DEFAULT 0 COMMENT 'Is this widget active?'"); } } diff --git a/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl index 4f986d82be..ddfb5373fb 100644 --- a/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl @@ -1,6 +1,7 @@ {* file to handle db changes in 5.68.alpha1 during upgrade *} UPDATE `civicrm_acl` SET `is_active` = 0 WHERE `is_active` IS NULL; +UPDATE `civicrm_dashboard_contact` SET `is_active` = 0 WHERE `is_active` IS NULL; UPDATE `civicrm_tag` SET `label` = `name` WHERE `label` = ''; diff --git a/Civi/Api4/Service/Spec/Provider/DashboardCreationSpecProvider.php b/Civi/Api4/Service/Spec/Provider/DashboardCreationSpecProvider.php new file mode 100644 index 0000000000..beb34532fd --- /dev/null +++ b/Civi/Api4/Service/Spec/Provider/DashboardCreationSpecProvider.php @@ -0,0 +1,38 @@ +getFieldByName('is_active')->setRequired(FALSE)->setDefaultValue(TRUE); + } + + /** + * @inheritDoc + */ + public function applies($entity, $action) { + return in_array($entity, ['Dashboard', 'DashboardContact'], TRUE) && $action === 'create'; + } + +} diff --git a/ext/civi_event/Civi/Api4/Service/Spec/Provider/EventCreationSpecProvider.php b/ext/civi_event/Civi/Api4/Service/Spec/Provider/EventCreationSpecProvider.php index 5a31a24193..3b3af3681c 100644 --- a/ext/civi_event/Civi/Api4/Service/Spec/Provider/EventCreationSpecProvider.php +++ b/ext/civi_event/Civi/Api4/Service/Spec/Provider/EventCreationSpecProvider.php @@ -29,6 +29,8 @@ class EventCreationSpecProvider extends \Civi\Core\Service\AutoService implement $spec->getFieldByName('title')->setRequiredIf('empty($values.is_template)'); $spec->getFieldByName('start_date')->setRequiredIf('empty($values.is_template)'); $spec->getFieldByName('template_title')->setRequiredIf('!empty($values.is_template)'); + // Arguably this is a bad default in the schema + $spec->getFieldByName('is_active')->setRequired(FALSE)->setDefaultValue(TRUE); $template_id = (new FieldSpec('template_id', 'Event', 'Integer')) ->setTitle(ts('Event Template')) diff --git a/xml/schema/Contact/DashboardContact.xml b/xml/schema/Contact/DashboardContact.xml index bd3538d35d..4018ca9673 100644 --- a/xml/schema/Contact/DashboardContact.xml +++ b/xml/schema/Contact/DashboardContact.xml @@ -96,8 +96,10 @@ is_active boolean + true Dashlet is Active? Is this widget active? + 0 CheckBox diff --git a/xml/schema/Core/Dashboard.xml b/xml/schema/Core/Dashboard.xml index d623d645c5..d61f0b5465 100644 --- a/xml/schema/Core/Dashboard.xml +++ b/xml/schema/Core/Dashboard.xml @@ -131,6 +131,7 @@ boolean Is Dashlet Active? Is this dashlet active? + 0 CheckBox diff --git a/xml/schema/Event/Event.xml b/xml/schema/Event/Event.xml index 0ed5c2e863..194c97ecc8 100644 --- a/xml/schema/Event/Event.xml +++ b/xml/schema/Event/Event.xml @@ -294,6 +294,7 @@ Is Active boolean true + 0 Is this Event enabled or disabled/cancelled? 1.7