APIv4 - Set default value for Dashboard & Event entities
authorcolemanw <coleman@civicrm.org>
Wed, 18 Oct 2023 11:54:39 +0000 (07:54 -0400)
committercolemanw <coleman@civicrm.org>
Wed, 18 Oct 2023 18:23:07 +0000 (14:23 -0400)
CRM/Contact/DAO/DashboardContact.php
CRM/Upgrade/Incremental/php/FiveSixtyEight.php
CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl
Civi/Api4/Service/Spec/Provider/DashboardCreationSpecProvider.php [new file with mode: 0644]
ext/civi_event/Civi/Api4/Service/Spec/Provider/EventCreationSpecProvider.php
xml/schema/Contact/DashboardContact.xml
xml/schema/Core/Dashboard.xml
xml/schema/Event/Event.xml

index 3e298084bb587a4375379df524bd95f42957333a..aff797b875d6423867cd1f7bbddc75ceb691e2d6 100644 (file)
@@ -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,
index 94b675211208faf9fd31747317e2e233d2119abe..c1bedfa946adab800eb9b95d43f4aeffb8e0d640 100644 (file)
@@ -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?'");
   }
 
 }
index 4f986d82be54fc8ac8d77d19599d6b71b0910993..ddfb5373fbe9106f653eb32d57682e5a5a33676b 100644 (file)
@@ -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 (file)
index 0000000..beb3453
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | 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       |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Service\Spec\Provider;
+
+use Civi\Api4\Service\Spec\RequestSpec;
+
+/**
+ * @service
+ * @internal
+ */
+class DashboardCreationSpecProvider extends \Civi\Core\Service\AutoService implements Generic\SpecProviderInterface {
+
+  /**
+   * @inheritDoc
+   */
+  public function modifySpec(RequestSpec $spec) {
+    // Arguably this is a bad default in the schema
+    $spec->getFieldByName('is_active')->setRequired(FALSE)->setDefaultValue(TRUE);
+  }
+
+  /**
+   * @inheritDoc
+   */
+  public function applies($entity, $action) {
+    return in_array($entity, ['Dashboard', 'DashboardContact'], TRUE) && $action === 'create';
+  }
+
+}
index 5a31a2419353d20ba73ad8a9a4e9f43c75c7ea37..3b3af3681cc83173a455c30286cbc75543e71032 100644 (file)
@@ -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'))
index bd3538d35d099dd17808706efe1e16d2c70e2434..4018ca9673b1eeec72099684ec6131e5f7388acd 100644 (file)
   <field>
     <name>is_active</name>
     <type>boolean</type>
+    <required>true</required>
     <title>Dashlet is Active?</title>
     <comment>Is this widget active?</comment>
+    <!-- FIXME - nonstandard default for is_active -->
     <default>0</default>
     <html>
       <type>CheckBox</type>
index d623d645c5e73012f197cdcaed639e2c790b7c69..d61f0b54651720185242d719268b6bf7b8181590 100644 (file)
     <type>boolean</type>
     <title>Is Dashlet Active?</title>
     <comment>Is this dashlet active?</comment>
+    <!-- FIXME - nonstandard default for is_active -->
     <default>0</default>
     <html>
       <type>CheckBox</type>
index 0ed5c2e86305d09c3d8450b7749999e0c84e0fc8..194c97ecc8176d6932041e7af5f95a65755c4fc3 100644 (file)
     <title>Is Active</title>
     <type>boolean</type>
     <required>true</required>
+    <!-- FIXME - nonstandard default for is_active -->
     <default>0</default>
     <comment>Is this Event enabled or disabled/cancelled?</comment>
     <add>1.7</add>