diff --git a/052-Automated-database-updates-in-Joomla-during-development-of-a-component.md b/052-Automated-database-updates-in-Joomla-during-development-of-a-component.md index b51d3f8..3b0e25b 100644 --- a/052-Automated-database-updates-in-Joomla-during-development-of-a-component.md +++ b/052-Automated-database-updates-in-Joomla-during-development-of-a-component.md @@ -1 +1,23 @@ -I would like to give you a explanation As well as demonstration [00:00:06](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m06s) Of how JCB deals with Joomla's Implementation when regards to creating of Database tables As well as updating them or even adding more Joomla's way of doing this through specific file convention Within your components file structure Package JCB is also been Designed to actually detect changes in your component development [00:00:37](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m37s) And create with files for you The best way to illustrate this is well just let's compile a component So we have sermon distributer here that's gonna compile that for us And then we'll go to the zip file Unzip it Have a look at it And see those files extracted here [00:01:04](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m04s) And inside of this we have an admin folder and inside admin ,a SQL folder And here is the first file of interest that's what Joomla uses to actually build a database upon the first install of the component Do take note that it runs this file only on a fresh install of the component Thereafter it will not run it again even if that's file gets updated Even if more values get added and usually it does JCB updates this file as you create new views which in Then it means a new table And if you add Fields which means a new column or field in the database And so [00:01:46](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m46s) This file update but it is for those Clients of yours that it couldn't install the component for the first time all those who already have the component installed This file will mean nothing to them All the files in this update folder Is what would actually be relevant If you have a client Which has version 1.3.2 installed on his system Any gets this package from you this 2.0.0 [00:02:14](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m14s) Package It will Actually Start with This file Then that one and so forth It will start with a File which is the same Version as the version that is currently installed on The Joomla website So [00:02:34](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m34s) That means JCB builds these files In that expected way Ok Now let's go make a change to the component and see how JCB updates these files Just gonna install the component So we have it in the database We can look at the database in the moment To see how things change Now I'm gonna open the admin views and I'm gonna add [00:03:07](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m07s) A field To the admin View called sermon Is it gonna be any generic field So that we can at least see it in action I'm gonna call it mobile telephone And Just put in the fourth position The left tab that's not really important but Ok so there we go We added a field [00:03:34](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m34s) Now you could it disappoint also add a new view and JCB will detect both of them And will add both of them to the update file But You could even do that You know Make this change run the compiler Have this new update Then make another change ,run the compiler and it'll follow along Incrementally Incrementing the the version [00:04:01](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m01s) Value of the component As you go Just for our sake Maybe let me add a view Already in another View And then you'll see how JCB combines to these values in one update So I'm going to grab a view that isn't already part of this component And just for illustration [00:04:26](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m26s) Save and close There we go we gotta view and it a new field If we compile the component now It will Do all those things that I've explained There you see it's incremented into 2.0.1 And if we go to the zip file again extracted open it up admin Sequel Updates [00:04:53](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m53s) we now see there is actually a new file. Let's open this file just Investigate a little So we see here's the Command to actually add that new field And here is another one To create That new table And all of that is been placed into this .... 2.0.0 [00:05:16](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m16s) File Which like I said is the current version Of this installed Component If we look at the database at this point You see there is no Look table And if we look at the Sermon table and structure Then we see that there is you know No [00:05:36](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m36s) Mobile field here Ok so that's install it now and see the change Ok it's been successful go back to the table Let's just refresh this I know you have it Got field added if we go back to the new table that it had to create Scroll down And there is the new table So it's done both of those as expected [00:06:09](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m09s) Secondly let me show you where it made some changes in JCB To relation to this component so you'll see that the component has automatically incremented it's version number If we open this component updates area You'll see that it has dynamically Stored that same values that we saw on the file here next to the correct version And it is actually created a new Version entry You have to manually update this URL As there are too many variations here we couldn't actually implement this dynamically [00:06:49](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m49s) this URL is what is being used in your updates server file If your component is set to have an update server file And so At this point You can now continue even adding another view or even another field and it'll just the same it'll increment it and it will update your database upon installation And really that is as simple as it is There are some places where that behaviour may not function as expected The only one I'm very much aware of is the one that happens when you Actually import [00:07:32](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m32s) Or Export a component from one JCB to another Those of you that have used this you can export a component and then Import it Again That effectively creates all the data in the relation to JCB but it does'nt Recreate the history and the asset IDs and everything else which is related to its Integration Within the Joomla Interface or Database So that means for example your There is no history [00:08:08](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m08s) Regarding the admin views And the only way to start any history for that View Would be to open it And to save and close it That's the only way Now that specific area will have a history track Same goes with the admin views You have to open them and save them This one not the admin view itself but the actual Fields of the admin view [00:08:36](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m36s) Open them save them again This will create its first entry and serve as a reference point To last time to the which those values were changed If you compile the component at that point it will actually Add two component ID to that specific entries And use it as a reference point like I've said Then having after having compiled it so you first saved them then compile the component And then only start making your changes So that you'll basically Bring the component into the motion of What would be the natural [00:09:16](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m16s) Flow of development This natural flow that you would Create a component add views then add Fields to it all along saving closing saving And that generates the history values that we actually need To detect changes If you import a component none of those values exist and so It won't behave as expected Well that's just a heads up I supposed many of you might not even have this issue but If you do You will know at least where to look and what to do to fix it [00:09:51](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m51s) Anyway that is a Quick overview of JCB's Implementation To correspond to Joomla's conventions In creating tables And updating them Dynamically Through The SQL Files In the updates folder And yes I hope that [00:10:16](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m16s) This is gonna be helpful to to those who may not have understood this before Thanks for watching +# AUTOMATED DATABASE UPDATES IN JOOMLA DURING DEVELOPMENT OF A COMPONENT + +### Demonstration - Creating, Updating And Adding Database Tables + +[00:00:00](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s) + +I would like to give you a explanation as well as demonstration of how JCB deals with Joomla's implementation when it regards to creating of Database tables, as well as updating them or even adding more. Joomla is a way of doing this through specific file convention within your components file structure package. JCB is also been designed to detect changes in your components development [00:00:37](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m37s) and create those files for you. The best way to illustrate this is let's compile a component. We have Sermon Distributor. Let's going to compile that for us. Then we'll go to the zip file, unzip it. Have a look at it, and see those files extracted here. [00:01:04](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m04s) Inside of this(com_sermondistributor) we have an admin folder and inside admin folder a sql folder. Here(installmysql.uft8.sql) is the first file of interest that's what Joomla uses to build a database upon the first install of the component. + +### Runs Only On Fresh Install - Thereafter It will Not Run Again + +[00:01:17](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m17s) + +Do take note that it runs this file only on a fresh install of the component, thereafter it will not run it again, even if that's file gets updated, even if more values get added and usually it does, JCB updates this file as you create new views which in then it means a new table, and if you add Fields which means a new column or field in the database. [00:0So1:46](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m46s) This file will update but it is for those clients of yours that is going to install the component for the first time. All those who already have the component installed, this file will mean nothing to them. All the files in this update folder is what would be relevant. If you have a client which has version 1.3.2 installed on his system, and he gets this package from you this 2.0.0 [00:02:14](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m14s) package, it will start with 1.3.2 file, then 1.3.3 and so forth. It will start with a file which is the same version as the version that is currently installed on the Joomla website. [00:02:34](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m34s) That means JCB builds these files in that expected way. + +### Making Changes - JCB Updates + +[00:02:44](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m44s) + +Now let's go make a change to the component and see how JCB updates these files. I'm going to install the component so we have it in the database. We can look at the database in the moment to see how things change. I'm going to open the Admin Views and I'm going to add [00:03:07](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m07s) a field to the Admin View called Sermon. It's going to be any generic field, so that we can at least see it in action. I'm going to call it Mobile Phone, and put in the fourth position, the left tab, that's not really important. We added a field. [00:03:34](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m34s) + +### Add A New View - JCB Combines These Values In One Update +???? +Now you could at this point also add a new view and JCB will detect both of them and will add both of them to the update file. You could even do that make this change, run the compiler, have this new update, then make another change, run the compiler, and it'll follow along incrementing the version [00:04:01](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m01s) value of the component as you go. Just for our sake, maybe let me add a view, already in another view and then you'll see how JCB combines these values in one update. I'm going to grab a view that isn't already part of this component and just for illustration. [00:04:26](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m26s) Save and close. There we go we have a view and a new field. If we compile the component now, it will do all those things that I've explained. There you see it's incremented into 2.0.1 and if we go to the zip file again, extracted, open it up, admin, sql, updates. [00:04:53](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m53s) We see there is a new file. Let's open this file, just investigate a little. We see here's the command to add that new field and here is another one to create that new table. All of that is been placed into this 2.0.0 [00:05:16](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m16s) file which like I said is the current version Of this installed Component If we look at the database at this point You see there is no Look table And if we look at the Sermon table and structure Then we see that there is you know No [00:05:36](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m36s) Mobile field here Ok so that's install it now and see the change Ok it's been successful go back to the table Let's just refresh this I know you have it Got field added if we go back to the new table that it had to create Scroll down And there is the new table So it's done both of those as expected [00:06:09](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m09s) Secondly let me show you where it made some changes in JCB To relation to this component so you'll see that the component has automatically incremented it's version number If we open this component updates area You'll see that it has dynamically Stored that same values that we saw on the file here next to the correct version And it is actually created a new Version entry You have to manually update this URL As there are too many variations here we couldn't actually implement this dynamically [00:06:49](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m49s) this URL is what is being used in your updates server file If your component is set to have an update server file And so At this point You can now continue even adding another view or even another field and it'll just the same it'll increment it and it will update your database upon installation And really that is as simple as it is There are some places where that behaviour may not function as expected The only one I'm very much aware of is the one that happens when you Actually import [00:07:32](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m32s) Or Export a component from one JCB to another Those of you that have used this you can export a component and then Import it Again That effectively creates all the data in the relation to JCB but it does'nt Recreate the history and the asset IDs and everything else which is related to its Integration Within the Joomla Interface or Database So that means for example your There is no history [00:08:08](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m08s) Regarding the admin views And the only way to start any history for that View Would be to open it And to save and close it That's the only way Now that specific area will have a history track Same goes with the admin views You have to open them and save them This one not the admin view itself but the actual Fields of the admin view [00:08:36](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m36s) Open them save them again This will create its first entry and serve as a reference point To last time to the which those values were changed If you compile the component at that point it will actually Add two component ID to that specific entries And use it as a reference point like I've said Then having after having compiled it so you first saved them then compile the component And then only start making your changes So that you'll basically Bring the component into the motion of What would be the natural [00:09:16](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m16s) Flow of development This natural flow that you would Create a component add views then add Fields to it all along saving closing saving And that generates the history values that we actually need To detect changes If you import a component none of those values exist and so It won't behave as expected Well that's just a heads up I supposed many of you might not even have this issue but If you do You will know at least where to look and what to do to fix it [00:09:51](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m51s) Anyway that is a Quick overview of JCB's Implementation To correspond to Joomla's conventions In creating tables And updating them Dynamically Through The SQL Files In the updates folder And yes I hope that [00:10:16](https://www.youtube.com/watch?v=zN2M15fzf_M&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m16s) This is gonna be helpful to to those who may not have understood this before Thanks for watching