Widget creation fails

Topics: Troubleshooting, Writing modules
Jan 29, 2012 at 6:02 PM

the module created runs fine in Orchard. It does not require a Model! ( It is a rotating Cube showing images based on jquery!)
Now, when I want to convert it to a Widget with below 'DataMigration.cs' It never shows up in the Widget list.
when I enabled the feature (in Orchard) the first time Orchard asked me to update feature  'ICube' - which obviously ran ok (at least no error msg)!
PS: According to other threads using 'UpdateFrom2 ... return 3;' did not help

? do I need some 'empty' Model to satisfy the system?
? what am I missing ?
Thanks for your time and hints
ed

using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace ICube {
    public class Migrations : DataMigrationImpl {

        
        public int Create() {
            return 1;
        }
               
        public int UpdateFrom1() {
            // Create a new widget content type with ICube
            ContentDefinitionManager.AlterTypeDefinition("ICubeWidget", cfg => cfg
                .WithPart("ICubePart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget"));

            return 2;
        }
    }
}
Jan 30, 2012 at 4:40 PM

I think you need .Creatable() on the type definition.

Jan 30, 2012 at 6:19 PM
randompete wrote:

I think you need .Creatable() on the type definition.

now I'm confused! Where would you apply .Creatable() ?

OR, cracy enough, did you mean .CreateTable() which probably would men to add a 'fake' DB definition in order to get the relevant code!

Thanks for clarifying this, ed

Coordinator
Jan 30, 2012 at 7:06 PM

Right after the WithSettings call.

Jan 31, 2012 at 8:33 AM

.. thank you for your help and my apologies to be such a pain ... but I'm learning

after applying .Creatable() nothing happened. So I disabled / enabled the ICube feature which gave me below error.
I get it on disable and on enable, BUT, my module still works! when in the enabled state!? (also, when checking in 'features' the state changes correctly!)
However, the target still is: building the ICube widget!
? what do I do to get rid of the error msg?
? is there any special procedure / sequence required to create the widget ?

ed 

[InvalidOperationException: Sequence contains more than one matching element]
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source, Func`2 predicate) +2715854
   Orchard.Environment.State.<>c__DisplayClass21.<Orchard.Environment.State.IShellStateManagerEventHandler.ApplyChanges>b__13(<>f__AnonymousTypec`2 entry) in
c:\Users\sebros\Desktop\1.3.10\src\Orchard\Environment\State\ShellStateCoordinator.cs:126
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +151
   System.Linq.<ConcatIterator>d__71`1.MoveNext() +207
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +325
   System.Linq.<ReverseIterator>d__a0`1.MoveNext() +93
   System.Linq.WhereEnumerableIterator`1.MoveNext() +87
   Orchard.Environment.State.ShellStateCoordinator.Orchard.Environment.State.IShellStateManagerEventHandler.ApplyChanges() in
c:\Users\sebros\Desktop\1.3.10\src\Orchard\Environment\State\ShellStateCoordinator.cs:158

Jan 31, 2012 at 1:21 PM

Can you show me your whole Migrations.cs now after the change you made?

Jan 31, 2012 at 2:23 PM
Edited Jan 31, 2012 at 3:09 PM
Below the code. 
? do I need to delete the module and start from scratch ?
THIS IS AN EDIT: I obviously have somewhere a mismatch with my Widgets! 

whenever I want to add a Widget; in the add Widget screen, below the Title box I have an ICube box!?!?
my conclusion: I need to delete everything re my ICube module and start from scratch. 
Is there anything I need to delete in the 'orchard system'?
thanks for your time, ed
using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace ICube {
    public class Migrations : DataMigrationImpl {

        public int Create() {


            return 1;
        }
        public int UpdateFrom1() {
            // Create a new widget content type with ICube
            ContentDefinitionManager.AlterTypeDefinition("ICubeWidget", cfg => cfg
                .WithPart("ICubePart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget")
                .Creatable());

            return 2;
        }
    }
}
Jan 31, 2012 at 5:31 PM

Ok, quick explanation of how Migrations work:

The first time you install a module, Orchard has no record of it. So it looks for a Create() migration and runs that, then whatever the return value is (here it's 1) it stores that alongside the feature record as "current version". This is migration version which is unrelated to your module version as in Module.txt.

At that point it checks for a method called UpdateFromX, where X is that current migration version. Since you have an UpdateFrom1() it'll run that; and then store 2 as the version number, because that's the number you returned.

So now Orchard is looking for an UpdateFrom2() method if you want to run a further migration and update it more. Changing the existing method won't make any difference because it's already been run.

Does all that make sense?

Jan 31, 2012 at 7:53 PM
Edited Feb 1, 2012 at 2:40 PM

yes it definitely makes sense and I was able to create the widget - sort of! I.e. when going to Widget-> add I see the ICube widget in the list; I can assign it to a certain Zone;
however, I only see the Title of the Widget but I do not see the rotating cube! (Again as a 'content' it works fine!)

Now one strange thing (which probably stems from a earlier (mis)-handling of this Widget: when going through the list od Widgets Each and Every Widget has a field called ICube. When I fill it it shows in the Zone!?

? how can I get rid of this field ?

Change as of Feb 1:  after I have some experience with orchard I decided to start from scratch and my ICube widget got generated (no extra fields in widgets i.e. all seems ok). However, when I use the ICube-widget the Cube is not shown. In the Edit Widget screen I see only fields: Zone , Layer Position, Title, Owner. How do I check whether the 'ICube' is really there?

thanks again for your patience, ed