Vulnerability in EPiServer.Forms
Hello all :)I have 2 class of different types. Article and ArticleNew inheriting from VariationContent
The scenario is that i have all my variants using only one of the classes which i Article
What i would like is to change some of the types that are Article to be ArticleNew.
var newProduct = new ArticleNew();
newProduct.InjectFrom(currentArticle); //using Omu.ValueInjecter;
var contentRepository = ServiceLocator.Current.GetInstance();
contentRepository.Save(newProduct, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
// TODO delete the old one Article
The above is just a thought how it maybe should be done..
I would like to keep the references to the porduct and so on..
How would you choose which Article(s) to be converted to ArticleNew(s)?
Depending on values in some of the properties. lets say if currentArticle.IsImportant then do the conversion..
I asked about the criteria because I initially think the best way might be to use some SQL, but there should be better way.
You might add a new constructor on ArticleNew, which take an Article and convert/copy the properties. Then iterate over Articles and do the conversion, and save as your code.
THe ContentReference properties would be kept in new content. But the history will not (and I assume you don't have to?)
Ok, so i guess thats basically what i was thinking, would it be ok to use automapper or valueinjector to do the mapping and copy the values?
And when saving the new ArticleNew object, should i use something like this?var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();contentRepository.Save(newProduct, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
i tried the above and don't get any errors but nothing gets stored/published.. think i might have missed something?
Sounds like you want to keep the id (ContentReference) of the Article to the ArticleNew?
Then it's a bit tricker. Are Article properties and ArticleNew properties the same? Do you care about versions?
Properties will be the same in the beginning, but will change when the conversions are done. and we don't care about the versions at this point.
I would like to keep all the values, linking to the product and where it is located in the structure, do i need to keep the same id to be able doing that?
Link from your Article to the product (for example, ContentReference property on Article point to a product) will work regardless of Id, but link from a product to an Article (ContentReference property on Article point to product) will require ContentGuid to be the kept.
I see some approaches to your requirement:
- Keep using the approach, but copy the properties (Name, Code) and Property of Article to ArticleNew first, (especially ContentGuid), delete the Article then save the new ArticleNew.
- The second approach is a bit tricker. You can change the entries you want to change to ArticleNew to have metaclass Id = metaClass Id new, then use CatalogContentDraftStore to delete all drafts of those entries. Well, we don't officially recommend to manipulate the database directly, so consider this as my personal advice.
- Check the MetaClass table, note the metaclass Id of Article and ArticleNew
- Get all entry ids to change, for example: Select ObjectId from dbo.CatalogEntryEx_Article where Important = 1
- Update entry with ids in previous step in CatalogEntry table to new MetaClassId: Update dbo.CatalogEntry set metaClassId = <ArticleNew id> where catalogEntryId in (Select ObjectId from dbo.CatalogEntryEx_Article where Important = 1)
- restart site, and use CatalogContentDraftStore to delete all versions of Article contenttype.
Above is pseudo code, but you get the idea. Remember to backup your database first :)