We have an existing PropertyType called IsPublic which uses a Umbraco.TrueFalse property editor.
Requirements have changed and this value now needs to be represented by multiple checkboxes that are driven from an Enum with the Values Public, Group1, Group2.
This all works as expected but with 10's of Thousands of documents we want to save our content editors from manually populating them all.
Saving a document in Umbraco, I can see that it creates an entry in the table cmsPropertyData with the value [ "Public", "Group1", "Group2" ] in the dataNvarchar column.
I've written a script to insert a row into this table based on the value of the original IsPublic flag.
However following running this, when opening a document in Umbraco the changes aren't displayed.
The script used to update is
DECLARE @HasPublicFlag NVARCHAR(50) = '[ "Public", "Group1", "Group2" ]'
DECLARE @NoPublicFlag NVARCHAR(50) = '[ "Group1", "Group2" ]'
DECLARE @feature INT = (SELECT nodeId FROM cmsContentType WHERE Alias = 'Feature')
--Existing IsPublic flag
DECLARE @featureIsPublic INT = (SELECT id FROM cmsPropertyType WHERE Alias = 'IsPublic' AND contentTypeId = @feature)
--New PropertyType
DECLARE @featureRoleRestriction INT = (SELECT id FROM cmsPropertyType WHERE Alias = 'documentRoleRestriction' AND contentTypeId = @page)
--Get feature document versions that are either newest version or published
;WITH FeatureDocumentsToUpdate AS
(
SELECT d.*, pd.dataInt
FROM cmsDocument d
JOIN cmsPropertyData pd ON pd.versionId = d.versionId
LEFT JOIN cmsPropertyData pd2 ON pd2.versionId = d.versionId AND pd2.propertytypeid = @featureRoleRestriction
WHERE (d.newest = 1 OR d.Published = 1) AND pd.propertytypeid = @featureIsPublic AND pd2.id IS NULL
)
--INSERT INTO cmsPropertyData based on value of existing flag
INSERT INTO cmsPropertyData(contentNodeId, versionId, propertytypeid, dataNvarchar)
SELECT s.nodeId, versionId, @featureRoleRestriction,
CASE WHEN s.dataInt = 0 THEN @NoPublicFlag ELSE @HasPublicFlag END AS NewValue
FROM FeatureDocumentsToUpdate s
Is there another table(s) that will need updating or is there a better way to do this?
Have you considered using a script that updates the documents via the ContentService rather than hitting the database directly. It might be the case that you are missing some updates that tell Umbraco that things have changed, such as updating version numbers etc.
Migrate existing PropertyData to new PropertyType
We have an existing
PropertyType
calledIsPublic
which uses aUmbraco.TrueFalse
property editor.Requirements have changed and this value now needs to be represented by multiple checkboxes that are driven from an Enum with the Values
Public
,Group1
,Group2
.This all works as expected but with 10's of Thousands of documents we want to save our content editors from manually populating them all.
Saving a document in Umbraco, I can see that it creates an entry in the table
cmsPropertyData
with the value[ "Public", "Group1", "Group2" ]
in thedataNvarchar
column.I've written a script to insert a row into this table based on the value of the original
IsPublic
flag.However following running this, when opening a document in Umbraco the changes aren't displayed.
The script used to update is
Is there another table(s) that will need updating or is there a better way to do this?
Hi Tom,
Have you considered using a script that updates the documents via the ContentService rather than hitting the database directly. It might be the case that you are missing some updates that tell Umbraco that things have changed, such as updating version numbers etc.
Thanks
Nik
Thanks Nik, for deployment reasons I was hoping to be able to perform this in a SQL script but I will investigate using the API as a backup.
It seems that what I was doing is working.
The content does become visible after performing some of the following steps:
However I don't seem to be able to reliably reproduce it.
is working on a reply...