Occasionally, we end up with a single contact that has two membership records (e.g., an old expired one and a newer current one). I would like to programmatically merge the two memberships cleanly, so that, for example, the remaining membership gets the oldest start date, the current membership type, all contributions are retained, etc. Have browsed Dedupe.php looking for a call that might do this, but to no avail. Any suggestions?
Currently there's no support for what you're describing built in to CiviCRM. You could implement this with API calls in an extension. If you do, please consider submitting it to the extensions directory!
I’ve started to work on a patch for CiviCRM (as it’s not that simple to implement this as an extension). The work-in-progress PR is available here. Comments and feedbacks are welcome ;)