November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Find the correct content:
1. EPiServer Find if you have it.
2. FindPageByCriteria and search by page type
3. ContentModelUsage. Useful in some cases when you know the content type.
4. GetChildren recursive like you are doing.
Change content:
Might be enough to only change the published ones? The you can add a new validation on the properties for the rest...
Use the filter below EPiServer.Filters for published state if you go for that and then implement IValidate to ensure editors fix the rest / change automatically on publishing event.
Hi,
Yes you can use the ForceCurrentVersion flag. E.g.:
contentRepository.Save(theWriteableClone, SaveAction.Publish | SaveAction.ForceCurrentVersion);
And for your second question, your approach should work fine. There is not really any better solution. It depends on if you really want to update all content, or just a specific content type? Then there are better solutions.
Edit: You also need to check whether the content was published, if not you need to use SaveAction.Save | SaveAction.ForceCurrentVersion. You always need to specify an "save action", but then you can combine that with e.g. ForceCurrentVersion.
Essentially I trying to write a job that scans for external links in all pages and blocks.
There seem to be more helpers for checking publish state on pages than blocks which seems to complicate things a little.
BlockData doesn't implement all interfaces as PageData, but most are mixed in during runtime. So you can cast a block to IVersionable and then check publish status.
Thanks.
Here's what I'm toying with currently for saving. I'm running through and testing but am expecting issues. I'm sure I saw something that said SaveAction.ForceCurrentVersion | SaveAction.Save isn't valid under version 8 for example.
var version = clone as IVersionable; if (version != null) { switch (version.Status) { case VersionStatus.CheckedIn: _contentRepository.Save(clone as IContent, SaveAction.ForceCurrentVersion | SaveAction.CheckIn); break; case VersionStatus.DelayedPublish: _contentRepository.Save(clone as IContent, SaveAction.ForceCurrentVersion | SaveAction.DelayedPublish); break; case VersionStatus.Published: _contentRepository.Save(clone as IContent, SaveAction.ForceCurrentVersion | SaveAction.Publish); break; case VersionStatus.Rejected: _contentRepository.Save(clone as IContent, SaveAction.ForceCurrentVersion | SaveAction.Reject); break; case VersionStatus.AwaitingApproval: case VersionStatus.CheckedOut: case VersionStatus.NotCreated: default: _contentRepository.Save(clone as IContent, SaveAction.ForceCurrentVersion | SaveAction.Save); break; } } else { _contentRepository.Save(clone as IContent, SaveAction.ForceCurrentVersion | SaveAction.Publish); }
Still feel a bt nervous though. Feels like there needs to be a save action that will just update the version without changing version status.
I'm trying to write a schedule job that scans through all content (pages and blocks) and updates certain properties.
I'm creating a writeable clone but I'm wondering is there an easy way to save the content without creating a new version or changing the publish state. Essentially the change should just update all the current versions without changing state.
Also worth checking - at the moment I'm using IContentRepository to try loop through and get all the content in the site by getting children of each node. It doesn't feel a particularly fantastic approach so could I do this better?
I'm using CMS 9.7.2.