dataragd and replication
Posted on 2007-09-25 12:35:09 EEST.
Did I wrote something new about datagard yesterday? Whatever it is , it is old ;)
So... what happened since last morning?
I added support to reload apache's httpd server when new virtual host is successfully created. It's obviously two command less when datagard stops.
Today, early morning, Bergie suggested yet another cool feature. Why to ask user for MySQL's admin password, if server might be not secured by this?
Quite easy as an idea , but I found it difficult to implement. Mainly ( no no, only because of it ) because php's exec function doesn't fill user's array with all data which are returned by executed command.
Docs clearly states:
"If the output argument is present, then the specified array will be filled with every line of output from the command"
But this:
$retval = 0;
$output = array();
exec($somecmd, &$output, &$retval);
Doesn't work as you would like to expect. $output is always an empty array. Anyway, I decided to use wild "convention", and I try to create database without password and when it fails I ask user for password. Not nice , but better than nothing for a start...
Also I added validation checks for midgard_setup_config which initially tries to "detect" if every single constant or class exists or is usefull in our case. Most of these are checked during configure script, but few times I "managed" to run datagard which changed permission with empty user and group name. Though , those passed correctly during package's configure.
And most sexy part of last changes. Midgard database provides predefined list of languages, so I had no other choice and implement replication support :) midgard_replicator requires much more love, but some missed features can be work arounded easily.
It's sample script to create one xml for more than 100 objects.
$midgard = new midgard_connection();
$midgard->open("my_configuration");
$qb = new midgard_query_builder("midgard_language");
$ret = $qb->execute();
$big_xml = "<?xml";
$xml_root = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$xml_ns = "<midgard_object xmlns=\"http://www.midgard-project.org/midgard_object/1.8\">";
$xml_ns_end = "</midgard_object>";
$xml_data = "";
foreach($ret as $lang) {
$xml = midgard_replicator::serialize($lang);
$xml = str_replace($xml_root, "", $xml);
$xml = str_replace($xml_ns, "", $xml);
$xml = str_replace($xml_ns_end, "", $xml);
$xml_data .= $xml;
}
$big_xml = $xml_root.$xml_ns.$xml_data.$xml_ns_end;
file_put_contents("languages.xml", $big_xml);
You can import this file with import_from_xml method, once it's written.
And so, datagard does it to give you more than 180 ready to use languages.