Archive
Monthly
Go
|
|
DNN Blog
Dec
14
Posted by:
Peter Donker
12/14/2009
Because the PortalName has been moved out of the Portals table it is no longer accessible. I worked around this with the following SPROC to get my own portalinfo:
CREATE PROCEDURE {databaseOwner}{objectQualifier}MyGetPortal
@PortalId INT,
@Locale NVARCHAR(6)
AS
DECLARE @DNNVersion INT
SET @DNNVersion = (SELECT MAX(v) FROM
(SELECT Major * 10000 + Minor * 100 + Build AS v FROM {databaseOwner}{objectQualifier}Version) AS x)
IF @DNNVersion > 50200
BEGIN
IF EXISTS(SELECT * FROM {databaseOwner}{objectQualifier}PortalLocalization WHERE PortalId=@PortalId AND CultureCode=@Locale)
SELECT * FROM {databaseOwner}{objectQualifier}Portals p
INNER JOIN {databaseOwner}{objectQualifier}PortalLocalization pl ON p.PortalId=pl.PortalId
WHERE p.PortalId=@PortalId
AND pl.CultureCode=@Locale
ELSE
SELECT * FROM {databaseOwner}{objectQualifier}Portals p
INNER JOIN {databaseOwner}{objectQualifier}PortalLocalization pl ON p.PortalId=pl.PortalId
WHERE p.PortalId=@PortalId
AND pl.CultureCode=p.DefaultLanguage
END
ELSE
BEGIN
SELECT * FROM {databaseOwner}{objectQualifier}Portals
WHERE PortalId=@PortalId
END
GO
One could add a default for the @Locale even … but I didn’t need it myself. I tested this on a 5.1.4 and it worked without throwing an error.
|
EDIT: Just goes to show one cannot know enough of the framework. Cathal was nice enough to point out that I missed vw_Portals. Just goes to show that one should always check the views that are available in SQL as well. So discard the above in favor of:
CREATE PROCEDURE {databaseOwner}{objectQualifier}MyGetPortal
@PortalId INT
AS
SELECT * FROM {databaseOwner}{objectQualifier}vw_Portals p
WHERE p.PortalId=@PortalId
GO
Quite a bit shorter, eh? Mind you, the locale is lost in this. So if you really need a localized PortalInfo with backward compatibility you’d probably still want the one above.
|
2 comment(s) so far...
Re: Getting a PortalInfo for both DNN 5.2+ and old versions of DNN
Won't that fail during the module install if the table does not exist? Or is it smart enough to catch the fact that the table is in a IF EXISTS statement and won't validate the table name?
By jsheely on
12/14/2009
|
Re: Getting a PortalInfo for both DNN 5.2+ and old versions of DNN
In my tests it was smart enough. Note I'm on SQL 2005. Can't speak for SQL 2000. But then ... who still uses that?
By Peter Donker on
12/14/2009
|
|