From 678ca6f9edd23f83b8ba3f37405c51a62eebbc72 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 12 Nov 2021 14:45:16 -0500 Subject: [PATCH] CiviGrant - Migrate schema files Insert and then delete CiviGrant to avoid messing up legacy code with expectations of component IDs. --- ext/civigrant/CRM/Grant/DAO/Grant.php | 106 +++++++++--------- ext/civigrant/CRM/Grant/Upgrader.php | 9 ++ ext/civigrant/civigrant.civix.php | 9 +- ext/civigrant/info.xml | 1 + ext/civigrant/sql/auto_install.sql | 58 ++++++++++ ext/civigrant/sql/auto_uninstall.sql | 20 ++++ ext/civigrant/xml/Menu/Grant.xml | 2 - .../xml/schema/CRM/Grant/Grant.entityType.php | 10 ++ .../civigrant/xml/schema/CRM}/Grant/Grant.xml | 1 - xml/schema/Grant/files.xml | 5 - xml/schema/Schema.xml | 1 - xml/templates/civicrm_data.tpl | 5 + 12 files changed, 164 insertions(+), 63 deletions(-) create mode 100644 ext/civigrant/CRM/Grant/Upgrader.php create mode 100644 ext/civigrant/sql/auto_install.sql create mode 100644 ext/civigrant/sql/auto_uninstall.sql create mode 100644 ext/civigrant/xml/schema/CRM/Grant/Grant.entityType.php rename {xml/schema => ext/civigrant/xml/schema/CRM}/Grant/Grant.xml (99%) delete mode 100644 xml/schema/Grant/files.xml diff --git a/ext/civigrant/CRM/Grant/DAO/Grant.php b/ext/civigrant/CRM/Grant/DAO/Grant.php index 3337bd12cb..f3e11207be 100644 --- a/ext/civigrant/CRM/Grant/DAO/Grant.php +++ b/ext/civigrant/CRM/Grant/DAO/Grant.php @@ -4,18 +4,18 @@ * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing * - * Generated from xml/schema/CRM/Grant/Grant.xml + * Generated from civigrant/xml/schema/CRM/Grant/Grant.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:36856b7ed6b7fc04e812c92fd42df94f) + * (GenCodeChecksum:167313787dd6438c7433ead152cb9893) */ +use CRM_Grant_ExtensionUtil as E; /** * Database access object for the Grant entity. */ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { - const EXT = 'civicrm'; + const EXT = E::LONG_NAME; const TABLE_ADDED = '1.8'; - const COMPONENT = 'CiviGrant'; /** * Static instance to hold the table name. @@ -170,7 +170,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { * Whether to return the plural version of the title. */ public static function getEntityTitle($plural = FALSE) { - return $plural ? ts('Grants') : ts('Grant'); + return $plural ? E::ts('Grants') : E::ts('Grant'); } /** @@ -179,7 +179,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { * @return string */ public static function getEntityDescription() { - return ts('Funds applied for and given out by this organization.'); + return E::ts('Funds applied for and given out by this organization.'); } /** @@ -209,15 +209,15 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_id' => [ 'name' => 'id', 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Grant ID'), - 'description' => ts('Unique Grant id'), + 'title' => E::ts('Grant ID'), + 'description' => E::ts('Unique Grant id'), 'required' => TRUE, 'import' => TRUE, 'where' => 'civicrm_grant.id', 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Number', @@ -228,33 +228,33 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_contact_id' => [ 'name' => 'contact_id', 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Contact ID'), - 'description' => ts('Contact ID of contact record given grant belongs to.'), + 'title' => E::ts('Contact ID'), + 'description' => E::ts('Contact ID of contact record given grant belongs to.'), 'required' => TRUE, 'where' => 'civicrm_grant.contact_id', 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'FKClassName' => 'CRM_Contact_DAO_Contact', 'html' => [ 'type' => 'EntityRef', - 'label' => ts("Contact"), + 'label' => E::ts("Contact"), ], 'add' => '1.8', ], 'grant_application_received_date' => [ 'name' => 'application_received_date', 'type' => CRM_Utils_Type::T_DATE, - 'title' => ts('Application received date'), - 'description' => ts('Date on which grant application was received by donor.'), + 'title' => E::ts('Application received date'), + 'description' => E::ts('Date on which grant application was received by donor.'), 'import' => TRUE, 'where' => 'civicrm_grant.application_received_date', 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Select Date', @@ -265,14 +265,14 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_decision_date' => [ 'name' => 'decision_date', 'type' => CRM_Utils_Type::T_DATE, - 'title' => ts('Decision date'), - 'description' => ts('Date on which grant decision was made.'), + 'title' => E::ts('Decision date'), + 'description' => E::ts('Date on which grant decision was made.'), 'import' => TRUE, 'where' => 'civicrm_grant.decision_date', 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Select Date', @@ -283,14 +283,14 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_money_transfer_date' => [ 'name' => 'money_transfer_date', 'type' => CRM_Utils_Type::T_DATE, - 'title' => ts('Grant Money transfer date'), - 'description' => ts('Date on which grant money transfer was made.'), + 'title' => E::ts('Grant Money transfer date'), + 'description' => E::ts('Date on which grant money transfer was made.'), 'import' => TRUE, 'where' => 'civicrm_grant.money_transfer_date', 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Select Date', @@ -301,14 +301,14 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_due_date' => [ 'name' => 'grant_due_date', 'type' => CRM_Utils_Type::T_DATE, - 'title' => ts('Grant Report Due Date'), - 'description' => ts('Date on which grant report is due.'), + 'title' => E::ts('Grant Report Due Date'), + 'description' => E::ts('Date on which grant report is due.'), 'import' => TRUE, 'where' => 'civicrm_grant.grant_due_date', 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Select Date', @@ -319,14 +319,14 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_report_received' => [ 'name' => 'grant_report_received', 'type' => CRM_Utils_Type::T_BOOLEAN, - 'title' => ts('Grant report received'), - 'description' => ts('Yes/No field stating whether grant report was received by donor.'), + 'title' => E::ts('Grant report received'), + 'description' => E::ts('Yes/No field stating whether grant report was received by donor.'), 'import' => TRUE, 'where' => 'civicrm_grant.grant_report_received', 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'CheckBox', @@ -336,14 +336,14 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_type_id' => [ 'name' => 'grant_type_id', 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Grant Type'), - 'description' => ts('Type of grant. Implicit FK to civicrm_option_value in grant_type option_group.'), + 'title' => E::ts('Grant Type'), + 'description' => E::ts('Type of grant. Implicit FK to civicrm_option_value in grant_type option_group.'), 'required' => TRUE, 'where' => 'civicrm_grant.grant_type_id', 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Select', @@ -357,8 +357,8 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'amount_total' => [ 'name' => 'amount_total', 'type' => CRM_Utils_Type::T_MONEY, - 'title' => ts('Total Amount'), - 'description' => ts('Requested grant amount, in default currency.'), + 'title' => E::ts('Total Amount'), + 'description' => E::ts('Requested grant amount, in default currency.'), 'required' => TRUE, 'precision' => [ 20, @@ -370,7 +370,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Text', @@ -380,8 +380,8 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'amount_requested' => [ 'name' => 'amount_requested', 'type' => CRM_Utils_Type::T_MONEY, - 'title' => ts('Amount Requested'), - 'description' => ts('Requested grant amount, in original currency (optional).'), + 'title' => E::ts('Amount Requested'), + 'description' => E::ts('Requested grant amount, in original currency (optional).'), 'precision' => [ 20, 2, @@ -390,7 +390,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'dataPattern' => '/^\d+(\.\d{2})?$/', 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Text', @@ -400,8 +400,8 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'amount_granted' => [ 'name' => 'amount_granted', 'type' => CRM_Utils_Type::T_MONEY, - 'title' => ts('Amount granted'), - 'description' => ts('Granted amount, in default currency.'), + 'title' => E::ts('Amount granted'), + 'description' => E::ts('Granted amount, in default currency.'), 'precision' => [ 20, 2, @@ -412,7 +412,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Text', @@ -422,15 +422,15 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'currency' => [ 'name' => 'currency', 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('Grant Currency'), - 'description' => ts('3 character string, value from config setting or input via user.'), + 'title' => E::ts('Grant Currency'), + 'description' => E::ts('3 character string, value from config setting or input via user.'), 'required' => TRUE, 'maxlength' => 3, 'size' => CRM_Utils_Type::FOUR, 'where' => 'civicrm_grant.currency', 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Select', @@ -447,8 +447,8 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'rationale' => [ 'name' => 'rationale', 'type' => CRM_Utils_Type::T_TEXT, - 'title' => ts('Grant Rationale'), - 'description' => ts('Grant rationale.'), + 'title' => E::ts('Grant Rationale'), + 'description' => E::ts('Grant rationale.'), 'rows' => 4, 'cols' => 60, 'import' => TRUE, @@ -456,7 +456,7 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'export' => TRUE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'TextArea', @@ -466,15 +466,15 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'grant_status_id' => [ 'name' => 'status_id', 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Grant Status'), - 'description' => ts('ID of Grant status.'), + 'title' => E::ts('Grant Status'), + 'description' => E::ts('ID of Grant status.'), 'required' => TRUE, 'import' => TRUE, 'where' => 'civicrm_grant.status_id', 'export' => FALSE, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'html' => [ 'type' => 'Select', @@ -488,17 +488,17 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO { 'financial_type_id' => [ 'name' => 'financial_type_id', 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Financial Type ID'), - 'description' => ts('FK to Financial Type.'), + 'title' => E::ts('Financial Type ID'), + 'description' => E::ts('FK to Financial Type.'), 'where' => 'civicrm_grant.financial_type_id', 'default' => NULL, 'table_name' => 'civicrm_grant', 'entity' => 'Grant', - 'bao' => 'CRM_Grant_BAO_Grant', + 'bao' => 'CRM_Grant_DAO_Grant', 'localizable' => 0, 'FKClassName' => 'CRM_Financial_DAO_FinancialType', 'html' => [ - 'label' => ts("Financial Type"), + 'label' => E::ts("Financial Type"), ], 'pseudoconstant' => [ 'table' => 'civicrm_financial_type', diff --git a/ext/civigrant/CRM/Grant/Upgrader.php b/ext/civigrant/CRM/Grant/Upgrader.php new file mode 100644 index 0000000000..1798462a98 --- /dev/null +++ b/ext/civigrant/CRM/Grant/Upgrader.php @@ -0,0 +1,9 @@ + [ + 'name' => 'Grant', + 'class' => 'CRM_Grant_DAO_Grant', + 'table' => 'civicrm_grant', + ], + ]); } diff --git a/ext/civigrant/info.xml b/ext/civigrant/info.xml index a752817759..bdce94b6f6 100644 --- a/ext/civigrant/info.xml +++ b/ext/civigrant/info.xml @@ -23,6 +23,7 @@ + CRM_Grant_Upgrader menu-xml@1.0.0 mgd-php@1.0.0 diff --git a/ext/civigrant/sql/auto_install.sql b/ext/civigrant/sql/auto_install.sql new file mode 100644 index 0000000000..07b7f9396d --- /dev/null +++ b/ext/civigrant/sql/auto_install.sql @@ -0,0 +1,58 @@ +-- +--------------------------------------------------------------------+ +-- | 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 schema.tpl +-- DO NOT EDIT. Generated by CRM_Core_CodeGen +-- +-- /******************************************************* +-- * +-- * Clean up the existing tables - this section generated from drop.tpl +-- * +-- *******************************************************/ + +SET FOREIGN_KEY_CHECKS=0; + +DROP TABLE IF EXISTS `civicrm_grant`; + +SET FOREIGN_KEY_CHECKS=1; +-- /******************************************************* +-- * +-- * Create new tables +-- * +-- *******************************************************/ + +-- /******************************************************* +-- * +-- * civicrm_grant +-- * +-- * This table stores information about grants given to a contact. +-- * +-- *******************************************************/ +CREATE TABLE `civicrm_grant` ( + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Grant id', + `contact_id` int unsigned NOT NULL COMMENT 'Contact ID of contact record given grant belongs to.', + `application_received_date` date COMMENT 'Date on which grant application was received by donor.', + `decision_date` date COMMENT 'Date on which grant decision was made.', + `money_transfer_date` date COMMENT 'Date on which grant money transfer was made.', + `grant_due_date` date COMMENT 'Date on which grant report is due.', + `grant_report_received` tinyint COMMENT 'Yes/No field stating whether grant report was received by donor.', + `grant_type_id` int unsigned NOT NULL COMMENT 'Type of grant. Implicit FK to civicrm_option_value in grant_type option_group.', + `amount_total` decimal(20,2) NOT NULL COMMENT 'Requested grant amount, in default currency.', + `amount_requested` decimal(20,2) COMMENT 'Requested grant amount, in original currency (optional).', + `amount_granted` decimal(20,2) COMMENT 'Granted amount, in default currency.', + `currency` varchar(3) NOT NULL COMMENT '3 character string, value from config setting or input via user.', + `rationale` text COMMENT 'Grant rationale.', + `status_id` int unsigned NOT NULL COMMENT 'ID of Grant status.', + `financial_type_id` int unsigned DEFAULT NULL COMMENT 'FK to Financial Type.', + PRIMARY KEY (`id`), + INDEX `index_grant_type_id`(grant_type_id), + INDEX `index_status_id`(status_id), + CONSTRAINT FK_civicrm_grant_contact_id FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE, + CONSTRAINT FK_civicrm_grant_financial_type_id FOREIGN KEY (`financial_type_id`) REFERENCES `civicrm_financial_type`(`id`) ON DELETE SET NULL +) +ENGINE=InnoDB; diff --git a/ext/civigrant/sql/auto_uninstall.sql b/ext/civigrant/sql/auto_uninstall.sql new file mode 100644 index 0000000000..6e905e1585 --- /dev/null +++ b/ext/civigrant/sql/auto_uninstall.sql @@ -0,0 +1,20 @@ +-- +--------------------------------------------------------------------+ +-- | 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-- * +-- *******************************************************/ + +SET FOREIGN_KEY_CHECKS=0; + +DROP TABLE IF EXISTS `civicrm_grant`; + +SET FOREIGN_KEY_CHECKS=1; \ No newline at end of file diff --git a/ext/civigrant/xml/Menu/Grant.xml b/ext/civigrant/xml/Menu/Grant.xml index b9bc0f796e..c31d0ecb27 100644 --- a/ext/civigrant/xml/Menu/Grant.xml +++ b/ext/civigrant/xml/Menu/Grant.xml @@ -8,7 +8,6 @@ access CiviGrant 1 1000 - CiviGrant civicrm/grant/info @@ -30,7 +29,6 @@ action=add access CiviGrant 1 - CiviGrant civicrm/contact/view/grant diff --git a/ext/civigrant/xml/schema/CRM/Grant/Grant.entityType.php b/ext/civigrant/xml/schema/CRM/Grant/Grant.entityType.php new file mode 100644 index 0000000000..89d4b72f8d --- /dev/null +++ b/ext/civigrant/xml/schema/CRM/Grant/Grant.entityType.php @@ -0,0 +1,10 @@ + 'Grant', + 'class' => 'CRM_Grant_DAO_Grant', + 'table' => 'civicrm_grant', + ], +]; diff --git a/xml/schema/Grant/Grant.xml b/ext/civigrant/xml/schema/CRM/Grant/Grant.xml similarity index 99% rename from xml/schema/Grant/Grant.xml rename to ext/civigrant/xml/schema/CRM/Grant/Grant.xml index 567865e761..b6955d4399 100644 --- a/xml/schema/Grant/Grant.xml +++ b/ext/civigrant/xml/schema/CRM/Grant/Grant.xml @@ -8,7 +8,6 @@ 1.8 true fa-money - CiviGrant civicrm/grant/add?reset=1&action=add&context=standalone civicrm/contact/view/grant?reset=1&action=view&id=[id]&cid=[contact_id] diff --git a/xml/schema/Grant/files.xml b/xml/schema/Grant/files.xml deleted file mode 100644 index b87a6e51c6..0000000000 --- a/xml/schema/Grant/files.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/xml/schema/Schema.xml b/xml/schema/Schema.xml index b7843f4009..d2de20ac9f 100644 --- a/xml/schema/Schema.xml +++ b/xml/schema/Schema.xml @@ -23,7 +23,6 @@ - diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index b46a6d1d28..632a0e22a2 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -26,6 +26,11 @@ INSERT INTO civicrm_component (name, namespace) VALUES ('CiviCase' , 'CRM_C INSERT INTO civicrm_component (name, namespace) VALUES ('CiviReport' , 'CRM_Report' ); INSERT INTO civicrm_component (name, namespace) VALUES ('CiviCampaign' , 'CRM_Campaign' ); +-- CiviGrant has migrated to an extension, but instead of removing the above insert, +-- go ahead and insert it, then delete. This is because too much legacy code has hard-coded +-- references to component ID, so it's better to keep the auto-increment values stable. +DELETE FROM civicrm_component WHERE name = 'CiviGrant'; + -- Create organization contact INSERT INTO civicrm_contact( `contact_type`, `sort_name`, `display_name`, `legal_name`, `organization_name`) VALUES ('Organization', @defaultOrganization, @defaultOrganization, @defaultOrganization, @defaultOrganization); -- 2.25.1