begin tran
go
declare @UserId int; set @UserId = 1 -- CHANGE USERID IF REQUIRED.
declare @d datetime; set @d = getdate()
declare @ContentTypeID int; select @ContentTypeID = ContentTypeID from dbo.ContentTypes where ContentType = 'Tab'
if @@rowcount <> 1 begin raiserror('Failed to read ContentTypeId for "Tab".', 16, 1); rollback; return; end
-- Create the missing ContentItem rows.
insert dbo.ContentItems (Content, ContentTypeID, TabID, ModuleID, ContentKey, Indexed, CreatedByUserID, CreatedOnDate, LastModifiedByUserID, LastModifiedOnDate)
select
t.TabName as Content,
@ContentTypeID as ContentTypeID,
t.TabID,
-1 as ModuleID,
N'' as ContentKey,
0 as Indexed,
@UserId as CreatedByUserID,
@d as CreatedOnDate,
@UserId as LastModifiedByUserID,
@d as LastModifiedOnDate
from
dbo.Tabs t
where
t.PortalId is not null
and t.ContentItemId is null
if (@@error <> 0) begin rollback; return; end
-- Update the missing ContentItemIds.
update t set
ContentItemId = ci.ContentItemId,
CultureCode = p.DefaultLanguage,
LastModifiedByUserID = @UserId,
LastModifiedOnDate = @d
from
dbo.Tabs t
inner join dbo.ContentItems ci on ci.TabId = t.TabId
and ci.ContentTypeID = 1
inner join dbo.Portals p on p.PortalId = t.PortalId
where
t.PortalId is not null
and t.ContentItemId is null
if (@@error <> 0) begin rollback; return; end
commit
print ''
print 'Committed'
go