Create a generic copy or clone api
This is a spin off of #4130 (closed)
I was looking at supporting import job templates & thought a clone or copy api makes sense.
I'm no longer prioritising this part & I think putting the code in the form layer or BAO layer for the specific entity is enouugh for now.
In order to clone the job the code looks something like
$userJob = UserJob::get()->addWhere('id', '=', $templateID)->execute()->first();
unset($userJob['metadata']['DataSource']['table_name'], $userJob['metadata']['submitted_values']['uploadFile'], $userJob['id'], $userJob['created_id'], $userJob['created_date'], $userJob['expires_date']);
$userJobID = UserJob::create(FALSE)->setValues($userJob)->execute()->first()['id'];
I feel like there is a case for a generic Copy
api - in the DAO
we have a function with a signature that I think is probably 'a bit much' - so it might make sense to migrate to a new function... & create a generic API
I checked what Entities implement Copy
and found a handful -the non static ones are not in the BAO - so we just have one non-std signature which is unused https://github.com/civicrm/civicrm-core/pull/25594
One option would be to add a parameter to the schema eg.
'is_not_clonable'
And then we could add that to fields like created_id
and they would not need to be in the params. We already have the title of the entity so can assume that should be prefixed with Copy Of
. The UserJob
would have to override to set some of the deeper values