This project is read-only.

How do I rollback module creation / upgrade and show a custom notification error.

Topics: Administration, Core, Troubleshooting
Oct 22, 2013 at 5:19 PM

I have a module that creates test orders. In order for test orders to be created products must first be loaded into our implementation of Orchard.

I've tried adding lines of code such as the following if products were not found:

_orchardServices.Notifier.Error(T("Products must be created before running the order test data generator"));

However, I cannot get the notification popup to appear. What am I doing wrong.

In addition how do I rollback the creation of the module or an upgrade of a module for my Migration.cs file?


Oct 22, 2013 at 5:27 PM
Forgot to mention,

I've tried returning 0 and throwing an exception in my Create() method of Migration and in both cases these notifications will show up.

Some features need to be upgraded: Conductor.OrderTestDataGenerator
Order Test Data Generator was enabled

But the custom one I added from above will not.
Oct 22, 2013 at 7:55 PM
Artificially failing the migrations is not a good idea. Why don't you run your test data generator from a controller action (after e.g. the user clicks a button) and why do you try to do it in a migration?
Oct 22, 2013 at 8:21 PM
I've also tried running it from the "Enabling" method of a class that implements the IFeatureEventHandler interface. This also seems to fail as any notifications I add are not displayed.

I found a way to get this to work by implementing the INotificationProvider interface from a class. However, now I need to add my check in two spots. One in the INotificationProvider custom class and another in the IFeatureEventHandler / Migration custom class.
Oct 22, 2013 at 8:26 PM
Again: why specifically do you want to do this when a feature is enabled, what is in every way more complicated than doing it when a user explicitly wants to generate test data? Also, users may not want test data when just enabling the feature (remember, a feature can be enabled, then disabled and finally enabled again).
Oct 22, 2013 at 8:31 PM
Well we did it this way because at the time it seemed the easiest way for us to enable test data. Just enable the separate module. Else we would have to build a page where the user can click to enable the test data. Plus you could click it multiple times when we really only need to create the test data once.