wotw Posted December 30, 2012 Share Posted December 30, 2012 Hey guys, I registered on another forum hot.... they never activated my account or help me so here it goes. I hope you guys are friendly I am basically trying to return an array with all the versions that the current software hasn't updated too. (I am making a software update script) I have built everything else including an API etc.. I have 12 years php knowlegde but this is bugging me and I have never come across this before. So I have an array: private $current_versions = array( '1.0.0', '1.0.1', '1.0.2', '1.1.0', '1.1.1', '1.1.2' ); This array is all of the versions for the software. I have two other variables: $current_version = '1.0.2'; $new_version = '1.1.2'; I am basically trying to get the difference. The current version the software is running is: 1.0.2 and the current actual version of the software is: 1.1.2. I need to return an array with just the versions the software is missing, so that I can run the update based on them versions only; in order. Thanks for your help and I will be taking part in this forum full time Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/ Share on other sites More sharing options...
Christian F. Posted December 30, 2012 Share Posted December 30, 2012 I'd do away with the array all together, and just build the upgrade script into a switch-case with fall-through. I assume you're using a version constant in the application, which is all you need to swtich on. Then you can simply just add another case (at the bottom) for each new version of the software you're releasing, and the switch statement will take care of all the necessary upgrades. No matter which version is running. Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402230 Share on other sites More sharing options...
wotw Posted December 30, 2012 Author Share Posted December 30, 2012 Can you do me a little sample? I am kind of lost at what you mean mate. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402234 Share on other sites More sharing options...
wotw Posted December 30, 2012 Author Share Posted December 30, 2012 Say for instance. I release version 3.0.4 But the user is still on version 1.0.2. It needs to update them all in order. Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402235 Share on other sites More sharing options...
Christian F. Posted December 30, 2012 Share Posted December 30, 2012 (edited) switch (VERSION_NUMBER) { case '1.0.2': // Upgrade from 1.0.2 to 1.1.0 case '1.1.0': // Upgrade from 1.1.0 to 2.0.0 case '2.0.0': // Upgrade from 2.0.0 to 2.0.1 case '3.0.4': // Upgrade from previous to current version. break; default: // Show error about unknown version. Quite simple, as you can see. Edited December 30, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402236 Share on other sites More sharing options...
wotw Posted December 30, 2012 Author Share Posted December 30, 2012 Christian, Thanks man. I never knew you could do it like that with a switch statement. I always thought it read everything at once doing switches like that. Thats awesome. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402237 Share on other sites More sharing options...
cpd Posted December 30, 2012 Share Posted December 30, 2012 (edited) Christian, Thanks man. I never knew you could do it like that with a switch statement. I always thought it read everything at once doing switches like that. Thats awesome. Thanks It doesn't do everything at once, the parser reads it line by line. When it finds a matching case it begins to execute the code thereafter until it reaches a break statement. A fall-through, as Christian mentioned, is when another case is found before a break is found and the code in this new case is then executed; you can have as many or as few as you like. Edited December 30, 2012 by CPD Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402248 Share on other sites More sharing options...
wotw Posted December 31, 2012 Author Share Posted December 31, 2012 But doing a software update this way is the very best way to do it? Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402266 Share on other sites More sharing options...
cpd Posted December 31, 2012 Share Posted December 31, 2012 Its a method of doing it. Best/worst methods are argued from person to person as opinion varies. Just remember there's usually many ways to carry out individual tasks all of which are just as good as the next. Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402315 Share on other sites More sharing options...
ignace Posted December 31, 2012 Share Posted December 31, 2012 (edited) Your update script should be several components. Create a backup (files and database). Put the website into maintenance mode (and make sure for proper headers for search engines) If your app supports CLI this could be done through it:$ php app/console admin:config:set --maintenance=true --user=upgrade --pass=upgradepass Query your update server for the updates (http://updates.server/upgrade?from=1.0.1). This would return a zip/tgz file with the changes. If you use a VCS then you could simply query for a diff between tag X (current) and Y (latest) or simply the master:HEAD Unpack Once you unpack this could contain a few things. The replacement files (duh!) A database upgrade script (ALTER/DROP TABLE ..) this is often forgotten when people develop software, they use a VCS yet they don't version their database. A cleanup script, whatever mess you made, clean it up! A test script that verifies all has gone well Optional, a PHP script that does extra steps, like creating a new cronjob, etc.. The update should be done in a transaction, meaning that all must pass or none. Make sure that when something fails everything is rolled back properly without breaking stuff! Edited December 31, 2012 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/272526-software-semantic-versioning/#findComment-1402330 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.