Export Block to XML
Permalink
Hi everyone
there's a method which I think can be really helpful but isn't because it doesn't always works as expected.
Let me start with a short example:
This will export the content of the block with the ID 110, but...
If the block with that ID has more than one table like this:
* btSlideshow (main block table)
* btSlideshowImages
it will usually just export the record from the mail table. Everything in the second table will be ignored. Due to this it's risky to rely on this method.
We could build blocks that fetch all the data in the constructor. Something like this:
However, loading data in the constructor is probably not the best idea either as we might call the constructor several times before we actually process the data.
I just wonder, has anyone ever tried to work with "Block::export"? Any experiences?
there's a method which I think can be really helpful but isn't because it doesn't always works as expected.
Let me start with a short example:
$b = Block::getByID(110); $node = new SimpleXMLElement('<dummy></dummy>'); $b->export($node); print_r($node);
This will export the content of the block with the ID 110, but...
If the block with that ID has more than one table like this:
* btSlideshow (main block table)
* btSlideshowImages
it will usually just export the record from the mail table. Everything in the second table will be ignored. Due to this it's risky to rely on this method.
We could build blocks that fetch all the data in the constructor. Something like this:
public function __construct() { $db = Loader::db(); $this->images = $db->GetAll('SELECT * FROM btSlideshowImages ...'); }
However, loading data in the constructor is probably not the best idea either as we might call the constructor several times before we actually process the data.
I just wonder, has anyone ever tried to work with "Block::export"? Any experiences?
![andrew](/files/avatars/4.jpg)
If the block's controller is written correctly, export already does this. I just added a slideshow to a page and used the sample content generator add-on to export the entire content of the site, and this is the full content of that page's slideshow block. Try adding 'full' as a second parameter to the export function on a block.
Actually, you shouldn't even have to add that second parameter.
Yes, you're right. The export of the core slideshow block works fine. I've got a block (contractor of mine wrote that) where it doesn't work..
I'll have a closer look and compare those two.
I'll have a closer look and compare those two.
I would take a look at the controller variables btExportTables:
protected $btExportTables = array('btSlideshow','btSlideshowImg');
just saw that, thanks ;-)
I think there are a few blocks missing this information.
I never noticed these variables - they are great!
This might be something for the submission guideline:http://www.concrete5.org/documentation/developers/system/submitting...
I haven't seen a lot of people working with that export stuff, but it could be very handy, but also very annoying if it doesn't work properly. Imagine someone has a site with 10'000 pages and 20'000 blocks and exports/imports the content to a new site and realizes that certain blocks aren't properly exported..
I'll try to have a look at this when going through the add-ons in the PRB!
I think there are a few blocks missing this information.
I never noticed these variables - they are great!
This might be something for the submission guideline:http://www.concrete5.org/documentation/developers/system/submitting...
I haven't seen a lot of people working with that export stuff, but it could be very handy, but also very annoying if it doesn't work properly. Imagine someone has a site with 10'000 pages and 20'000 blocks and exports/imports the content to a new site and realizes that certain blocks aren't properly exported..
I'll try to have a look at this when going through the add-ons in the PRB!
Is there an equivalent to btExportTables that package controllers need to make package data exportable?
What kind of data do you have in mind?
You might be able to override this:
If you have a look at concrete/core/libraries/content/export.php you'll find a list of objects which are exported.
You might be able to override this:
public static function export($xml) { ...
If you have a look at concrete/core/libraries/content/export.php you'll find a list of objects which are exported.
I read Andrew's post that he had exported a whole site to xml, and wondered if I needed to do anything with my packages that have package db.xml to support such an export.
(I have not written have any blocks with secondary tables in the block db.xml, generally I declare any extra data in a package level db.xml)
(I have not written have any blocks with secondary tables in the block db.xml, generally I declare any extra data in a package level db.xml)
I don't think it matters if it's in the package's db.xml or not. If you need extra data in the block that is connected to the bID, you'll need to use btExportTables.
However, if you connect data without using the bID, it's getting a bit more complicated from what I've seen.
I've got a package where you can specify a list of states in the dashboard. In a second step, you can use them in a block. If I wanted to export such a block I'd probably have to come up with some custom code.
I've got a lot of these packages /-:
However, if you connect data without using the bID, it's getting a bit more complicated from what I've seen.
I've got a package where you can specify a list of states in the dashboard. In a second step, you can use them in a block. If I wanted to export such a block I'd probably have to come up with some custom code.
I've got a lot of these packages /-:
When I run this code:
with a slideshow block in my site, I get this:
Which looks correct and multi-table to me.
$b = Block::getByID(64); $node = new SimpleXMLElement('<dummy></dummy>'); $b->export($node); print $node->asXML();
with a slideshow block in my site, I get this:
<?xml version="1.0"?> <dummy> <block type="slideshow" name=""> <data table="btSlideshow"> <record> <fsID><![CDATA[0]]></fsID> <playback><![CDATA[ORDER]]></playback> <duration><![CDATA[]]></duration> <fadeDuration><![CDATA[]]></fadeDuration> </record> </data> <data table="btSlideshowImg"> <record> <slideshowImgId><![CDATA[1]]></slideshowImgId> <fID>{ccm:export:file:england_village.jpg}</fID>
Viewing 15 lines of 45 lines. View entire code block.
Which looks correct and multi-table to me.