Updated 033 Export Import of fully mapped components (markdown)

Amigo 2019-07-17 08:40:28 +02:00
parent e27ef0483a
commit ec5a508b79

@ -2,27 +2,43 @@
### Various Linked Concepts to A component is Exported
We're happy to announce a new feature that's been added to the advanced component builder for Joomla. [00:00:10](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m10s) This feature is a feature I suppose can become very useful in the future of JCB. It allows you to export a component out of JCB, and not only the component's information, but everything attached to it. [00:00:34](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m34s) If the component has admin views linked to it, and those admin views have fields linked to it, and those fields have field types linked to it, and those component has site views, and custom admin views, and those site views and custom admin views has templates and layouts, and dynamic gets, and all these various linked concepts to a component is exported. [00:01:09](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m09s)
Ok so
[00:00:00](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s)
A new feature has been added to the advanced Component Builder for Joomla which can become very useful in the future. It allows you to export a component out of JCB, and not only the component's information, but everything attached to it. [00:00:34](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m34s) If the component has Admin Views linked to it, and those Admin Views have fields linked to it, and those fields have field types linked to it, and those component has site views, and Custom Admin views, and those Site Views and Custom Admin Views has templates and layouts, and dynamic gets, and all these various linked concepts to a component, is exported.
### Two Ways To Export A Component - Encrypted And Non Encrypted
The way that you will export a component is you'd simply click on export component. You need to select the component or components that you would like to export. There's a few things to say when we want to export a component. There are two ways in which we export a component. One is [00:01:36](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m36s) an encrypted way, and the other is non encrypted.
[00:01:09](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m09s)
The way to export a component is to simply click on 'Export Components'. Select the component or components that should be exported. There are two ways how a component gets exported. One is an encrypted way, and the other is non encrypted.
### Smart Export Builder
Let me show you that in the code. So I like you to understand exactly how it works. So we have a method here called smartExportBuilder. Now SmartExportBuilder gets fired at the very end of the compilation or rather the build. Where all the data has now been extracted from the database [00:02:05](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m05s) and it's now one big array of objects. In this function called getSmartExport, is where this data extrusion takes place.
[00:01:40](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m40s)
Let me show that in the code. There is a method called 'smartExportBuilder'. The 'SmartExportBuilder' gets fired at the very end of the compilation or rather the build. Where all the data has now been extracted from the database and it's now one big array of objects. In this function called 'getSmartExport', is where this data extrusion takes place.
### Export Key
During this process we actually [00:02:25](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m25s) take an account of a specific value. That value's name is export key. So in this 'foreach' we are looping through the components that you've selected. If you selected more than one, then it will check whether there is an export key for that component. Let me show you where that is a set in the user interface. When you open a component, [00:03:00](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m00s) it has a tab called settings. At the bottom of the right-hand column it has a new field called export key. You can put any value in here. If you leave this value empty, and you export only this(sermonDistributor) component, then the component will not be encrypted. If you add a value to this(export key) field [00:03:32](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m32s) and you export this component it will encrypt that component's data, the database values. It will not encrypt attached files or folders or images that are part of this component. It will only encrypt the data from the database.
[00:02:21](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m21s)
During this process an account is taken of a specific value. That value's name is 'export key'. So in this 'foreach' we are looping through the components that have been selected. If more than one have been selected, then it will check whether there is an 'export key' for that component. It is set in the user interface. When a component is opened, it has a tab called settings.[00:03:00](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m00s) At the bottom of the right-hand column it has a new field called 'Export Key'. Any value may be placed in here. If this value is left empty, and only this(sermonDistributor) component gets exported, then the component will not be encrypted. If a value is added to this (Export Key) field and this component is exported, it will encrypt that component's data; the database values. [00:03:32](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m32s)It will not encrypt attached files or folders or images that are part of this component. It will only encrypt the data from the database.
### Export Key - Encrypt All Components
Having said that, [00:03:54](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m54s) if you select multiple components, and any one of them has a key, then it will encrypt all the components. I'll explain again in the code how this is done. We go back to the code. In the code we are asking, does this component have an export key? [00:04:16](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m16s) If it's true and it has a string, this Ok so key is encrypted in a database. We first check that it is able to be encrypted, and then we encrypt the key. Then we add it to the key array with the component's id. Basically we are building up an array [00:04:41](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m41s) of each component's key. If a component does not have a key, it simply ignores this little script and it continues building its data set. Then once all the data set of all components are finished, we get to the smartExportBuilder I spoke of when we started looking at the code. In this smartExportBuilder we are simply asking, have we found any keys?
[00:03:54](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m54s)
If multiple components is selected, and any one of them has a key, then it will encrypt all the components. It will be explained again in the code how this is done. Return to the code. It needs to be asked: Does this component have an export key? [00:04:16](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m16s) If it is 'true' and it has a 'string', this key is encrypted in a database. First check if it is possible to encrypt it, and then encrypt the key. Then add it to the key array with the component's ID. An array is being build of each component's key. [00:04:41](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m41s) If a component does not have a key, it simply ignores this little script and it continues building its data set. Then once all the data set of all components are finished, then in the 'smartExportBuilder' it may determined if any keys had been found.
### If Any Key - Implode The array
If we have found any keys, [00:05:15](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m15s) we are going to implode the array, convert it to md5 string. We will then use this md5 string with an Aes encryption cypher to lock the data. [00:05:37](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m37s) So there is the data. Now above here we already changed the whole data set to a serialized string. So we have a string in this(data) variable. And here we are encrypting the whole string. In this(data) variable we have the encrypted value. If we don't have any keys, even if that means if none of the components that was selected had any keys set, then it will default to simply [00:06:09](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m09s) do a base64_encode. If that is well, then it gets written to the file that's part of the package. So that is how it exports the data. I'm not going to explain much about the actual mechanics that's happening here in the bottom of the file. You're welcome to look through it. If you see any room for improvements, you're welcome to make a pull request. [00:06:43](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m43s) So it exports the data and then checks whether we have any keys. So if you have, for example exporting five components, and all five components have keys, in all five keys will create a very long string, and then that whole string will be changed into an md5 string which is 32 characters. And that 32 characters is then used to encrypt the data. [00:07:13](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m13s)
[00:05:12](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m12s)
If any keys has been found, the array is going to be imploded and converted to a 'md5' string.<<<<<<<<<
We will then use this md5 string with an Aes encryption cypher to lock the data. [00:05:37](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m37s) So there is the data. Now above here we already changed the whole data set to a serialized string. So we have a string in this(data) variable. And here we are encrypting the whole string. In this(data) variable we have the encrypted value. If we don't have any keys, even if that means if none of the components that was selected had any keys set, then it will default to simply [00:06:09](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m09s) do a base64_encode. If that is well, then it gets written to the file that's part of the package. So that is how it exports the data. I'm not going to explain much about the actual mechanics that's happening here in the bottom of the file. You're welcome to look through it. If you see any room for improvements, you're welcome to make a pull request. [00:06:43](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m43s) So it exports the data and then checks whether we have any keys. So if you have, for example exporting five components, and all five components have keys, in all five keys will create a very long string, and then that whole string will be changed into an md5 string which is 32 characters. And that 32 characters is then used to encrypt the data. [00:07:13](https://www.youtube.com/watch?v=lkE0ZiSWufg&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m13s)
Basically
### Exporting A Component - Generating A Key