function remove_attachment_connections($connection_types)
{
    // get attachments for type
    $results = get_connected_results($connection_types);
    // aggregate results
    $aggregated = aggregate_results($results);
    foreach ($aggregated as $post_id => $to_post) {
        // remove old connection
        delete_old_connections($connection_types, $post_id);
    }
}
function migrate_attachments_to_post_type($connection_types)
{
    // get attachments for type
    $results = get_connected_results($connection_types);
    // aggregate results
    $aggregated = aggregate_results($results);
    $query = get_query_for_post_ids(array_keys($aggregated));
    // iterate over attachments
    while ($query->have_posts()) {
        $query->the_post();
        $post = get_post();
        // create post
        echo "Processing {$post->post_title}\n";
        $new_post_id = create_new_post($post);
        // connect new post to relation type
        echo "Connecting {$post->post_title} to posts\n";
        connect_new_post_to_connected($new_post_id, $aggregated[$post->ID]);
        // copy over tags
        echo "Copying tags for {$post->post_title}\n";
        copy_tags_from_old_to_new($post->ID, $new_post_id);
    }
}