From 975bf8c23b167174682500390858a23a995675e9 Mon Sep 17 00:00:00 2001 From: larssandergreen Date: Mon, 10 Jul 2023 19:18:14 -0600 Subject: [PATCH] Make Project entity_id and entity_table non-required --- CRM/Volunteer/DAO/Need.php | 129 +++++++++++++++++++++++---- CRM/Volunteer/DAO/Project.php | 90 +++++++++++++++++-- CRM/Volunteer/DAO/ProjectContact.php | 42 +++++++-- CRM/Volunteer/Upgrader.php | 13 ++- sql/auto_install.sql | 4 +- xml/schema/CRM/Volunteer/Project.xml | 4 +- 6 files changed, 246 insertions(+), 36 deletions(-) diff --git a/CRM/Volunteer/DAO/Need.php b/CRM/Volunteer/DAO/Need.php index 1a9f3771..f43cec1a 100644 --- a/CRM/Volunteer/DAO/Need.php +++ b/CRM/Volunteer/DAO/Need.php @@ -6,7 +6,7 @@ * * Generated from org.civicrm.volunteer/xml/schema/CRM/Volunteer/Need.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:f028b707d10c466685b33b7dc5a94f79) + * (GenCodeChecksum:3dbbc0ff3b491a8c56fb6003ddca4a3e) */ use CRM_Volunteer_ExtensionUtil as E; @@ -34,78 +34,102 @@ class CRM_Volunteer_DAO_Need extends CRM_Core_DAO { /** * Need 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_volunteer_project table which contains entity_table + entity for each volunteer project (initially civicrm_event + eventID). * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $project_id; /** - * @var datetime + * @var string|null + * (SQL type: datetime) + * Note that values will be retrieved from the database as a string. */ public $start_time; /** * Used for specifying fuzzy dates, e.g., I have a need for 3 hours of volunteer work to be completed between 12/01/2015 and 12/31/2015. * - * @var datetime + * @var string|null + * (SQL type: datetime) + * Note that values will be retrieved from the database as a string. */ public $end_time; /** * Length in minutes of this volunteer time slot. * - * @var int + * @var int|string|null + * (SQL type: int) + * Note that values will be retrieved from the database as a string. */ public $duration; /** * Boolean indicating whether or not the time and role are flexible. Activities linked to a flexible need indicate that the volunteer is generally available. * - * @var bool + * @var bool|string + * (SQL type: tinyint) + * Note that values will be retrieved from the database as a string. */ public $is_flexible; /** * The number of volunteers needed for this need. * - * @var int + * @var int|string|null + * (SQL type: int) + * Note that values will be retrieved from the database as a string. */ public $quantity; /** * Indicates whether this need is offered on public volunteer signup forms. Implicit FK to option_value row in visibility option_group. * - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $visibility_id; /** * The role associated with this need. Implicit FK to option_value row in volunteer_role option_group. * - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $role_id; /** * Is this need enabled? * - * @var bool + * @var bool|string + * (SQL type: tinyint) + * Note that values will be retrieved from the database as a string. */ public $is_active; /** - * @var timestamp + * @var string|null + * (SQL type: timestamp) + * Note that values will be retrieved from the database as a string. */ public $created; /** - * @var timestamp + * @var string|null + * (SQL type: timestamp) + * Note that values will be retrieved from the database as a string. */ public $last_updated; @@ -156,6 +180,12 @@ public static function &fields() { 'title' => E::ts('CiviVolunteer Need ID'), 'description' => E::ts('Need Id'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.id', 'table_name' => 'civicrm_volunteer_need', 'entity' => 'Need', @@ -167,8 +197,15 @@ public static function &fields() { 'project_id' => [ 'name' => 'project_id', 'type' => CRM_Utils_Type::T_INT, + 'title' => E::ts('Project ID'), 'description' => E::ts('FK to civicrm_volunteer_project table which contains entity_table + entity for each volunteer project (initially civicrm_event + eventID).'), 'required' => FALSE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.project_id', 'table_name' => 'civicrm_volunteer_need', 'entity' => 'Need', @@ -181,6 +218,12 @@ public static function &fields() { 'name' => 'start_time', 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, 'title' => E::ts('Start Date and Time'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.start_time', 'table_name' => 'civicrm_volunteer_need', 'entity' => 'Need', @@ -193,6 +236,12 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, 'title' => E::ts('End Date and Time'), 'description' => E::ts('Used for specifying fuzzy dates, e.g., I have a need for 3 hours of volunteer work to be completed between 12/01/2015 and 12/31/2015.'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.end_time', 'table_name' => 'civicrm_volunteer_need', 'entity' => 'Need', @@ -205,6 +254,12 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_INT, 'title' => E::ts('Duration'), 'description' => E::ts('Length in minutes of this volunteer time slot.'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.duration', 'table_name' => 'civicrm_volunteer_need', 'entity' => 'Need', @@ -218,6 +273,12 @@ public static function &fields() { 'title' => E::ts('Flexible'), 'description' => E::ts('Boolean indicating whether or not the time and role are flexible. Activities linked to a flexible need indicate that the volunteer is generally available.'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.is_flexible', 'default' => '0', 'table_name' => 'civicrm_volunteer_need', @@ -231,8 +292,14 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_INT, 'title' => E::ts('Quantity'), 'description' => E::ts('The number of volunteers needed for this need.'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.quantity', - 'default' => 'NULL', + 'default' => NULL, 'table_name' => 'civicrm_volunteer_need', 'entity' => 'Need', 'bao' => 'CRM_Volunteer_DAO_Need', @@ -244,8 +311,14 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_INT, 'title' => E::ts('Visibility'), 'description' => E::ts(' Indicates whether this need is offered on public volunteer signup forms. Implicit FK to option_value row in visibility option_group.'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.visibility_id', - 'default' => 'NULL', + 'default' => NULL, 'table_name' => 'civicrm_volunteer_need', 'entity' => 'Need', 'bao' => 'CRM_Volunteer_DAO_Need', @@ -261,8 +334,14 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_INT, 'title' => E::ts('Role'), 'description' => E::ts('The role associated with this need. Implicit FK to option_value row in volunteer_role option_group.'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.role_id', - 'default' => 'NULL', + 'default' => NULL, 'table_name' => 'civicrm_volunteer_need', 'entity' => 'Need', 'bao' => 'CRM_Volunteer_DAO_Need', @@ -279,6 +358,12 @@ public static function &fields() { 'title' => E::ts('Enabled'), 'description' => E::ts('Is this need enabled?'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.is_active', 'default' => '1', 'table_name' => 'civicrm_volunteer_need', @@ -291,6 +376,12 @@ public static function &fields() { 'name' => 'created', 'type' => CRM_Utils_Type::T_TIMESTAMP, 'title' => E::ts('Date of Creation'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.created', 'default' => 'CURRENT_TIMESTAMP', 'table_name' => 'civicrm_volunteer_need', @@ -303,6 +394,12 @@ public static function &fields() { 'name' => 'last_updated', 'type' => CRM_Utils_Type::T_TIMESTAMP, 'title' => E::ts('Date of Last Update'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_need.last_updated', 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'table_name' => 'civicrm_volunteer_need', diff --git a/CRM/Volunteer/DAO/Project.php b/CRM/Volunteer/DAO/Project.php index 3dfe0b2d..3f9d33c6 100644 --- a/CRM/Volunteer/DAO/Project.php +++ b/CRM/Volunteer/DAO/Project.php @@ -6,7 +6,7 @@ * * Generated from org.civicrm.volunteer/xml/schema/CRM/Volunteer/Project.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:10f524cbe66b778694cc0184b796310c) + * (GenCodeChecksum:8f3f187df7478f516973550267a6c8d4) */ use CRM_Volunteer_ExtensionUtil as E; @@ -24,6 +24,13 @@ class CRM_Volunteer_DAO_Project extends CRM_Core_DAO { */ public static $_tableName = 'civicrm_volunteer_project'; + /** + * 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,7 +41,9 @@ class CRM_Volunteer_DAO_Project extends CRM_Core_DAO { /** * Project 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; @@ -42,13 +51,17 @@ class CRM_Volunteer_DAO_Project extends CRM_Core_DAO { * The title of the Volunteer Project * * @var string + * (SQL type: varchar(255)) + * Note that values will be retrieved from the database as a string. */ public $title; /** * Full description of the Volunteer Project. Text and HTML allowed. Displayed on sign-up screens. * - * @var text + * @var string + * (SQL type: text) + * Note that values will be retrieved from the database as a string. */ public $description; @@ -56,34 +69,44 @@ class CRM_Volunteer_DAO_Project extends CRM_Core_DAO { * Entity table for entity_id (initially civicrm_event) * * @var string + * (SQL type: varchar(64)) + * Note that values will be retrieved from the database as a string. */ public $entity_table; /** * Implicit FK project entity (initially eventID). * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $entity_id; /** * Is this need enabled? * - * @var bool + * @var bool|string + * (SQL type: tinyint) + * Note that values will be retrieved from the database as a string. */ public $is_active; /** * FK to Location Block ID * - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $loc_block_id; /** * The campaign associated with this Volunteer Project. * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $campaign_id; @@ -135,6 +158,12 @@ public static function &fields() { 'title' => E::ts('CiviVolunteer Project ID'), 'description' => E::ts('Project Id'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project.id', 'table_name' => 'civicrm_volunteer_project', 'entity' => 'Project', @@ -151,6 +180,12 @@ public static function &fields() { 'required' => TRUE, 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project.title', 'table_name' => 'civicrm_volunteer_project', 'entity' => 'Project', @@ -166,6 +201,12 @@ public static function &fields() { 'required' => FALSE, 'rows' => 8, 'cols' => 60, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project.description', 'table_name' => 'civicrm_volunteer_project', 'entity' => 'Project', @@ -181,9 +222,15 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_STRING, 'title' => E::ts('Entity Table'), 'description' => E::ts('Entity table for entity_id (initially civicrm_event)'), - 'required' => TRUE, + 'required' => FALSE, 'maxlength' => 64, 'size' => CRM_Utils_Type::BIG, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project.entity_table', 'table_name' => 'civicrm_volunteer_project', 'entity' => 'Project', @@ -194,8 +241,15 @@ public static function &fields() { 'entity_id' => [ 'name' => 'entity_id', 'type' => CRM_Utils_Type::T_INT, + 'title' => E::ts('Entity ID'), 'description' => E::ts('Implicit FK project entity (initially eventID).'), - 'required' => TRUE, + 'required' => FALSE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project.entity_id', 'table_name' => 'civicrm_volunteer_project', 'entity' => 'Project', @@ -209,6 +263,12 @@ public static function &fields() { 'title' => E::ts('Enabled'), 'description' => E::ts('Is this need enabled?'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project.is_active', 'default' => '1', 'table_name' => 'civicrm_volunteer_project', @@ -222,6 +282,12 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_INT, 'title' => E::ts('Location Block ID'), 'description' => E::ts('FK to Location Block ID'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project.loc_block_id', 'table_name' => 'civicrm_volunteer_project', 'entity' => 'Project', @@ -236,6 +302,12 @@ public static function &fields() { 'title' => E::ts('Campaign'), 'description' => E::ts('The campaign associated with this Volunteer Project.'), 'required' => FALSE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project.campaign_id', 'table_name' => 'civicrm_volunteer_project', 'entity' => 'Project', diff --git a/CRM/Volunteer/DAO/ProjectContact.php b/CRM/Volunteer/DAO/ProjectContact.php index 29bb8141..30b9c694 100644 --- a/CRM/Volunteer/DAO/ProjectContact.php +++ b/CRM/Volunteer/DAO/ProjectContact.php @@ -6,7 +6,7 @@ * * Generated from org.civicrm.volunteer/xml/schema/CRM/Volunteer/ProjectContact.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:8c8d44d50d3072d3aa1168df85cf26a1) + * (GenCodeChecksum:f2111bca3a99e30e8c02201655cf9b31) */ use CRM_Volunteer_ExtensionUtil as E; @@ -32,28 +32,36 @@ class CRM_Volunteer_DAO_ProjectContact extends CRM_Core_DAO { public static $_log = TRUE; /** - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $id; /** * Foreign key to the Volunteer Project for this record * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $project_id; /** * Foreign key to the Contact for this record * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $contact_id; /** * Nature of the contact's relationship to the Volunteer Project (e.g., Beneficiary). See option group volunteer_project_relationship. * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $relationship_type_id; @@ -104,6 +112,12 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_INT, 'title' => E::ts('CiviVolunteer ProjectContact Row ID'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project_contact.id', 'table_name' => 'civicrm_volunteer_project_contact', 'entity' => 'ProjectContact', @@ -118,6 +132,12 @@ public static function &fields() { 'title' => E::ts('CiviVolunteer Project ID'), 'description' => E::ts('Foreign key to the Volunteer Project for this record'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project_contact.project_id', 'table_name' => 'civicrm_volunteer_project_contact', 'entity' => 'ProjectContact', @@ -132,6 +152,12 @@ public static function &fields() { 'title' => E::ts('Contact ID'), 'description' => E::ts('Foreign key to the Contact for this record'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project_contact.contact_id', 'table_name' => 'civicrm_volunteer_project_contact', 'entity' => 'ProjectContact', @@ -146,6 +172,12 @@ public static function &fields() { 'title' => E::ts('Relationship Type'), 'description' => E::ts('Nature of the contact\'s relationship to the Volunteer Project (e.g., Beneficiary). See option group volunteer_project_relationship.'), 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], 'where' => 'civicrm_volunteer_project_contact.relationship_type_id', 'table_name' => 'civicrm_volunteer_project_contact', 'entity' => 'ProjectContact', diff --git a/CRM/Volunteer/Upgrader.php b/CRM/Volunteer/Upgrader.php index 21a4576b..27fbd2e8 100644 --- a/CRM/Volunteer/Upgrader.php +++ b/CRM/Volunteer/Upgrader.php @@ -59,7 +59,7 @@ public function install() { $this->schemaUpgrade20(); $this->addNeedEndDate(); $this->installNeedMetaDateFields(); - + // uncomment the next line to insert sample data // $this->executeSqlFile('sql/volunteer_sample.mysql'); } @@ -453,6 +453,15 @@ public function upgrade_2301() { return TRUE; } + /** + * Fix entity_table and entity_id which should not be required on project table + */ + public function upgrade_2302() { + $this->ctx->log->info('Applying update 2302 - Fix entity_table and entity_id which should not be required on project table'); + CRM_Core_DAO::executeQuery('ALTER TABLE `civicrm_volunteer_project` MODIFY `entity_table` varchar(64) NULL, MODIFY `entity_id` int(10) NULL'); + return TRUE; + } + public function uninstall() { $customgroups = civicrm_api3('CustomGroup', 'get', [ 'name' => ['IN' => [ @@ -499,7 +508,7 @@ public function uninstall() { foreach (array_keys($optionvalues['values'] ?? []) as $optionvalue_id) { civicrm_api3('OptionValue', 'delete', ['id' => $optionvalue_id]); } - + // Now delete the groups themselves. foreach ($optiongroup_ids as $optiongroup_id) { civicrm_api3('OptionGroup', 'delete', ['id' => $optiongroup_id]); diff --git a/sql/auto_install.sql b/sql/auto_install.sql index 517a46ba..9b48949c 100644 --- a/sql/auto_install.sql +++ b/sql/auto_install.sql @@ -37,8 +37,8 @@ CREATE TABLE `civicrm_volunteer_project` ( `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Project Id', `title` varchar(255) NOT NULL COMMENT 'The title of the Volunteer Project', `description` text NULL COMMENT 'Full description of the Volunteer Project. Text and HTML allowed. Displayed on sign-up screens.', - `entity_table` varchar(64) NOT NULL COMMENT 'Entity table for entity_id (initially civicrm_event)', - `entity_id` int unsigned NOT NULL COMMENT 'Implicit FK project entity (initially eventID).', + `entity_table` varchar(64) NULL COMMENT 'Entity table for entity_id (initially civicrm_event)', + `entity_id` int unsigned NULL COMMENT 'Implicit FK project entity (initially eventID).', `is_active` tinyint NOT NULL DEFAULT 1 COMMENT 'Is this need enabled?', `loc_block_id` int unsigned COMMENT 'FK to Location Block ID', `campaign_id` int unsigned NULL COMMENT 'The campaign associated with this Volunteer Project.', diff --git a/xml/schema/CRM/Volunteer/Project.xml b/xml/schema/CRM/Volunteer/Project.xml index 5b84c14d..0355ba95 100644 --- a/xml/schema/CRM/Volunteer/Project.xml +++ b/xml/schema/CRM/Volunteer/Project.xml @@ -45,14 +45,14 @@ entity_table varchar 64 - true + false 4.4 Entity table for entity_id (initially civicrm_event) entity_id int unsigned - true + false 4.4 Implicit FK project entity (initially eventID).