* @param string $blockCopyOfDependencies
* Fields that you want to block from.
* getting copied
+ * @param bool $blockCopyofCustomValues
+ * Case when you don't want to copy the custom values set in a
+ * template as it will override/ignore the submitted custom values
*
* @return CRM_Core_DAO|bool
* the newly created copy of the object. False if none created.
*/
- public static function copyGeneric($daoName, $criteria, $newData = NULL, $fieldsFix = NULL, $blockCopyOfDependencies = NULL) {
+ public static function copyGeneric($daoName, $criteria, $newData = NULL, $fieldsFix = NULL, $blockCopyOfDependencies = NULL, $blockCopyofCustomValues = FALSE) {
$object = new $daoName();
$newObject = FALSE;
if (!$newData) {
}
}
$newObject->save();
- $newObject->copyCustomFields($object->id, $newObject->id);
+ if (!$blockCopyofCustomValues) {
+ $newObject->copyCustomFields($object->id, $newObject->id);
+ }
CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName($daoName), $newObject->id, $newObject);
}
/**
* Transform an array to a serialized string for database storage.
*
- * @param array|NULL $value
- * @param $serializationType
- * @return string|NULL
+ * @param array|null $value
+ * @param int $serializationType
+ * @return string|null
+ *
* @throws \Exception
*/
public static function serializeField($value, $serializationType) {
*
* @param string|null $value
* @param $serializationType
+ *
* @return array|null
- * @throws \Exception
+ * @throws CRM_Core_Exception
*/
public static function unSerializeField($value, $serializationType) {
if ($value === NULL) {
return strlen($value) ? json_decode($value, TRUE) : [];
case self::SERIALIZE_PHP:
- return strlen($value) ? unserialize($value) : [];
+ return strlen($value) ? unserialize($value, ['allowed_classes' => FALSE]) : [];
case self::SERIALIZE_COMMA:
return explode(',', trim(str_replace(', ', '', $value)));
default:
- throw new Exception('Unknown serialization method for field.');
+ throw new CRM_Core_Exception('Unknown serialization method for field.');
}
}