public static function build_slonik_preamble($db_doc, $replica_set, $slony_preamble_file) { dbsteward::notice("Building slonik pramble for replica set ID " . $replica_set['id'] . " output file " . $slony_preamble_file); $timestamp = date('r'); // all the other slonik file writers use mode a // have the preamble function to w to overwrite previous slonik command file sets // as the preamble is always the first thing in a slonik file $slony_preamble_fp = fopen($slony_preamble_file, 'w'); if ($slony_preamble_fp === FALSE) { throw new exception("failed to open slony preamble output file " . $slony_preamble_file); } $slony_preamble_ofs = new output_file_segmenter($slony_preamble_file, 1, $slony_preamble_fp, $slony_preamble_file); $slony_preamble_ofs->set_comment_line_prefix("#"); // keep slonik file comment lines consistent // don't write the fixed file header file name. slony preamble must start with the CLUSTER NAME directive $slony_preamble_ofs->disable_fixed_file_header(); if (!isset($db_doc->database->slony->slonyNode)) { $slony_preamble_ofs->write("DBSTEWARD: NO SLONY NODES DEFINED\n"); return FALSE; } $slony_preamble_ofs->write("CLUSTER NAME = " . $db_doc->database->slony['clusterName'] . ";\n"); // define the connection info for each node this replica set uses foreach ($db_doc->database->slony->slonyNode as $slony_node) { // the set uses this node, include it if (pgsql8::slony_replica_set_uses_node($replica_set, $slony_node)) { $slony_preamble_ofs->write("NODE " . $slony_node['id'] . " ADMIN CONNINFO = '" . "dbname=" . $slony_node['dbName'] . " host=" . $slony_node['dbHost'] . " user="******" password="******"';\n"); } } $slony_preamble_ofs->write("\n"); $slony_preamble_ofs->write("# " . $slony_preamble_file . "\n"); $slony_preamble_ofs->write("# DBSteward slony preamble generated " . $timestamp . "\n"); $slony_preamble_ofs->write("# Replica Set: " . $replica_set['id'] . "\n\n"); }