+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Upgrading Jobs Module

Upgrading Jobs Module

10 posts, 0 answered
  1. F
    F avatar
    34 posts
    Registered:
    15 Mar 2011
    18 Mar 2011
    Link to this post
    Hello,

    I put the Jobs module in a test website and it works perfectly.
    I understood that a DocumentLibrary is created at the Module's installation.

    I added several fields to the module : extra fields in the form resulting into extra fields in the library.
    When Jobs.dll is compiled, I just drop it in the /bin directory and do no further action.

    I get an error when i submit the form, because the extra fields I added aren't in the document library (so the Item.SetValue() on that field fails).
    To make things work, I need to :
    - Delete the library
    - uninstall the job
    - reinstall the job (that creates the library, with the fields I added)

    Is there a simpler way to do this? Maybe using the "Upgrade" method?
    If I'm correct, then, what triggers the "Upgrade" method? is it just dropping a DLL with a different version number?
    Could I get a sample on how to use the upgrade method and what actions triggers it?

    Thank you
    F.
  2. Craig
    Craig avatar
    9 posts
    Registered:
    22 Feb 2011
    23 Mar 2011
    Link to this post
    I don't have a solution, but I do have the same question.  Can the Upgrade method be used to make changes to a custom module?  If not, what kinds of operations are appropriate for the Upgrade method?

  3. George
    George avatar
    28 posts
    Registered:
    24 Sep 2012
    29 Mar 2011
    Link to this post
    Hi,

    The purpose of the Upgrade method is, let's say that you have some custom logic in Install. Later you release a new version of your module, and in the new version you add more custom logic. In this case, the Upgrade method should hold the new custom logic in order to introduce it to the module when upgrading. The Upgrade method is triggered right after the upgrade of the database scheme. In this method you can do anything you usually do in Install.

    Here is an example of how the Upgrade method can be used,

    /// <summary>
    /// Upgrades this module from the specified version.
    /// </summary>
    /// <param name="initializer">The Site Initializer. A helper class for installing Sitefinity modules.</param>
    /// <param name="upgradeFrom">The version this module us upgrading from.</param>
    public override void Upgrade(SiteInitializer initializer, Version upgradeFrom)
    {
        if (upgradeFrom.Build < 1100)
        {
            var suppress = initializer.PageManager.Provider.SuppressSecurityChecks;
            initializer.PageManager.Provider.SuppressSecurityChecks = true;
             
            var groupPage = initializer.PageManager.GetPageNode(ContentModule.ContentPageGroupId);
            if (groupPage != null)
            {
                groupPage.Title = Res.Get(ResourceClassId, "PageGroupNodeTitle");
                groupPage.UrlName = Res.Get(ResourceClassId, "PageGroupNodeTitle");
                groupPage.Description = Res.Get(ResourceClassId, "PageGroupNodeDescription");
            }
     
            var landingPage = initializer.PageManager.GetPageNode(ContentModule.HomePageId);
            if (landingPage != null)
            {
                landingPage.UrlName = Res.Get<PageResources>().ContentBlocksUrlName;
                landingPage.Page.HtmlTitle = Res.Get<PageResources>().ContentBlocksHtmlTitle;
                landingPage.Description = Res.Get<PageResources>().ContentBlocksDescription;
            }
     
            initializer.PageManager.Provider.SuppressSecurityChecks = suppress;
        }
    }

    Hope this helps.


    Kind regards,
    George
    the Telerik team
  4. F
    F avatar
    34 posts
    Registered:
    15 Mar 2011
    29 Mar 2011
    Link to this post
    Thank you for your help.

    With this new information, i think i know what to do.

    F.
  5. Mike L
    Mike L avatar
    5 posts
    Registered:
    22 Aug 2006
    12 Jan 2012
    Link to this post
    how does the Upgrade method gets called? at which stage.

    and what's the proper ways to update the fields, adding/removing fields (via OpenAccess dataprovider)

    thanks,
  6. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    13 Jan 2012
    Link to this post
    Hello,

    The upgrade method for your module is called on application start, every time, when the current version of the module is different than the one in the database.

    The actual unit which gets upgraded is not the module, but the data provider. Sitefinity keeps the current versions of all registered data providers for all modules in the DB. When you do an upgrade, you actually change the assemblies with new ones, which have a more recent version.

    When the application is initialized, Sitefinity goes through all data providers, and compares the version in the DB with the current assembly version. If they differ, and the provider belongs to a custom module, your upgrade method gets called.

    The upgrade method gets a System.Version argument. It contains information about the old version - major, minor and build number. Since you are the developer of the custom module, you know the current version already, so you have enough information to perform the needed changes to the persistent classes or database.

    Sometimes, you don't need to do anything, as OpenAccess takes care automatically. Adding a new property to the persistent class is such a case. Other times, you need to manually change the schema (i.e. when changing a property type). It all depends on the changes in your model between the two versions.

    Greetings,
    Slavo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  7. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    14 Jan 2012
    Link to this post
    Hi Slavo,

    While I can see this working if the module is in an assembly seperate from the web application, how does the "upgrade if the version number changes" work if the module is in the same assembly as the sitefinity web site?  I'm having problem with OpenAccess not updating mapping changes.  In my case the module is in the same project as the SF site.

    --Steve
  8. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    16 Jan 2012
    Link to this post
    Hi,

    You  SF site is also built into an assembly, unless you've opened it as a web site (and not a web application project). The assembly has its own version, but by default the version does not change. Maybe this is the reason OpenAccess does not update the mappings.

    You can control how the assembly version changes by editing the AssemblyInfo.cs file in your project (also available in the SF site web project). The default code looks like this:

    [assembly: AssemblyVersion("1.0.0.0")]

    You should instruct the compiler to automatically increment the build number by changing the above line to:
    [assembly: AssemblyVersion("1.0.*")]

    Now with each next build of your project, the assembly version will be different and OpenAccess will know it has to update the mappings for your module. All the best,
    Slavo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  9. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    16 Jan 2012
    Link to this post
    Hi Slavo,

    I get that, but the assembly vesion matches the release version numbering.  So what happens if I change the AssemblyVersion property to auto-increment?  Will it break how the SF Project Manager determines whether an upgrade is newer that my (auto-incremented) installed version?

    --Steve
  10. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    20 Jan 2012
    Link to this post
    Hi,

    It will not break anything. What the project manager does when you upgrade is replace the old Sitefinity DLLs with the new ones. It will not touch your assembly at all, only the Sitefinity assemblies. Moreover, the version of your module's assembly is not bound to the version of Sitefinity, they can have arbitrary versions, as long as the references can be resolved.

    What CAN happen is that your module's references to Sitefinity assemblies can break. This will only happen if you've included a reference to the specific version, which we don't recommend.

    Greetings,
    Slavo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

10 posts, 0 answered