HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Can't get addon upgrade code to work.

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#107768 (In Topic #21002)
Avatar

Community saint

Hey Chris, I have run into a couple of problems in the addon export/import process while fixing up the YouTube Channel Integration block addon. They're two separate issues so I will create two separate postings for them.

I don't know if I'm misunderstanding how the internals of the install/upgrade process works with the addon install function or if this is a bug in my code or ocPortal. Installing a clean install of the addon works as it should. With a clean install of the old version or clean install of the new version I get the correct config options added to the Setup>Configuration>Blocks config page added by the install function in my addon code when the addon is installed. If I install the old version and then upgrade to the new version by uploading the new block in the Import Non-bundled Addon(s) page, it installs the new block files, but the code to delete the previous config option and add two new options doesn't get run during this upgrade installation process. I have to access the block to get the two new options to show up in the Setup>Configuration>Blocks config page. For example, I had to load the block in the block assistant and click the Preview button to force the block code to run. That added the two new options to the Blocks config page, but failed to delete the old option. If I run ':delete_config_option('channel_update_time');' from OcCLE, it deletes the unused option that should have been deleted from the install function. This is the install code from the addon:

Code


    function install($upgrade_from=NULL,$upgrade_from_hack=NULL)
    {
        // New install
        if (is_null($upgrade_from)) {
            add_config_option('UPDATE_TIME','youtube_channel_block_update_time','integer','return \'60\';','BLOCKS','YOUTUBE_CHANNEL_INTEGRATION');
            add_config_option('YOUTUBE_CHANNEL_BLOCK_API_KEY','youtube_channel_block_api_key','line','return \'\';','BLOCKS','YOUTUBE_CHANNEL_INTEGRATION');
        }
 
// Upgrade from block version prior to version 10 - replace channel_update_time config option and also add a new api key config option.
        if ((!is_null($upgrade_from)) && ($upgrade_from < 10)) {
            add_config_option('UPDATE_TIME','youtube_channel_block_update_time','integer','return \'60\';','BLOCKS','YOUTUBE_CHANNEL_INTEGRATION');
            add_config_option('YOUTUBE_CHANNEL_BLOCK_API_KEY','youtube_channel_block_api_key','line','return \'\';','BLOCKS','YOUTUBE_CHANNEL_INTEGRATION');
            delete_config_option('channel_update_time');
        }
    }
 


I'm running ocPortal v9.0.19. In the new version of the addon I have incremented the $info['version'] variable from 9 to 10 and made sure the $info['update_require_upgrade'] variable is set to 1. So I'm stumped about why it isn't performing the upgrade to the added/deleted config options.
Back to the top
 
Posted
Item has a rating of 5 (Liked by Jason Verhagen)  
Rating:
#107788
Avatar

Hi Jason,

The v9 addon reimport doesn't handle upgrading, just it happens on-the-fly like you saw.

I recognise this is an issue, e.g. if new config options are added, people don't expect to go have to view a block before going to the config. A bigger issue is when options are coded up as installed/uninstalled by a block, but the main addon code is something else like a hook – that definitely would/will confuse people.

I just checked, and v10 is going to have upgrading as a part of the reimport process. We have done some major cleanup to how addons are handled for Composr.

I suggests for the time being you give some OcCLE workaround if you think necessary:

Code

:require_code('zones2'); upgrade_block('block_name');

As a side-note, I and many others have huge appreciate for what you've been doing :).

Best,
Chris


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#107790
Avatar

Community saint

I see, that makes sense. With some testing earlier I found that I could also trigger the block install code (via the upgrade_block() function) by going to the ocPortal Upgrader script and clicking the 'Do a database upgrade' button. I'll recommend the OcCLE command for those familiar with it and just uninstall/reinstall for those that aren't.

Chris Graham said

As a side-note, I and many others have huge appreciate for what you've been doing .

I'm glad to help out. It helps me out too...I'm not neck deep in ocPortal code everyday, so it keeps things fresh in my mind, gets me to knock things off of my own todo list, and motivates me to check out or learn features of ocPortal I haven't used yet. 
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: