I'm not sure how to properly submit a PR for a stored proc, so I will describe it here. The fix is simple.
Description of bug
The second select statement has a bug:
SELECT ExtensionUrlProviderID,
PortalID,
SettingName,
SettingValue
FROM dbo.ExtensionUrlProviderSetting
WHERE PortalID = PortalID
SHOULD BE:
SELECT ExtensionUrlProviderID,
PortalID,
SettingName,
SettingValue
FROM dbo.ExtensionUrlProviderSetting
WHERE PortalID = @PortalID
Note: the WHERE clause uses @portalid which is the incoming sproc parameter.
As-is, the code that loads the ExtensionUrlProvider Settings will override the correct value with whatever the last value for that SettingName is, regardless of portal, because the sproc loads all settings without regards for PortalId.