CRM-20237 keep some of original name in name field
[civicrm-core.git] / CRM / Price / BAO / PriceSet.php
index 27fdb9014ec54ae3479fbc52ccfbab487a29b4f4..7d92106f670e91f4b693a70fc95da2c97589e30c 100644 (file)
@@ -1240,24 +1240,25 @@ WHERE  id = %1";
    */
   public static function copy($id) {
     $maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set");
-    $oldTitle = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $id, 'title', 'id');
-    $newTitle = preg_replace('/\[Copy id \d+\]$/', "", $oldTitle);
+    $priceSet = civicrm_api3('PriceSet', 'getsingle', array('id' => $id));
+
+    $newTitle = preg_replace('/\[Copy id \d+\]$/', "", $priceSet['title']);
     $title = ts('[Copy id %1]', array(1 => $maxId + 1));
     $fieldsFix = array(
       'replace' => array(
         'title' => trim($newTitle) . ' ' . $title,
-        'name' => 'Price_Set__id_' . ($maxId + 1) . '_',
+        'name' => substr($priceSet['name'], 0, 20) . 'price_set_' . ($maxId + 1),
       ),
     );
 
-    $copy = &CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSet',
+    $copy = CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSet',
       array('id' => $id),
       NULL,
       $fieldsFix
     );
 
     //copying all the blocks pertaining to the price set
-    $copyPriceField = &CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceField',
+    $copyPriceField = CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceField',
       array('price_set_id' => $id),
       array('price_set_id' => $copy->id)
     );