Reply New Topic
14/9/2024 16:24:45
#1
Offline
Home away from home

Automatic database upgrade for non-module objects?

I am working on migrating some modules and started with downloads. I discovered my site did not have icms_data_file and icms_data_urllink tables in the database because we never added them to the upgrade scripts when we added them to the installer (in version 1.3.0). The Downloads uses those tables and I'm working on adding them to the database and addressing this for anyone else who might be in the same situation.

If these were module tables, there is an automatic upgrade method that looks at the object and its variables and determines the name and structure for the tables and adds or applies any necessary changes. At this point, I haven't found similar methods for these objects - and there are quite a few. Avatars, comments, notifications, files, URLs, images and image categories, users, groups, group permissions, private messages, autotasks, blocks, ranks, templates, and probably a few more - I haven't gone through them all. They all seemed primed and ready for this approach - am I missing something?


_________________
Christian Web Resources
Facebook

15/9/2024 4:06:23
#2
Offline
Webmaster

Re: Automatic database upgrade for non-module objects?

The system module is a strange animal On the one side, it contains functionality that should be part of the IPF classes, on the other, it looks like a mini-core,with submodules that are similar to full-fledged modules, but not quite.

I discussed some time ago with Mekdrop that we should be downsizing the system module and spinning out some of those functionalities into separate modules (like comments, ratings, ...). That would solve some of those issues, but that's not for right away though.


_________________

Me on OpenHub


15/9/2024 11:06:07
#3
Offline
Home away from home

Re: Automatic database upgrade for non-module objects?

It would be a major undertaking to rework this and I was hoping there was something to leverage that I wasn't seeing. In order to get this done and the keep this release moving forward, there's a couple of ways to proceed.

1. Do what's been done in other releases and include the table structure manually in the upgrade script (see modules/system/include/update-13.php)

2. Replicate the icms_db_legacy_updater_Handler::upgradeObjectItem() method and modify the new method (or just embed it in the upgrade script) to not rely on the object being part of a module

3. Find a way to modify the icms_db_legacy_updater_Handler::upgradeObjectItem() method to allow for other objects like these in different locations (the library folder), or at least for these 2 objects and their tables.

If we can get it done and take a small step in the right direction to deal with all the other components, that would be ideal.


_________________
Christian Web Resources
Facebook

15/9/2024 14:56:58
#4
Offline
Home away from home

Re: Automatic database upgrade for non-module objects?

Well, some experimenting has gotten me the results I was looking for - with a pretty small change to icms_db_legacy_updater_Handler::upgradeObjectItem(). Here's how the first lines look -

  function upgradeObjectItem($dirname, $item) {
        $module_handler = icms_getModuleHandler($item, $dirname, null, true); // this is changed

        if (!$module_handler) { // added this branch
                $module_handler = icms::handler($dirname . '_' . $item);
        }
        if (!$module_handler) {
                return false;
        }

Then, in the system module's upgrade file I added at the end

    if (!$abortUpdate) $newDbVersion = 45;
    
    if ($dbVersion < $newDbVersion) {
        $icmsDatabaseUpdater->automaticUpgrade('icms_data', array('file', 'urllink'));
        /* Finish up this portion of the db update */
        if (!$abortUpdate) {
            $icmsDatabaseUpdater->updateModuleDBVersion($newDbVersion, 'system');
            echo sprintf(_DATABASEUPDATER_UPDATE_OK, icms_conv_nr2local($newDbVersion)) . '<br />';
        }
    }        

After upgrading the system module, I had the 2 tables I needed. Updates of other IPF modules still work.

Any unexpected risks? Another few sets of eyes on this would be fantastic!


_________________
Christian Web Resources
Facebook

15/9/2024 21:17:35
#5
Offline
Webmaster

Re: Automatic database upgrade for non-module objects?

this looks like a very elegant and minimalistic change, kudos for that!

Taking the module upgrade route would also have been my choice.


_________________

Me on OpenHub


17/9/2024 7:26:42
#6
Offline
Home away from home

Re: Automatic database upgrade for non-module objects?

I had a good solid foundation for the solution - thanks to all the work others had done before me. I would like to test a few other things and then I'll create a pull request to add this in. What do you think about making this a default action of the system module update, rather than just a step?


_________________
Christian Web Resources
Facebook

18/9/2024 3:01:05
#7
Offline
Webmaster

Re: Automatic database upgrade for non-module objects?

If it is feasable to make this automatic, it would be best.


_________________

Me on OpenHub


19/10/2024 11:06:48
#8
Offline
Home away from home

Re: Automatic database upgrade for non-module objects?

After looking at this a bit more, I have submitted changes that will look at these 2 tables every time the system module is updated. It might be good to do the same in 1.4.7.


_________________
Christian Web Resources
Facebook

Reply New Topic extras
 Previous Topic   Next Topic
You can view topic.
You can start a new topic.
You can reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You can post without approval.