Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#4213 Make contribution_page.frontend_title required #26259

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions CRM/Contribute/BAO/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion CRM/Contribute/DAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contribute/Contribution.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:9e60bb45bfa633f107c72cc1f3049b58)
* (GenCodeChecksum:c612cd79d620e91f7498a3883c635293)
*/

/**
Expand Down Expand Up @@ -480,6 +480,7 @@ public static function &fields() {
'table' => 'civicrm_contribution_page',
'keyColumn' => 'id',
'labelColumn' => 'title',
'nameColumn' => 'name',
],
'add' => '1.5',
],
Expand Down
118 changes: 81 additions & 37 deletions CRM/Contribute/DAO/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contribute/ContributionPage.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:075cce622b131127948be961f14fec2b)
* (GenCodeChecksum:fff705a45cbf2750018b57a05e5b1cb2)
*/

/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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' => [
Expand All @@ -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,
Expand Down Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionPage/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
13 changes: 11 additions & 2 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions CRM/Core/I18n/SchemaStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand All @@ -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'",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -473,9 +478,6 @@ public static function &widgets() {
'rows' => "6",
'cols' => "50",
],
'frontend_title' => [
'type' => "Text",
],
],
'civicrm_product' => [
'name' => [
Expand Down
8 changes: 7 additions & 1 deletion CRM/Upgrade/Incremental/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
+--------------------------------------------------------------------+
*/

use Civi\Core\Exception\DBQueryException;
use Civi\Core\SettingsBag;

/**
Expand Down Expand Up @@ -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()) {
Expand Down
Loading