I think this is an important abiltity to have and a presents a great learning opportunity to become more familiar with LinuxMCE, PHP, & MySQL. Over the last couple days I've got the script more or less working to export and import basic user generated device templates. I have tested this with a few IR A/V devices and I have also tried the PLCBUS template, programmed IR codes and ruby commands are exporting and importing . The following is a list of some updates and issues:
Changes:
* - fixed - quotes around field names are gone
* - fixed - stores all rows from related tables rather than last row only
* - fixed - updates DeviceTemplate FK's for new related table PK entries after inserts are done
* - fixed - strings are escaped before inserting to db (ruby looks okay to me)
* - added - preview insert/update statements before importing to DB
* Known Issues:
* - when previewing these are placeholder values PK_DeviceTemplate=-3, PK_InfraredGroup=-2
* - does not set FK_Manufacturer, FK_DeviceCategory properly in related tables if new
* Manufacturer or DeviceCategory entries are inserted by the script
* - does not export/import DHCPDevice PnpDetectionScript scripts - only DB entries
* - does not import DTs marked 'old', use &forceExportType=new during export to be able to import
* - no validation of data can create duplicate rows in tables when importing 'old' as 'new'
* - I'm sure there's more...
Thanks posde and merkur2k I'm learning lots. It has a ways to go to deal with all possibilities, and could be a little prettier, but it's in a state where it is worth doing some testing with. I'd like to rename it at some point (posde?) as it no longer generates a PHP script. DeviceTemplateRevolver (DTR) or DeviceTemplateXchanger (DTX)... or something. I expect to tackle the issues mentioned above, feel free to add to the list if you find specific issues. Backup your data before using.
Use:
Exporting - the script will display the serialized data and ask you to confirm the export after which it will present the file download dialog.
Importing - View or Import. Default is View. Choosing view will parse the selected file and display the generated insert/update statements without executing any of them. Choosing Import will immediately execute the insert/update statements and display them at the same time. Choose view the first time, verify the insert/update statements, hit the back button and choose Import to import the device.
Grab the updated script from:
http://filebin.ca/mftsyp/DeviceTemplate2php.tar.gzJ.