// Generate better XML definitions in installer

This commit is contained in:
rMalie
2011-12-27 10:36:59 +00:00
parent 68b63d1d47
commit e8066f4d80
77 changed files with 470 additions and 405 deletions
+72
View File
@@ -0,0 +1,72 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class InstallSimplexmlElement extends SimpleXMLElement
{
/**
* Can add SimpleXMLElement values in XML tree
*
* @see SimpleXMLElement::addChild()
*/
public function addChild($name, $value = null, $namespace = null)
{
if ($value instanceof SimplexmlElement)
{
$content = trim((string)$value);
if (strlen($content) > 0)
$new_element = parent::addChild($name, str_replace('&', '&amp;', $content), $namespace);
else
{
$new_element = parent::addChild($name);
foreach ($value->attributes() as $k => $v)
$new_element->addAttribute($k, $v);
}
foreach ($value->children() as $child)
$new_element->addChild($child->getName(), $child);
}
else
return parent::addChild($name, str_replace('&', '&amp;', $value), $namespace);
}
/**
* Generate nice and sweet XML
*
* @see SimpleXMLElement::asXML()
*/
public function asXML($filename = null)
{
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML(parent::asXML());
if ($filename)
return file_put_contents($filename, $dom->saveXML());
return $dom->saveXML();
}
}
+11 -19
View File
@@ -346,7 +346,7 @@ class InstallXmlLoader
if (!file_exists($path))
throw new PrestashopInstallerException('XML data file '.$entity.'.xml not found');
if (!$this->cache_xml_entity[$this->path_type][$cache_id] = @simplexml_load_file($path))
if (!$this->cache_xml_entity[$this->path_type][$cache_id] = @simplexml_load_file($path, 'InstallSimplexmlElement'))
throw new PrestashopInstallerException('XML data file '.$entity.'.xml invalid');
}
@@ -683,7 +683,7 @@ class InstallXmlLoader
if (!$this->entityExists($entity))
return $info;
$xml = @simplexml_load_file($this->data_path.$entity.'.xml');
$xml = @simplexml_load_file($this->data_path.$entity.'.xml', 'InstallSimplexmlElement');
if (!$xml)
return $info;
@@ -764,7 +764,12 @@ class InstallXmlLoader
$field['relation'] = $info['relation'];
}
$this->writeNiceAndSweetXML($xml, $this->data_path.$entity.'.xml');
// Recreate entities nodes, in order to have the <entities> node after the <fields> node
$store_entities = clone $xml->entities;
unset($xml->entities);
$xml->addChild('entities', $store_entities);
$xml->asXML($this->data_path.$entity.'.xml');
}
/**
@@ -825,7 +830,7 @@ class InstallXmlLoader
unset($xml->entities);
$entities = $xml->addChild('entities');
$this->createXmlEntityNodes($entity, $content['nodes'], $entities);
$this->writeNiceAndSweetXML($xml, $this->data_path.$entity.'.xml');
$xml->asXML($this->data_path.$entity.'.xml');
// Generate multilang XML files
if ($content['nodes_lang'])
@@ -840,7 +845,7 @@ class InstallXmlLoader
$xml_node = new SimpleXMLElement('<entity_'.$entity.' />');
$this->createXmlEntityNodes($entity, $nodes, $xml_node);
$this->writeNiceAndSweetXML($xml_node, $this->lang_path.$iso.'/data/'.$entity.'.xml');
$xml_node->asXML($this->lang_path.$iso.'/data/'.$entity.'.xml');
}
if ($xml->fields['image'])
@@ -1048,8 +1053,7 @@ class InstallXmlLoader
foreach ($node as $k => $v)
{
if (isset($types[$k]) && $types[$k])
// Sadly SimpleXML is really stupid ...
$entity_node->addChild($k, str_replace('&', '&amp;', $v));
$entity_node->addChild($k, $v);
else
$entity_node[$k] = $v;
}
@@ -1137,16 +1141,4 @@ class InstallXmlLoader
if (file_exists($from_path.$tab->class_name.'.gif'))
copy($from_path.$tab->class_name.'.gif', $backup_path.$tab->class_name.'.gif');
}
/**
* ONLY FOR DEVELOPMENT PURPOSE
*/
public function writeNiceAndSweetXML(SimpleXMLElement $xml, $filename)
{
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
file_put_contents($filename, $dom->saveXML());
}
}