From a10eb98a1cb6db3fe338b4dedaf9322403bfb571 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 3 Apr 2023 18:16:21 +1200 Subject: [PATCH] dev/core#4213 Make frontend_title required --- CRM/Contribute/BAO/ContributionPage.php | 31 +++-- CRM/Contribute/DAO/Contribution.php | 3 +- CRM/Contribute/DAO/ContributionPage.php | 118 ++++++++++++------ CRM/Contribute/Form/Contribution/Confirm.php | 4 +- CRM/Contribute/Form/ContributionBase.php | 2 +- .../Form/ContributionPage/Settings.php | 2 +- CRM/Core/DAO.php | 13 +- CRM/Core/I18n/SchemaStructure.php | 12 +- CRM/Upgrade/Incremental/Base.php | 8 +- .../Incremental/php/FiveSixtyThree.php | 10 +- .../Incremental/sql/5.63.alpha1.mysql.tpl | 16 +++ .../PaymentProcessorCreationSpecProvider.php | 7 -- .../Spec/Provider/TitleFieldSpecProvider.php | 50 ++++++++ sql/civicrm_generated.mysql | 8 +- .../Form/ContributionPage/Settings.tpl | 16 +-- .../Contribute/BAO/ContributionPageTest.php | 32 ++--- tests/phpunit/CRM/Price/BAO/PriceSetTest.php | 20 ++- .../CRMTraits/Contribute/RecurFormsTrait.php | 1 + xml/schema/Contribute/Contribution.xml | 1 + xml/schema/Contribute/ContributionPage.xml | 48 ++++--- xml/templates/civicrm_sample.tpl | 8 +- 21 files changed, 273 insertions(+), 137 deletions(-) create mode 100644 Civi/Api4/Service/Spec/Provider/TitleFieldSpecProvider.php diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index 43a401bdf0af..94aeb0555658 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -17,11 +17,13 @@ use Civi\Api4\Contribution; use Civi\Api4\LineItem; +use Civi\Core\Event\PostEvent; +use Civi\Core\HookInterface; /** * This class contains Contribution Page related functions. */ -class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_ContributionPage { +class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_ContributionPage implements HookInterface { /** * Creates a contribution page. @@ -31,25 +33,22 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio * @return CRM_Contribute_DAO_ContributionPage */ public static function create($params) { - $financialTypeId = NULL; - if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) { - $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id'); - } - + // @todo - this implode is probably handled by writeRecord - test & remove. if (isset($params['payment_processor']) && is_array($params['payment_processor'])) { $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']); } - $hook = empty($params['id']) ? 'create' : 'edit'; - CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params); - $dao = new CRM_Contribute_DAO_ContributionPage(); - $dao->copyValues($params); - $dao->save(); - if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) { - CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']); - } - CRM_Utils_Hook::post($hook, 'ContributionPage', $dao->id, $dao); + return self::writeRecord($params); + } + + /** + * Callback for hook_civicrm_post(). + * + * @param \Civi\Core\Event\PostEvent $event + * + * @noinspection PhpUnusedParameterInspection + */ + public static function self_hook_civicrm_post(PostEvent $event): void { CRM_Core_PseudoConstant::flush(); - return $dao; } /** diff --git a/CRM/Contribute/DAO/Contribution.php b/CRM/Contribute/DAO/Contribution.php index c6c9cb284a2a..42014c57797b 100644 --- a/CRM/Contribute/DAO/Contribution.php +++ b/CRM/Contribute/DAO/Contribution.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contribute/Contribution.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:9e60bb45bfa633f107c72cc1f3049b58) + * (GenCodeChecksum:c612cd79d620e91f7498a3883c635293) */ /** @@ -480,6 +480,7 @@ public static function &fields() { 'table' => 'civicrm_contribution_page', 'keyColumn' => 'id', 'labelColumn' => 'title', + 'nameColumn' => 'name', ], 'add' => '1.5', ], diff --git a/CRM/Contribute/DAO/ContributionPage.php b/CRM/Contribute/DAO/ContributionPage.php index b8da3ff99e4c..a5ca0ed500b0 100644 --- a/CRM/Contribute/DAO/ContributionPage.php +++ b/CRM/Contribute/DAO/ContributionPage.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contribute/ContributionPage.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:075cce622b131127948be961f14fec2b) + * (GenCodeChecksum:fff705a45cbf2750018b57a05e5b1cb2) */ /** @@ -61,12 +61,30 @@ class CRM_Contribute_DAO_ContributionPage extends CRM_Core_DAO { /** * Contribution Page title. For top of page display * - * @var string|null + * @var string * (SQL type: varchar(255)) * Note that values will be retrieved from the database as a string. */ public $title; + /** + * Contribution Page Public title + * + * @var string + * (SQL type: varchar(255)) + * Note that values will be retrieved from the database as a string. + */ + public $frontend_title; + + /** + * Unique name for identifying contribution page + * + * @var string + * (SQL type: varchar(255)) + * Note that values will be retrieved from the database as a string. + */ + public $name; + /** * Text and html allowed. Displayed below title. * @@ -454,15 +472,6 @@ class CRM_Contribute_DAO_ContributionPage extends CRM_Core_DAO { */ public $is_billing_required; - /** - * Contribution Page Public title - * - * @var string|null - * (SQL type: varchar(255)) - * Note that values will be retrieved from the database as a string. - */ - public $frontend_title; - /** * Class constructor. */ @@ -532,8 +541,9 @@ public static function &fields() { 'title' => [ 'name' => 'title', 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('Contribution Page Title'), + 'title' => ts('Page Name'), 'description' => ts('Contribution Page title. For top of page display'), + 'required' => TRUE, 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, 'usage' => [ @@ -552,6 +562,54 @@ public static function &fields() { ], 'add' => '1.3', ], + 'frontend_title' => [ + 'name' => 'frontend_title', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Public Title'), + 'description' => ts('Contribution Page Public title'), + 'required' => TRUE, + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_contribution_page.frontend_title', + 'table_name' => 'civicrm_contribution_page', + 'entity' => 'ContributionPage', + 'bao' => 'CRM_Contribute_BAO_ContributionPage', + 'localizable' => 1, + 'html' => [ + 'type' => 'Text', + ], + 'add' => '5.20', + ], + 'name' => [ + 'name' => 'name', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Unique Name'), + 'description' => ts('Unique name for identifying contribution page'), + 'required' => TRUE, + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_contribution_page.name', + 'table_name' => 'civicrm_contribution_page', + 'entity' => 'ContributionPage', + 'bao' => 'CRM_Contribute_BAO_ContributionPage', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => '5.63', + ], 'intro_text' => [ 'name' => 'intro_text', 'type' => CRM_Utils_Type::T_TEXT, @@ -1488,30 +1546,6 @@ public static function &fields() { 'localizable' => 0, 'add' => '4.6', ], - 'contribution_page_frontend_title' => [ - 'name' => 'frontend_title', - 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('Public Title'), - 'description' => ts('Contribution Page Public title'), - 'maxlength' => 255, - 'size' => CRM_Utils_Type::HUGE, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_contribution_page.frontend_title', - 'default' => NULL, - 'table_name' => 'civicrm_contribution_page', - 'entity' => 'ContributionPage', - 'bao' => 'CRM_Contribute_BAO_ContributionPage', - 'localizable' => 1, - 'html' => [ - 'type' => 'Text', - ], - 'add' => '5.20', - ], ]; CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } @@ -1581,7 +1615,17 @@ public static function &export($prefix = FALSE) { * @return array */ public static function indices($localize = TRUE) { - $indices = []; + $indices = [ + 'UI_name' => [ + 'name' => 'UI_name', + 'field' => [ + 0 => 'name', + ], + 'localizable' => FALSE, + 'unique' => TRUE, + 'sig' => 'civicrm_contribution_page::1::name', + ], + ]; return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; } diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index c4a8e2e80350..5b28abd7af39 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1592,7 +1592,7 @@ protected function postProcessMembership( $membershipSource = $form->_params['membership_source']; } elseif ((isset($form->_values['title']) && !empty($form->_values['title'])) || (isset($form->_values['frontend_title']) && !empty($form->_values['frontend_title']))) { - $title = !empty($form->_values['frontend_title']) ? $form->_values['frontend_title'] : $form->_values['title']; + $title = $form->_values['frontend_title']; $membershipSource = ts('Online Contribution:') . ' ' . $title; } $isPayLater = NULL; @@ -2133,7 +2133,7 @@ protected function processFormSubmission($contactID) { } } // add a description field at the very beginning - $title = !empty($this->_values['frontend_title']) ? $this->_values['frontend_title'] : $this->_values['title']; + $title = $this->_values['frontend_title']; $this->_params['description'] = ts('Online Contribution') . ': ' . (!empty($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $title); $this->_params['accountingCode'] = $this->_values['accountingCode'] ?? NULL; diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index fb6f61e3e719..0a02db1e1c44 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -497,7 +497,7 @@ public function preProcess() { CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values) ); - $title = !empty($this->_values['frontend_title']) ? $this->_values['frontend_title'] : $this->_values['title']; + $title = $this->_values['frontend_title']; $this->setTitle(($this->_pcpId ? $this->_pcpInfo['title'] : $title)); $this->_defaults = []; diff --git a/CRM/Contribute/Form/ContributionPage/Settings.php b/CRM/Contribute/Form/ContributionPage/Settings.php index bad15a145c1e..7669084a27d7 100644 --- a/CRM/Contribute/Form/ContributionPage/Settings.php +++ b/CRM/Contribute/Form/ContributionPage/Settings.php @@ -120,7 +120,7 @@ public function buildQuickForm() { // name $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE); - $this->addField('contribution_page_frontend_title', ['entity' => 'ContributionPage']); + $this->addField('frontend_title', ['entity' => 'ContributionPage'], TRUE); //CRM-7362 --add campaigns. CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values)); diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index ead9a4f45115..0cd22185722d 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -944,6 +944,12 @@ public static function writeRecord(array $record): CRM_Core_DAO { if (empty($values[$idField]) && array_key_exists('name', $fields) && empty($values['name'])) { $instance->makeNameFromLabel(); } + if (empty($values[$idField]) && array_key_exists('frontend_title', $fields) && empty($values['frontend_title'])) { + $instance->frontend_title = $instance->title; + } + if (empty($values[$idField]) && array_key_exists('title', $fields) && empty($values['title']) && !empty($values['frontend_title'])) { + $instance->title = $instance->frontend_title; + } $instance->save(); if (!empty($record['custom']) && is_array($record['custom'])) { @@ -1866,7 +1872,7 @@ public static function copyGeneric($daoName, $criteria, $newData = NULL, $fields $localizableFields = FALSE; foreach ($fields as $name => $value) { - if ($name == 'id' || $value['name'] == 'id') { + if ($name === 'id' || $value['name'] === 'id') { // copy everything but the id! continue; } @@ -1884,7 +1890,7 @@ public static function copyGeneric($daoName, $criteria, $newData = NULL, $fields $newObject->$dbName = $fieldsToReplace[$dbName]; } - if ($type == 'Timestamp' || $type == 'Date') { + if ($type === 'Timestamp' || $type === 'Date') { $newObject->$dbName = CRM_Utils_Date::isoToMysql($newObject->$dbName); } @@ -1896,6 +1902,9 @@ public static function copyGeneric($daoName, $criteria, $newData = NULL, $fields $newObject->copyValues($newData); } } + if (!empty($fields['name'])) { + $newObject->makeNameFromLabel(); + } $newObject->save(); // ensure we copy all localized fields as well diff --git a/CRM/Core/I18n/SchemaStructure.php b/CRM/Core/I18n/SchemaStructure.php index 765a8efd8351..efd06caa5bfd 100644 --- a/CRM/Core/I18n/SchemaStructure.php +++ b/CRM/Core/I18n/SchemaStructure.php @@ -97,7 +97,8 @@ public static function &columns() { 'frontend_description' => "text DEFAULT NULL COMMENT 'Alternative public description of the group.'", ], 'civicrm_contribution_page' => [ - 'title' => "varchar(255) COMMENT 'Contribution Page title. For top of page display'", + 'title' => "varchar(255) NOT NULL COMMENT 'Contribution Page title. For top of page display'", + 'frontend_title' => "varchar(255) NOT NULL COMMENT 'Contribution Page Public title'", 'intro_text' => "text COMMENT 'Text and html allowed. Displayed below title.'", 'pay_later_text' => "text COMMENT 'The text displayed to the user in the main form'", 'pay_later_receipt' => "text COMMENT 'The receipt sent to the user instead of the normal receipt text'", @@ -109,7 +110,6 @@ public static function &columns() { 'receipt_from_name' => "varchar(255) COMMENT 'FROM email name used for receipts generated by contributions to this contribution page.'", 'receipt_text' => "text COMMENT 'text to include above standard receipt info on receipt email. emails are text-only, so do not allow html for now'", 'footer_text' => "text COMMENT 'Text and html allowed. Displayed at the bottom of the first page of the contribution wizard.'", - 'frontend_title' => "varchar(255) DEFAULT NULL COMMENT 'Contribution Page Public title'", ], 'civicrm_product' => [ 'name' => "varchar(255) NOT NULL COMMENT 'Required product/premium name'", @@ -429,6 +429,11 @@ public static function &widgets() { 'civicrm_contribution_page' => [ 'title' => [ 'type' => "Text", + 'required' => "true", + ], + 'frontend_title' => [ + 'type' => "Text", + 'required' => "true", ], 'intro_text' => [ 'type' => "RichTextEditor", @@ -473,9 +478,6 @@ public static function &widgets() { 'rows' => "6", 'cols' => "50", ], - 'frontend_title' => [ - 'type' => "Text", - ], ], 'civicrm_product' => [ 'name' => [ diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index acdceee88045..81214edd06f7 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -9,6 +9,7 @@ +--------------------------------------------------------------------+ */ +use Civi\Core\Exception\DBQueryException; use Civi\Core\SettingsBag; /** @@ -609,7 +610,12 @@ public static function alterColumn($ctx, $table, $column, $properties, $localiza $queries[] = "ALTER TABLE `$table` CHANGE `$column` `$column` $properties"; } foreach ($queries as $query) { - CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE); + try { + CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE); + } + catch (DBQueryException $e) { + throw new CRM_Core_Exception($e->getSQLErrorCode() . "\n" . $e->getDebugInfo()); + } } $schema = new CRM_Logging_Schema(); if ($schema->isEnabled()) { diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyThree.php b/CRM/Upgrade/Incremental/php/FiveSixtyThree.php index 95835f1dfd47..583146387cc9 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyThree.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyThree.php @@ -26,13 +26,21 @@ class CRM_Upgrade_Incremental_php_FiveSixtyThree extends CRM_Upgrade_Incremental * * @param string $rev * The version number matching this function name + * + * @throws \Civi\Core\Exception\DBQueryException */ - public function upgrade_5_63_alpha1($rev): void { + public function upgrade_5_63_alpha1(string $rev): void { + $this->addTask('Add name column to civicrm_contribution_page', 'addColumn', 'civicrm_contribution_page', + 'name', "varchar(255) NULL COMMENT 'Unique name for identifying contribution page'"); $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); $enabledComponents = Civi::settings()->get('enable_components'); $extensions = array_map(['CRM_Utils_String', 'convertStringToSnakeCase'], $enabledComponents); $this->addExtensionTask('Enable component extensions', $extensions); + + $this->addTask('Make ContributionPage.name required', 'alterColumn', 'civicrm_contribution_page', 'name', "varchar(255) NOT NULL COMMENT 'Unique name for identifying contribution page'"); + $this->addTask('Make ContributionPage.title required', 'alterColumn', 'civicrm_contribution_page', 'title', "varchar(255) NOT NULL COMMENT 'Contribution Page title. For top of page display'", TRUE); + $this->addTask('Make ContributionPage.frontend_title required', 'alterColumn', 'civicrm_contribution_page', 'frontend_title', "varchar(255) NOT NULL COMMENT 'Contribution Page Public title'", TRUE); } } diff --git a/CRM/Upgrade/Incremental/sql/5.63.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.63.alpha1.mysql.tpl index 6fb9a85cf3ce..d96fd227a11f 100644 --- a/CRM/Upgrade/Incremental/sql/5.63.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.63.alpha1.mysql.tpl @@ -14,3 +14,19 @@ VALUES ( {$domainID}, 'https://civicrm.org/help?src=iam', '{ts escape="sql" skip="true"}Get Help{/ts}', 'Get Help', NULL, 'AND', @adminHelplastID, '1', NULL, 2 ); UPDATE IGNORE `civicrm_navigation` SET `name` = 'Register Your Site', `label` = '{ts escape="sql" skip="true"}Register Your Site{/ts}' WHERE `name` = 'Register your site'; + +-- Ensure new name field is not null/unique. Setting to ID is a bit lazy - but sql localisation is painful. +UPDATE civicrm_contribution_page SET `name` = `id`; + +-- Add name field, make frontend_title required (in conjunction with php function) +{if $multilingual} + {foreach from=$locales item=locale} + UPDATE `civicrm_contribution_page` + SET `frontend_title_{$locale}` = `title_{$locale}` + WHERE `frontend_title_{$locale}` IS NULL OR `frontend_title_{$locale}` = ''; + {/foreach} +{else} + UPDATE `civicrm_contribution_page` + SET `frontend_title` = `title` + WHERE `frontend_title` IS NULL OR `frontend_title` = ''; +{/if} diff --git a/Civi/Api4/Service/Spec/Provider/PaymentProcessorCreationSpecProvider.php b/Civi/Api4/Service/Spec/Provider/PaymentProcessorCreationSpecProvider.php index 5a592e5f7a90..9e11858ce02a 100644 --- a/Civi/Api4/Service/Spec/Provider/PaymentProcessorCreationSpecProvider.php +++ b/Civi/Api4/Service/Spec/Provider/PaymentProcessorCreationSpecProvider.php @@ -25,13 +25,6 @@ class PaymentProcessorCreationSpecProvider extends \Civi\Core\Service\AutoServic * @inheritDoc */ public function modifySpec(RequestSpec $spec) { - // Name is autogenerated from title if missing - $spec->getFieldByName('name')->setRequired(FALSE)->setRequiredIf('empty($values.title)'); - // Title is supplied from name if missing - $spec->getFieldByName('title')->setRequired(FALSE)->setRequiredIf('empty($values.name)'); - // Frontend_title is copied from title if missing - $spec->getFieldByName('frontend_title')->setRequired(FALSE); - // Billing mode is copied across from the payment processor type field in the BAO::create function. $spec->getFieldByName('billing_mode')->setRequired(FALSE); diff --git a/Civi/Api4/Service/Spec/Provider/TitleFieldSpecProvider.php b/Civi/Api4/Service/Spec/Provider/TitleFieldSpecProvider.php new file mode 100644 index 000000000000..4b5810e93790 --- /dev/null +++ b/Civi/Api4/Service/Spec/Provider/TitleFieldSpecProvider.php @@ -0,0 +1,50 @@ +getFieldByName('name')->setRequired(FALSE)->setRequiredIf('empty($values.title)'); + // Title is supplied from name if missing + $spec->getFieldByName('title')->setRequired(FALSE)->setRequiredIf('empty($values.name)'); + // Frontend_title is copied from title if missing + $spec->getFieldByName('frontend_title')->setRequired(FALSE); + } + + /** + * @inheritDoc + */ + public function applies($entity, $action): bool { + return in_array($entity, ['PaymentProcessor', 'ContributionPage']) && $action === 'create'; + } + +} diff --git a/sql/civicrm_generated.mysql b/sql/civicrm_generated.mysql index 7b88752ba6f7..1473deeeba0b 100644 --- a/sql/civicrm_generated.mysql +++ b/sql/civicrm_generated.mysql @@ -2397,10 +2397,10 @@ UNLOCK TABLES; LOCK TABLES `civicrm_contribution_page` WRITE; /*!40000 ALTER TABLE `civicrm_contribution_page` DISABLE KEYS */; -INSERT INTO `civicrm_contribution_page` (`id`, `title`, `intro_text`, `financial_type_id`, `payment_processor`, `is_credit_card_only`, `is_monetary`, `is_recur`, `is_confirm_enabled`, `recur_frequency_unit`, `is_recur_interval`, `is_recur_installments`, `adjust_recur_start_date`, `is_pay_later`, `pay_later_text`, `pay_later_receipt`, `is_partial_payment`, `initial_amount_label`, `initial_amount_help_text`, `min_initial_amount`, `is_allow_other_amount`, `default_amount_id`, `min_amount`, `max_amount`, `goal_amount`, `thankyou_title`, `thankyou_text`, `thankyou_footer`, `is_email_receipt`, `receipt_from_name`, `receipt_from_email`, `cc_receipt`, `bcc_receipt`, `receipt_text`, `is_active`, `footer_text`, `amount_block_is_active`, `start_date`, `end_date`, `created_id`, `created_date`, `currency`, `campaign_id`, `is_share`, `is_billing_required`, `frontend_title`) VALUES - (1,'Help Support CiviCRM!','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Contribute NOW by trying out our new online contribution features!',1,NULL,0,1,0,1,NULL,0,0,0,0,NULL,NULL,0,NULL,NULL,NULL,1,137,10.00,10000.00,100000.00,'Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools.

Please tell your friends and colleagues about CiviCRM!

','

Back to CiviCRM Home Page

',1,'CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1,NULL,1,NULL,NULL,NULL,NULL,'USD',NULL,1,0,NULL), - (2,'Member Signup and Renewal','Members are the life-blood of our organization. If you\'re not already a member - please consider signing up today. You can select the membership level the fits your budget and needs below.',2,NULL,0,1,0,1,NULL,0,0,0,0,NULL,NULL,0,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,'Thanks for Your Support!','Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.',NULL,1,'Membership Department','memberships@civicrm.org',NULL,NULL,'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.\r\n\r\nKeep this receipt for your records.',1,NULL,0,NULL,NULL,NULL,NULL,'USD',NULL,1,0,NULL), - (3,'Pledge for CiviCRM!','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Pledge NOW by trying out our online contribution features!',1,NULL,0,1,0,1,NULL,0,0,0,0,NULL,NULL,0,NULL,NULL,NULL,1,NULL,10.00,10000.00,100000.00,'Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools like Pledge.

Please tell your friends and colleagues about CiviPledge!

','

Back to CiviCRM Home Page

',1,'CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1,NULL,1,NULL,NULL,NULL,NULL,'USD',NULL,1,0,NULL); +INSERT INTO `civicrm_contribution_page` (`id`, `title`, `name`, `intro_text`, `financial_type_id`, `payment_processor`, `is_credit_card_only`, `is_monetary`, `is_recur`, `is_confirm_enabled`, `recur_frequency_unit`, `is_recur_interval`, `is_recur_installments`, `adjust_recur_start_date`, `is_pay_later`, `pay_later_text`, `pay_later_receipt`, `is_partial_payment`, `initial_amount_label`, `initial_amount_help_text`, `min_initial_amount`, `is_allow_other_amount`, `default_amount_id`, `min_amount`, `max_amount`, `goal_amount`, `thankyou_title`, `thankyou_text`, `thankyou_footer`, `is_email_receipt`, `receipt_from_name`, `receipt_from_email`, `cc_receipt`, `bcc_receipt`, `receipt_text`, `is_active`, `footer_text`, `amount_block_is_active`, `start_date`, `end_date`, `created_id`, `created_date`, `currency`, `campaign_id`, `is_share`, `is_billing_required`, `frontend_title`) VALUES + (1,'Help Support CiviCRM!','donate','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Contribute NOW by trying out our new online contribution features!',1,NULL,0,1,0,1,NULL,0,0,0,0,NULL,NULL,0,NULL,NULL,NULL,1,137,10.00,10000.00,100000.00,'Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools.

Please tell your friends and colleagues about CiviCRM!

','

Back to CiviCRM Home Page

',1,'CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1,NULL,1,NULL,NULL,NULL,NULL,'USD',NULL,1,0,NULL), + (2,'Member Signup and Renewal','membership','Members are the life-blood of our organization. If you\'re not already a member - please consider signing up today. You can select the membership level the fits your budget and needs below.',2,NULL,0,1,0,1,NULL,0,0,0,0,NULL,NULL,0,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,'Thanks for Your Support!','Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.',NULL,1,'Membership Department','memberships@civicrm.org',NULL,NULL,'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.\r\n\r\nKeep this receipt for your records.',1,NULL,0,NULL,NULL,NULL,NULL,'USD',NULL,1,0,NULL), + (3,'Pledge for CiviCRM!','pledge','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Pledge NOW by trying out our online contribution features!',1,NULL,0,1,0,1,NULL,0,0,0,0,NULL,NULL,0,NULL,NULL,NULL,1,NULL,10.00,10000.00,100000.00,'Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools like Pledge.

Please tell your friends and colleagues about CiviPledge!

','

Back to CiviCRM Home Page

',1,'CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1,NULL,1,NULL,NULL,NULL,NULL,'USD',NULL,1,0,NULL); /*!40000 ALTER TABLE `civicrm_contribution_page` ENABLE KEYS */; UNLOCK TABLES; diff --git a/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl b/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl index ed2d4f78d574..4645a9de5175 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl +++ b/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl @@ -20,14 +20,14 @@
{include file="CRM/common/formButtons.tpl" location="top"}
- - - - - - - - + + + + + + + + diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php index da86515a9369..b9d20497ac6d 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionPageTest.php @@ -15,21 +15,15 @@ */ class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase { - const FINANCIAL_TYPE_ID = 1; - - public function setUp(): void { - parent::setUp(); - } - /** * Create() method (create Contribution Page) */ - public function testCreate() { + public function testCreate(): void { $params = [ 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e', 'title' => 'Test Contribution Page', - 'financial_type_id' => self::FINANCIAL_TYPE_ID, + 'financial_type_id' => 1, 'intro_text' => '', 'footer_text' => 'Thanks', 'is_for_organization' => 0, @@ -45,21 +39,19 @@ public function testCreate() { 'is_credit_card_only' => '', ]; - $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params); - - $this->assertNotNull($contributionpage->id); - $this->assertIsInt($contributionpage->id); - $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]); + $contributionPageID = CRM_Contribute_BAO_ContributionPage::create($params)->id; + $this->assertIsInt($contributionPageID); + $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPageID]); } /** * Test setValues() method */ - public function testSetValues() { + public function testSetValues(): void { $params = [ 'title' => 'Test Contribution Page', - 'financial_type_id' => self::FINANCIAL_TYPE_ID, + 'financial_type_id' => 1, 'is_active' => 1, ]; @@ -70,7 +62,7 @@ public function testSetValues() { CRM_Contribute_BAO_ContributionPage::setValues($id, $values); $this->assertEquals($params['title'], $values['title'], 'Verify contribution title.'); - $this->assertEquals(self::FINANCIAL_TYPE_ID, $values['financial_type_id'], 'Verify financial types id.'); + $this->assertEquals(1, $values['financial_type_id'], 'Verify financial types id.'); $this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.'); $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]); } @@ -78,11 +70,11 @@ public function testSetValues() { /** * Test copy() method */ - public function testcopy() { + public function testcopy(): void { $params = [ 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e', 'title' => 'Test Contribution Page', - 'financial_type_id' => self::FINANCIAL_TYPE_ID, + 'financial_type_id' => 1, 'intro_text' => '', 'footer_text' => 'Thanks', 'is_for_organization' => 0, @@ -100,8 +92,8 @@ public function testcopy() { $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); $copyContributionPage = CRM_Contribute_BAO_ContributionPage::copy($contributionPage->id); - $this->assertEquals($copyContributionPage->financial_type_id, self::FINANCIAL_TYPE_ID, 'Check for Financial type id.'); - $this->assertEquals($copyContributionPage->goal_amount, 400, 'Check for goal amount.'); + $this->assertEquals(1, $copyContributionPage->financial_type_id, 'Check for Financial type id.'); + $this->assertEquals(400, $copyContributionPage->goal_amount, 'Check for goal amount.'); $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]); $this->callAPISuccess('ContributionPage', 'delete', ['id' => $copyContributionPage->id]); } diff --git a/tests/phpunit/CRM/Price/BAO/PriceSetTest.php b/tests/phpunit/CRM/Price/BAO/PriceSetTest.php index 05fd017999f8..0b54d72b63f7 100644 --- a/tests/phpunit/CRM/Price/BAO/PriceSetTest.php +++ b/tests/phpunit/CRM/Price/BAO/PriceSetTest.php @@ -20,10 +20,8 @@ class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase { * * (these are denoted as 'quickConfig' in the code - but quickConfig is only supposed to refer to the * configuration interface - there should be no different post process. - * - * @throws \CRM_Core_Exception */ - public function testGetAmountLevelTextAmount() { + public function testGetAmountLevelTextAmount(): void { $priceSetID = $this->eventPriceSetCreate(9); $priceSet = CRM_Price_BAO_PriceSet::getCachedPriceSetDetail($priceSetID); $field = reset($priceSet['fields']); @@ -37,21 +35,19 @@ public function testGetAmountLevelTextAmount() { } /** - * CRM-20237 Test that Copied price set does not generate long name and unneded information - * - * @throws \CRM_Core_Exception + * CRM-20237 Test that Copied price set does not generate long name and unnecessary information */ - public function testCopyPriceSet() { + public function testCopyPriceSet(): void { $priceSetID = $this->eventPriceSetCreate(9); $oldPriceSetInfo = $this->callAPISuccess('PriceSet', 'getsingle', ['id' => $priceSetID]); $newPriceSet = CRM_Price_BAO_PriceSet::copy($priceSetID); - $this->assertEquals(substr($oldPriceSetInfo['name'], 0, 20) . 'price_set_' . $newPriceSet->id, $newPriceSet->name); + $this->assertEquals('Price_Set_Copy_id_' . $newPriceSet->id . '_', $newPriceSet->name); $this->assertEquals($oldPriceSetInfo['title'] . ' [Copy id ' . $newPriceSet->id . ']', $newPriceSet->title); $new2PriceSet = CRM_Price_BAO_PriceSet::copy($newPriceSet->id); - $this->assertEquals(substr($newPriceSet->name, 0, 20) . 'price_set_' . $new2PriceSet->id, $new2PriceSet->name); + $this->assertEquals('Price_Set_Copy_id_' . $new2PriceSet->id . '_', $new2PriceSet->name); $this->assertEquals($oldPriceSetInfo['title'] . ' [Copy id ' . $new2PriceSet->id . ']', $new2PriceSet->title); - $oldPriceField = $this->callAPISuccess('priceField', 'getsingle', ['price_set_id' => $priceSetID]); - $oldPriceFieldValue = $this->callAPISuccess('priceFieldValue', 'getsingle', ['price_field_id' => $oldPriceField['id']]); + $oldPriceField = $this->callAPISuccess('PriceField', 'getsingle', ['price_set_id' => $priceSetID]); + $oldPriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $oldPriceField['id']]); $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $oldPriceFieldValue['id']]); $this->callAPISuccess('PriceField', 'delete', ['id' => $oldPriceField['id']]); $this->callAPISuccess('PriceSet', 'delete', ['id' => $priceSetID]); @@ -73,7 +69,7 @@ public function testCopyPriceSet() { * * @throws \CRM_Core_Exception */ - public function testGetMembershipCount() { + public function testGetMembershipCount(): void { // create two organisations $organization1 = $this->organizationCreate(); $organization2 = $this->organizationCreate(); diff --git a/tests/phpunit/CRMTraits/Contribute/RecurFormsTrait.php b/tests/phpunit/CRMTraits/Contribute/RecurFormsTrait.php index 7c4c0dd753c9..88ddc42d78e0 100644 --- a/tests/phpunit/CRMTraits/Contribute/RecurFormsTrait.php +++ b/tests/phpunit/CRMTraits/Contribute/RecurFormsTrait.php @@ -98,6 +98,7 @@ public function getContributionPageID(): int { 'receipt_from_name' => 'Bob', 'receipt_from_email' => 'bob@example.org', 'financial_type_id' => 'Donation', + 'title' => 'page', ])['id']; } return $this->ids['ContributionPage'][0]; diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index 440969da492c..99089cd2fd2c 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -88,6 +88,7 @@
{$form.title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_contribution_page' field='title' id=$contributionPageID}{/if}{$form.title.html}
{$form.contribution_page_frontend_title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_contribution_page' field='frontend_title' id=$contributionPageID}{/if}{$form.contribution_page_frontend_title.html}
{$form.frontend_title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_contribution_page' field='frontend_title' id=$contributionPageID}{/if}{$form.frontend_title.html}
{$form.title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_contribution_page' field='title' id=$contributionPageID}{/if}{$form.title.html}
{$form.financial_type_id.label} {help id="id-financial_type"} {$form.financial_type_id.html}
civicrm_contribution_page
id + name title diff --git a/xml/schema/Contribute/ContributionPage.xml b/xml/schema/Contribute/ContributionPage.xml index 56519fefbc11..d1067e82653a 100644 --- a/xml/schema/Contribute/ContributionPage.xml +++ b/xml/schema/Contribute/ContributionPage.xml @@ -31,16 +31,42 @@ title - Contribution Page Title + Page Name varchar 255 true + true Contribution Page title. For top of page display 1.3 Text + + frontend_title + Public Title + varchar + 255 + true + true + Contribution Page Public title + + Text + + 5.20 + + + name + Unique Name + Unique name for identifying contribution page + true + varchar + 255 + + Text + + 5.63 + intro_text Contribution Page Introduction Text @@ -501,18 +527,10 @@ if true - billing block is required for online contribution page 4.6 - - frontend_title - Public Title - varchar - 255 - true - NULL - Contribution Page Public title - - Text - - 5.20 - contribution_page_frontend_title - + + UI_name + name + true + 2.1 + diff --git a/xml/templates/civicrm_sample.tpl b/xml/templates/civicrm_sample.tpl index 266052884f92..412e770b51df 100644 --- a/xml/templates/civicrm_sample.tpl +++ b/xml/templates/civicrm_sample.tpl @@ -44,11 +44,11 @@ VALUES (@priceFieldID, 'other_amount', 'Other Amount', 1, 3, 1, 0, 1); INSERT INTO civicrm_contribution_page - (title,intro_text,financial_type_id,is_monetary,is_allow_other_amount,default_amount_id,min_amount,max_amount,goal_amount,thankyou_title,thankyou_text,thankyou_footer,receipt_from_name,receipt_from_email,cc_receipt,bcc_receipt,receipt_text,is_active,footer_text,amount_block_is_active,currency,is_email_receipt) + (title,frontend_title, name,intro_text,financial_type_id,is_monetary,is_allow_other_amount,default_amount_id,min_amount,max_amount,goal_amount,thankyou_title,thankyou_text,thankyou_footer,receipt_from_name,receipt_from_email,cc_receipt,bcc_receipt,receipt_text,is_active,footer_text,amount_block_is_active,currency,is_email_receipt) VALUES - ('Help Support CiviCRM!','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Contribute NOW by trying out our new online contribution features!',1,1,1,137,'10.00','10000.00','100000.00','Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools.

Please tell your friends and colleagues about CiviCRM!

','

Back to CiviCRM Home Page

','CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1, NULL, 1, 'USD', 1), - ('Member Signup and Renewal', 'Members are the life-blood of our organization. If you''re not already a member - please consider signing up today. You can select the membership level the fits your budget and needs below.', 2, 1, 0, NULL, NULL, NULL, NULL, 'Thanks for Your Support!', 'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.', NULL, 'Membership Department', 'memberships@civicrm.org', NULL, NULL, 'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.\r\n\r\nKeep this receipt for your records.', 1, NULL, 0, 'USD', 1), - ('Pledge for CiviCRM!','Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Pledge NOW by trying out our online contribution features!',1,1,1,NULL,'10.00','10000.00','100000.00','Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools like Pledge.

Please tell your friends and colleagues about CiviPledge!

','

Back to CiviCRM Home Page

','CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1, NULL, 1, 'USD', 1); + ('Donate page', 'Help Support CiviCRM!','donate', 'Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Contribute NOW by trying out our new online contribution features!',1,1,1,137,'10.00','10000.00','100000.00','Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools.

Please tell your friends and colleagues about CiviCRM!

','

Back to CiviCRM Home Page

','CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1, NULL, 1, 'USD', 1), + ('Membership page','Member Signup and Renewal', 'membership','Members are the life-blood of our organization. If you''re not already a member - please consider signing up today. You can select the membership level the fits your budget and needs below.', 2, 1, 0, NULL, NULL, NULL, NULL, 'Thanks for Your Support!', 'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.', NULL, 'Membership Department', 'memberships@civicrm.org', NULL, NULL, 'Thanks for supporting our organization with your membership. You can learn more about membership benefits from our members only page.\r\n\r\nKeep this receipt for your records.', 1, NULL, 0, 'USD', 1), + ('Pledge page', 'Pledge for CiviCRM!','pledge', 'Do you love CiviCRM? Do you use CiviCRM? Then please support CiviCRM and Pledge NOW by trying out our online contribution features!',1,1,1,NULL,'10.00','10000.00','100000.00','Thanks for Your Support!','

Thank you for your support. Your contribution will help us build even better tools like Pledge.

Please tell your friends and colleagues about CiviPledge!

','

Back to CiviCRM Home Page

','CiviCRM Fundraising Dept.','donationFake@civicrm.org','receipt@example.com','bcc@example.com','Your donation is tax deductible under IRS 501(c)(3) regulation. Our tax identification number is: 93-123-4567',1, NULL, 1, 'USD', 1); INSERT INTO `civicrm_tell_friend` (`entity_table`, `entity_id`, `title`, `intro`, `suggested_message`, `general_link`, `thankyou_title`, `thankyou_text`, `is_active`)