Skip to content

Commit e434548

Browse files
committed
Fix #72: '"Copy price set" can trigger fatal errors ...'
1 parent b21053a commit e434548

2 files changed

Lines changed: 13 additions & 20 deletions

File tree

info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<author>Allen Shaw</author>
1414
<email>allen@joineryhq.com</email>
1515
</maintainer>
16-
<releaseDate>2025-06-16</releaseDate>
17-
<version>1.5.5</version>
16+
<releaseDate>2025-09-16</releaseDate>
17+
<version>1.6.0</version>
1818
<develStage>stable</develStage>
1919
<compatibility>
20-
<ver>5.38</ver>
20+
<ver>5.65</ver>
2121
</compatibility>
2222
<comments>Initial development sponsored by the Vestibular Disorders Assocation.</comments>
2323
<civix>

percentagepricesetfield.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,18 @@
88
/**
99
* Implements hook_civicrm_copy().
1010
*/
11-
function percentagepricesetfield_civicrm_copy($objectName, &$object) {
11+
function percentagepricesetfield_civicrm_copy($objectName, &$object, $original_id = NULL) {
1212
if (strtolower($objectName) == 'set') {
13-
// Get the price set that this one was copied from, basd on the convention
14-
// that copied price sets always have '__Copy_id_[N]_' or '_Copy_id_[N]_' appended
15-
// to their name, where [N] is an integer.
16-
// Notes:
17-
// - [N] is often, but not always, the ID of the new price set, because N is
18-
// calculated using max(id)+1, and max(id) is not always equivalent to the
19-
// next serial ID.)
20-
// - Note the difference between leading "__" and leading "_" in the appended
21-
// strings. This seems to vary by CiviCRM version, older versions using two
22-
// underscores, and newer versions using only one.
23-
$original_price_set_name = preg_replace('/_+Copy_id_[0-9]+_$/', '', $object->name);
24-
$params = array(
25-
'name' => $original_price_set_name,
26-
);
27-
CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceSet', $params, $source_price_set);
13+
if (!$original_id) {
14+
// If we don't know the original price set id, we cannot copy the
15+
// Percentage Price Fields configurations. Therefore, alert the user and
16+
// skip any further action.
17+
CRM_Core_Session::setStatus(E::ts('If the new Price Set contains any Percentage Price Set Fields, they were not fully configured. Please double-check the configuration of any such fields in the new Price Set.'), 'Caution.', 'error');
18+
return;
19+
}
20+
2821
// Get all percentage fields in the source prices set:
29-
$source_percentage_field_ids = _percentagepricesetfield_get_percentage_field_ids($source_price_set['id'], FALSE);
22+
$source_percentage_field_ids = _percentagepricesetfield_get_percentage_field_ids($original_id, FALSE);
3023
foreach ($source_percentage_field_ids as $field_id) {
3124
// Get the percentage price field values for this field.
3225
$source_percentage_values = _percentagepricesetfield_get_settings($field_id, FALSE);

0 commit comments

Comments
 (0)