Php Application Updater Theory

I have to add auto updation in one of the php Application that I have made (FamilyTree). So I started thinking as in how I can implement this. I have seen this thing in lots of applications such as WordPress itself. Wonder how they do it. Anyway, hear whay I have to say.

I use git as Version Control so I basically deal with commits. Whenever there is a release marked in git. It is basically after a commit. A certain commit is marked as the final commit of some version which solves the final issue of that version or implements the final feature of that version.

Let’s say I had earlier released 0.1 of my software. Now I am releasing version 0.2 of my software. To know the changes that you have made from one commit to another, you will have to read all the commit reasons that you have mentioned when you added that commit given that you have explained each of your commits properly.

Now we had php application, now we don’t have to compile, we just have to replace the files. That would be easy I suppose. All we have to do is to find out the files which were changed from 0.1 commit point to 0.2 commit point. I found out a git command which can do this for me.

git diff --name-only HEAD~10..HEAD yourdir

This command right now show the files that were changed in the last 10 commits. We want to know from one commit point to another. So just replace them with the commit SHA of your two commit points and voila!!. yourdir is just a directory. If you are running this command inside repository. Then you don’t need that.

Now we have all the files which were changed from 0.1 version to 0.2. Our Updater should just replace all of these files and we are good to go.

But wait a min! What if we have database and we have made changes in the database to. How will we manage then?

Now one more feature has been added to our application that if database has changes such as we have added more columns in one of the tables. Then insert sql scripts which migrates the database to the new schema and make certain changes in the database. Now after this, you application is using latest code and is on latest database schema.

Here is all of the above theories practical. There can be a script which after running collects all the files mentioned by the above git command and puts in zip file. Now modify that zip file and add sql files which will modify the database accordingly.

Cons of this Theory:  This way is incremental way as it is relative to the previous version. For example, A user is using 0.1 version and latest version of the software is 0.3. Then first he would have to update to 0.2 and then go to 0.3 which can take some time to happen.

Right now I only have this theory in mind. I haven’t yet implemented. I will let you know on this same blog about the challenges that I faced while implementing the same.

Till then sayonara!

Leave a comment