/** * Gets the default empty file as an xml string. * * @return string */ protected function getDefaultEmptyFile() { $xml_template = new \Altumo\Xml\XmlElement('<DatabaseUpdaterConfiguration/>'); $settings = $xml_template->addChild('Settings'); $settings->addChild('DropOnNewSnapshot', 'false'); $database = $xml_template->addChild('Database'); $database->addChild('DatabaseName', '[[DATABASE]]'); $database->addChild('Hostname', '[[DATABASE_HOST]]'); $database->addChild('Username', '[[DATABASE_USER]]'); $database->addChild('Password', '[[DATABASE_PASSWORD]]'); return $xml_template->getXmlAsString(true); }
/** * Converts an XML string to a JSON string. * * Adapted from http://pear.php.net/package/Services_JSON * * * @param string $xml * @throws \Exception if $xml is not valid XML * @return string */ public static function convertXmlToJson($xml) { $xml_element = new \Altumo\Xml\XmlElement($xml); return $xml_element->getAsJsonString(); }
/** * Tests basic parsing. * */ public function testXmlFileParsing() { $xml_file = new \Altumo\Xml\XmlElement(); $xml_file->setContentsByString('<?xml version="1.0" encoding="UTF-8" ?>' . '<hello>World</hello>'); $this->assertTrue($xml_file->xpath('.') === 'World'); }
/** * DEPRECATED. * * The functionallity provided by this method is now irrelevant due to the * way Concrete Inheritance works. * * * Finds tables with missing concrete_inheritance foreign keys * (on the table being extended) and adds them. * * @return void * * @throws \Exception // if a column by the same name as the foreign key * // being created already exists. * // (only if the column is not already a foreign key) * // if a referenced parent table is not * // defined in the schema. */ protected function addConcreteInheritanceForeignKeys() { // turns out foreign keys are not required for the latest version of // ConcreteInheritanceBehavior return; $table_elements =& $this->getTableElements(); $table_inheritance_map = $this->getTableConcreteInheritanceMap(); foreach ($table_inheritance_map as $parent_table_name => $child_tables) { foreach ($child_tables as $child_table_name) { if (!isset($table_elements[$parent_table_name])) { throw new \Exception("Attempted to inherit from an undefined table \"{$parent_table_name}\""); } $parent_table_element =& $table_elements[$parent_table_name]; if (0) { $parent_table_element = new \Altumo\Xml\XmlElement(); } $foreign_key_name = $child_table_name . '_id'; // Ensure no column with the same name as the FK exists on the parent table and is not a foreign key already. $existing_column = $parent_table_element->queryWithXpath('column[@name="' . $foreign_key_name . '"]', \Altumo\Xml\XmlElement::RETURN_TYPE_XML_ELEMENT, false); $column_already_exists = false; if (!empty($existing_column)) { // A column exists. Ensure it's a foreign key to the parent table. $existing_fk = $parent_table_element->queryWithXpath('foreign-key[@foreignTable="' . $child_table_name . '"]/reference[@local="' . $foreign_key_name . '"]', \Altumo\Xml\XmlElement::RETURN_TYPE_XML_ELEMENT, false); $column_already_exists = true; // If the foreign-key does not exist, throw an exception if (empty($existing_fk)) { throw new \Exception("A column \"{$foreign_key_name}\" already exists in table \"{$parent_table_name}\". \n However this column is not a foreign key to {$child_table_name}. \n Either remove/rename this colum or make it a foreign key for Concrete Inheritance."); // Skip this entry if a correct foreign key already exists. } else { continue; } } // Add foreign key if (!$column_already_exists) { $column_element = $parent_table_element->addChild('column'); $column_element->addAttribute('name', $foreign_key_name); $column_element->addAttribute('required', 'false'); $column_element->addAttribute('type', 'integer'); } $foreign_key_element = $parent_table_element->addChild('foreign-key'); $foreign_key_element->addAttribute('foreignTable', $child_table_name); $foreign_key_element->addAttribute('onDelete', 'cascade'); $foreign_key_reference_element = $foreign_key_element->addChild('reference'); $foreign_key_reference_element->addAttribute('local', $foreign_key_name); $foreign_key_reference_element->addAttribute('foreign', 'id'); } } }