ChrisTERiS Posted January 4, 2021 Share Posted January 4, 2021 Hello, I've a problem to update the module version even if the real code works (eg update tables, create table). Everything works fine except that the version number still says 1.0 // ######################## MODULE CONFIGURATION ######################## function my_mod_config() { $configarray = array( "name" => "My Module", "description" => "Description goes here....", "version" => "1.0", "author" => "ChrisTERiS", "language" => "english", "fields" => array( )); return $configarray; } // ########################## ACTIVATE MODULE ########################### function my_mod_activate() { // Code to create Tables. Works !!! } // ######################### DEACTIVATE MODULE ########################## function my_mod_deactivate() { // Code to remove Tables. Works !!! } // ########################### UPGRADE MODULE ########################## function my_mod_upgrade($vars) { $currentlyInstalledVersion = $vars['version']; if ($currentlyInstalledVersion < 1.3) { // Code to upgrade table to version 1.3. Works !!! } if ($currentlyInstalledVersion < 2.0) { // Code to upgrade table to version 2.0. Works !!! } return; } Any advice is highly appreciated. Have a Happy New Year, Chris 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted January 4, 2021 Share Posted January 4, 2021 (edited) Happy New Year. You need to change the version number in the `$configarray`. "version" => "1.0", Edited January 4, 2021 by pRieStaKos 1 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted January 4, 2021 Author Share Posted January 4, 2021 1 hour ago, pRieStaKos said: Happy New Year. You need to change the version number in the `$configarray`. "version" => "1.0", I did this, and it's true that it worked when upgrading an active installation. But the problem is that in a fresh installation, it executes only the part of code in function my_mod_upgrade and ignores the code of the main function my_mod_activate. Have tried it twice, I'll give one more try to see will acts the same. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted January 4, 2021 Share Posted January 4, 2021 (edited) I could be wrong (I'm not using standard module functions in my projects) but your my_mod_activate() function should be based on the latest version of your module. Let's say you released the following versions: 1.0.0 1.0.1 - You changed this: UPDATE sometable SET animal = 'Dog' 1.0.2 - You changed this: UPDATE sometable SET animal = 'Cat' In my_mod_upgrade() you have the following: function my_mod_upgrade($vars) { $currentlyInstalledVersion = $vars['version']; if ($currentlyInstalledVersion < 1.0.1) { // UPDATE sometable SET animal = 'Dog' } if ($currentlyInstalledVersion < 1.0.2) { // UPDATE sometable SET animal = 'Cat' } return; } my_mod_activate() need to be like this: function my_mod_activate() { // CREATE sometable (animal VARCHAR(30) NOT NULL) // INSERT INTO sometable (animal) VALUS ('Cat') } As you can the the activation uses "Cat" (the value of the latest version). That said, your my_mod_config() needs to go with version 1.0.3. In other words fresh installation do not trigger upgrade function. function my_mod_config() { $configarray = array( "name" => "My Module", "description" => "Description goes here....", "version" => "1.0.3", "author" => "ChrisTERiS", "language" => "english", "fields" => array( )); return $configarray; } Edit: please, ignore my versioning (the 1.0.0). I suspect that WHMCS supports only 1.0 format. Edited January 4, 2021 by Kian 1 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted January 4, 2021 Author Share Posted January 4, 2021 @Kian Interesting solution, thank you. I'll try it tomorrow morning as is very late now. For the moment I was able to solve (somehow) this issue, by setting version 2.0 in config and if ($currentlyInstalledVersion < 2.1) in upgrade function. With if ($currentlyInstalledVersion < 2.0) upgrade does not works. 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted January 5, 2021 Author Share Posted January 5, 2021 (edited) That's so weird. Even a version update with a query does not works. Eg the code below works as for the database table modifications, but the query to update tbladdonmodules does not works without to give any error. if ($currentlyInstalledVersion < 2.0) { // Articles mysqli_query($db,"ALTER TABLE `mod_legalterms_articles` ADD `language` VARCHAR(100) DEFAULT 'english' NOT NULL"); // Settings mysqli_query($db,"ALTER TABLE `mod_legalterms_settings` ADD `licensekey` VARCHAR(100) DEFAULT '' NOT NULL"); // Update Version try { Capsule::table('tbladdonmodules') ->where('module', '=', 'legalterms') ->where('setting', '=', 'version') ->update( [ 'value' => '2.0' ] ); } catch (\Exception $e) { echo "I couldn't update Version. {$e->getMessage()}"; } } Edited January 5, 2021 by WHMUp Typo 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted January 5, 2021 Author Share Posted January 5, 2021 Finally, the old good way, works fine. // Update Version mysqli_query($db,"UPDATE tbladdonmodules SET value='2.0' WHERE module='legalterms' AND setting='version'"); 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted January 6, 2021 Share Posted January 6, 2021 Double check your code. Dependency files, everything. Try running them through a debugger 1 by 1. 10:1, if the upgrade function isn't working, it's because something, somewhere , is broken inside code, and it can't work. I've seen this way, way too many times over the years 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.