//First find all of the old ModuleDockingNodeNamed modules (they won't have a controlTransformName key)
@PART[*]:HAS[@MODULE[ModuleDockingNode],@MODULE[ModuleDockingNodeNamed]:HAS[~controlTransformName[]]]
{
    //Change the module type on the old ModuleDockingNodeNamed module so it's out of the way but the data is saved for later restoration
    //Prior to this patch, there would only ever be one ModuleDockingNodeNamed in a part.
    @MODULE[ModuleDockingNodeNamed]:HAS[~controlTransformName[]]
    {
        @name = ModuleDockingNodeNamed_deprecated
    }
    
    //Now copy each ModuleDockingNode, then strip its contents, change its name to ModuleDockingNodeNamed, and give it default values
	+MODULE[ModuleDockingNode],*
	{
        //remove all keys
        -* = dummy
        
        //remove all EVENTS and ACTIONS nodes
        -EVENTS,* {}
        -ACTIONS,* {}
        
        //change the name key (hence 'type' of module)
        %name = ModuleDockingNodeNamed
		%controlTransformName = not_initialized
		%portName = default
		%initialized = false
	}
    
    //Go to the first of these new ModuleDockingNodeNamed modules, and restore in the data we saved earlier
    @MODULE[ModuleDockingNodeNamed],0
    {
        @portName = #$../MODULE[ModuleDockingNodeNamed_deprecated]/portName$
        @initialized = #$../MODULE[ModuleDockingNodeNamed_deprecated]/initialized$
    }
    
    //Finally, delete the deprecated module
    -MODULE[ModuleDockingNodeNamed_deprecated]
}

//Next, repeat this process for all new parts which don't already have a ModuleDockingNodeNamed (no need to save/restore anything this time)

//So find all parts that have a ModuleDockingNode with no ModuleDockingNodeNamed modules
@PART[*]:HAS[@MODULE[ModuleDockingNode],!MODULE[ModuleDockingNodeNamed]]
{
    //As before, copy each ModuleDockingNode, then strip its contents, change its name to ModuleDockingNodeNamed, and give it default values
	+MODULE[ModuleDockingNode],*
	{
        -* = dummy
        -EVENTS,* {}
        -ACTIONS,* {}
        %name = ModuleDockingNodeNamed
		%controlTransformName = not_initialized
		%portName = default
		%initialized = false
	}
}