1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

AddOn Updates

Discussion in 'XenForo Development Discussions' started by Uniphix, Sep 11, 2013.

  1. Uniphix

    Uniphix Active Member

    When updating an addon already installed, lets say I have some listeners that are called such as initDependencies... One of the issues I'm having is when I need to rebuild data and the 'table' has not yet been created, or something of this sort or a table column is missing etc.

    SO in this case I have to manually add a table to the database directly which in my opinion is a pain if I have to tell all my customers to update their database with the new changes. What I would like to know is there a way to check the addon's version and see if the version is installed before proceeding the typical rebuilding of data which requires a table that has not yet been made due to needing ot update the addon first before that data could be rebuilt correctly...

    For example:

    Installed Addon already there and a new table that requires data to be used across the site so I store this in the data registry. Now the problem the table that has not yet been made is on a new update

    So install version is version 1 update version is version 2...

    Current Version is 1 therefore is there a way to check against the addon such as

    if( $currentVersion > 1 ) then perform the typical duties of rebuilding the data otherwise ignore if I need to do an update on the addon first...

    Thanks
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    The add on install callback executes before cache rebuilds. There's never a reason to create tables manually.

    Just have your installer create the tables.
     
  3. Uniphix

    Uniphix Active Member

    Not cache rebuilds :)...

    Here is an example:

    PHP:
    if (!array_key_exists('socialProviders'$data) || !is_array($data['socialProviders']))
            {
                
    $data['socialProviders'] = XenForo_Model::create('MyAddon_Model_SocialProvider')->rebuildSocialProviderCache();
            }
           
    MyAddon_SocialProviderHandler::setProviders($data['socialProviders']);

    Problem is that this is part of an update of an existing addon that I am making, and the issue is that social_provider table does NOT exist yet therefore when it calls the table it says that the table does not exist yet... I need to be able to do something like

    if( current version of addon is equal to or less than VERSION_NUMBER ) then attempt the rebuilt of cache to the data registry and attach it etc...
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    I have no idea what you're trying to do.

    Usually tables and columns are added when an add on is installed or upgraded via the Install callback you can define in the add on options in the admin CP
     
  5. Uniphix

    Uniphix Active Member

    This is what I am trying to say...

    Initial Install... Yes...
    Update AddOn for installing IE your adding new "Features"

    Suppose this new feature requires some data caching within the data registry, therefore that method I did above would fail because it would say something like this...

    Zend_Db_Statement_Mysqli_Exception: Mysqli prepare error: Table 'db.social_provider' doesn't exist - library/Zend/Db/Statement/Mysqli.php:77
    Generated By: Unknown Account, 56 minutes ago

    therefore when trying to rebuild the data it fails because the 'table' has not been created... Therefore I have NO way to update the addon via admin.php because of course something could also be used in the admin... In this case I may need to access this "data registry" item that is created and stored at the time of Listener calling init_dependencies.

    Therefore for me to bypass that ERROR I would have to manually create that table because I cannot do an "AddOn" Update... For installing for the first time this problem wouldn't occur because those "Listeners" may not be added already for that specific AddOn until I add that new AddOn. But for existing addon to update.

    The only way to really bypass that error is to turn off code event listeners. Now that I think about it...
     
  6. tyteen4a03

    tyteen4a03 Well-Known Member

    Check your own addon's version? Just use the versionId param passed by XenForo.

    Check other addon's version? Just use the addon model.

    Otherwise, I am confused too.
     
  7. Mike

    Mike XenForo Developer Staff Member

    The issue is that he has an event on init_dependencies to build caches. The new code is uploaded before the upgrade is run, so it tries to build a cache for an table that doesn't exist yet.

    It can be worked around by checking the add-on version in the "addOns" cache.
     
    tyteen4a03 likes this.
  8. Uniphix

    Uniphix Active Member

    Mike I'm glad you understand where I am coming from! I am going to assume that the 'addOns' is part of the new updated 1.2 version? In this case that will be good, although the issue is we are not using 1.2 yet as our addon we have is just as big as XenForo itself so we have a lot of 'updating' to do
     
  9. Dan

    Dan Well-Known Member

  10. Chris D

    Chris D XenForo Developer Staff Member

    One very simple solution:

    Disable the add-on first, upload the files, run the upgrade, enable the add-on.

    I do get where you're coming from, though, and giving people any instructions, no matter how simple, sometimes falls on deaf ears. But it really is a very simple solution to the problem.

    One thing you can do in your initDependencies listener is only execute it where it's needed. I am only wildly assuming that the initDependencies stuff only needs to execute in public areas, so one partial solution is:

    PHP:
    if ($dependencies instanceof XenForo_Dependencies_Public)
    {
        
    // Your code
    }
    Wrap your existing code in that, and it will only execute on the front end.

    So, the worst case scenario is someone ignores your instruction to disable the add-on first. If that happens, they will get errors on the front end but the admin CP will be completely unaffected, allowing them to proceed with the add-on upgrade (which will create the table).

    So any issues would be short-lived. Still not ideal, of course.

    It seems @Uniphix wants a solution compatible with 1.1.x. This isn't, unfortunately. Aside from that it's a good solution.
     
    Sim likes this.
  11. Uniphix

    Uniphix Active Member

    That is well understandable. The issue is both the front end and back end uses that table for caching purposes. The best way to do this would just to disable listeners while updating...

    For XF 1.2 it'll be eaiser to control this by doing a version check
     

Share This Page