Skip to content

Commit

Permalink
Merge pull request #26231 from colemanw/campaignIndexes
Browse files Browse the repository at this point in the history
REF - Fix Campaign index names, add default value for created_date
  • Loading branch information
aydun authored Jun 5, 2023
2 parents 9280554 + e383fa5 commit 854a117
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
4 changes: 0 additions & 4 deletions CRM/Campaign/BAO/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public static function create(&$params) {
if (empty($params['created_id'])) {
$params['created_id'] = CRM_Core_Session::getLoggedInContactID();
}

if (empty($params['created_date'])) {
$params['created_date'] = date('YmdHis');
}
}

/** @var \CRM_Campaign_DAO_Campaign $campaign */
Expand Down
13 changes: 8 additions & 5 deletions CRM/Campaign/DAO/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Campaign/Campaign.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:75a9a33157dcd3411e3072a2b3740b0f)
* (GenCodeChecksum:dbeaf967ec7d7d3532d4cacb2a0e36b4)
*/

/**
Expand Down Expand Up @@ -586,14 +586,17 @@ public static function &fields() {
'token' => FALSE,
],
'where' => 'civicrm_campaign.created_date',
'default' => 'CURRENT_TIMESTAMP',
'table_name' => 'civicrm_campaign',
'entity' => 'Campaign',
'bao' => 'CRM_Campaign_BAO_Campaign',
'localizable' => 0,
'html' => [
'type' => 'Select Date',
'formatType' => 'activityDateTime',
'label' => ts("Created Date"),
],
'readonly' => TRUE,
'add' => '3.3',
],
'last_modified_id' => [
Expand Down Expand Up @@ -762,16 +765,16 @@ public static function indices($localize = TRUE) {
'unique' => TRUE,
'sig' => 'civicrm_campaign::1::name',
],
'UI_campaign_type_id' => [
'name' => 'UI_campaign_type_id',
'index_campaign_type_id' => [
'name' => 'index_campaign_type_id',
'field' => [
0 => 'campaign_type_id',
],
'localizable' => FALSE,
'sig' => 'civicrm_campaign::0::campaign_type_id',
],
'UI_campaign_status_id' => [
'name' => 'UI_campaign_status_id',
'index_status_id' => [
'name' => 'index_status_id',
'field' => [
0 => 'status_id',
],
Expand Down
7 changes: 7 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveSixtyThree.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function upgrade_5_63_alpha1(string $rev): void {
'name', "varchar(255) NULL COMMENT 'Unique name for identifying contribution page'");
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);

// Campaign indexes
$this->addTask(ts('Drop index %1', [1 => 'civicrm_campaign.UI_campaign_type_id']), 'dropIndex', 'civicrm_campaign', 'UI_campaign_type_id');
$this->addTask(ts('Create index %1', [1 => 'civicrm_campaign.index_campaign_type_id']), 'addIndex', 'civicrm_campaign', 'campaign_type_id', 'index');
$this->addTask(ts('Drop index %1', [1 => 'civicrm_campaign.UI_campaign_status_id']), 'dropIndex', 'civicrm_campaign', 'UI_campaign_status_id');
$this->addTask(ts('Create index %1', [1 => 'civicrm_campaign.index_status_id']), 'addIndex', 'civicrm_campaign', 'status_id', 'index');
$this->addTask('Add default value to civicrm_campaign.created_date', 'alterColumn', 'civicrm_campaign', 'created_date', "datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time that Campaign was created.'");

$enabledComponents = Civi::settings()->get('enable_components');
$extensions = array_map(['CRM_Utils_String', 'convertStringToSnakeCase'], $enabledComponents);
$this->addExtensionTask('Enable component extensions', $extensions);
Expand Down
13 changes: 8 additions & 5 deletions xml/schema/Campaign/Campaign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<name>UI_name</name>
<fieldName>name</fieldName>
<unique>true</unique>
<add>5.61</add>
<add>5.63</add>
</index>
<field>
<name>title</name>
Expand Down Expand Up @@ -127,9 +127,9 @@
<add>3.3</add>
</field>
<index>
<name>UI_campaign_type_id</name>
<name>index_campaign_type_id</name>
<fieldName>campaign_type_id</fieldName>
<add>3.3</add>
<add>5.63</add>
</index>

<field>
Expand All @@ -149,9 +149,9 @@
<add>3.3</add>
</field>
<index>
<name>UI_campaign_status_id</name>
<name>index_status_id</name>
<fieldName>status_id</fieldName>
<add>3.3</add>
<add>5.63</add>
</index>

<field>
Expand Down Expand Up @@ -233,12 +233,15 @@
<field>
<name>created_date</name>
<type>datetime</type>
<default>CURRENT_TIMESTAMP</default>
<readonly>true</readonly>
<title>Campaign Created Date</title>
<comment>Date and time that Campaign was created.</comment>
<add>3.3</add>
<html>
<type>Select Date</type>
<formatType>activityDateTime</formatType>
<label>Created Date</label>
</html>
</field>

Expand Down

0 comments on commit 854a117

Please sign in to comment.