Deleting block by deleting code possible?

Vote:
 

Hello,

i have a requirement to remove an obsolete block which is not needed anymore. So i want to delete it and other related resources like controllers and views.

Is that possible at all and a good idea since it might still be used in CMS somewhere? Will it be removed there after rollout or will this cause problems?

If not, what is the best approach in this case? The minimum requirement is that this block can't be used anymore. 

Another block has properties that are now not needed anymore. For those is use following attribute?

[ScaffoldColumn(false)]

Or is it possible to remove those columns from code?

#216086
Edited, Jan 23, 2020 17:37
Vote:
 

If I recall correctly you can remove block related code (type definition, controllers, views, etc) even if you have instance of that block in database. Best would be to review its usage and remove those block instances as well. There are few plugins out there (for example, https://marketplace.episerver.com/apps/nansen/content-usage-finder/) that shows usage of the content types.

#216092
Jan 24, 2020 0:41
Vote:
 

Hi,

I think my understanding roughly tallies with Valdis' - If you remove the content type class from code, any content of that type will remain and the content type will still be available in Episerver (assuming it has been used at some point). Removing any of the code used to render that content type (i.e. views and controllers) may well result in an error if you visit a page which attempts to render that block. As Valdis suggests, to completely remove the block, you would need to delete any instances of that block type. Once there are no instances remaining, you can safely delete the related files though, to remove the content type from being available in the CMS, you may need to go in to admin in and manually delete it (the type will have a warning triangle icon against it and you'd need to click on the content type then settings to find the delete option).

The alternative is to take a similar approach to the one you have taken with the unwanted properties and simply hide the block type from the editors so it doesn't get used in the future. The easiest way to do this is to apply a security restriction to that content type which can never be met by adding an attribute to the content type like the following:

[Access(Roles = "NONE")]

Where "NONE" is a role which doesn't exist. This is a reversible process should you need that block type again but has the disadvantage that your codebase will still have the code related to the unwanted block in there.

To answer your second question - the process for removing properties is similar to the process I mentioned for removing a content type. You can remove the properties in your code but, assuming they've been used, the properties will remain on that type in the Episerver database. To fully remove them you'd need to go in to the CMS admin and remove the field manually once it's been removed in code. Again, the easiest way around this is to hide the fields using [ScaffoldColumn(false)] as it can be applied through code and is non-destructive but it results in the data in that field being retained and that field remaining in your code.

As a final note, if you want to fully remove the content types or properties but don't want to manually remove them through admin, you should be able to do that using the IContentTypeRepository which lets you interact with content types programmatically.

#216096
Jan 24, 2020 10:49
Vote:
 

Hi Tim,

Adding to what Paul said, instead of using Access atribute to block access to the content type - you can use the ContentType attribute:s property AvailableInEditMode and set that to false (so then no one can create the content type but naturally this applies only when the content type actually exists).

For example in the past if some content type is not needed anymore and the editors have removed the instances they knew about we have deployed the code that is missing the content type. Now if you go to admin view and go to manage the content types and you still see your removed content type you can click it and try to delete it - this will give you warning about instances of it if it is still used somewhere (for example instances in waste basket).

#216121
Jan 26, 2020 17:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.