diff --git a/install-new/classes/xmlLoader.php b/install-new/classes/xmlLoader.php index 5430b2524..242201f6d 100644 --- a/install-new/classes/xmlLoader.php +++ b/install-new/classes/xmlLoader.php @@ -54,6 +54,10 @@ class InstallXmlLoader protected $ids = array(); + protected $primaries = array(); + + protected $delayed_inserts = array(); + public function __construct() { $this->language = InstallLanguages::getInstance(); @@ -290,6 +294,8 @@ class InstallXmlLoader $this->copyImages($entity, $identifier, (string)$xml->fields['image'], $data); } } + + $this->flushDelayedInserts(); } /** @@ -373,6 +379,20 @@ class InstallXmlLoader return $data; } + public function flushDelayedInserts() + { + foreach ($this->delayed_inserts as $entity => $queries) + { + $type = 'INSERT IGNORE'; + if ($entity == 'access') + $type = 'REPLACE'; + + if (!Db::getInstance()->autoExecute(_DB_PREFIX_.$entity, $queries, $type)) + $this->setError($this->language->l('An SQL error occured for entity %1$s: %2$s', $entity, Db::getInstance()->getMsgError())); + unset($this->delayed_inserts[$entity]); + } + } + /** * Create a simple entity with all its data and lang data * If a methode createEntity$entity exists, use it. Else if $classname is given, use it. Else do a simple insert in database. @@ -385,16 +405,15 @@ class InstallXmlLoader */ public function createEntity($entity, $identifier, $classname, array $data, array $data_lang = array()) { + $xml = $this->loadEntity($entity); if (method_exists($this, 'createEntity'.Tools::toCamelCase($entity))) { // Create entity with custom method in current class $method = 'createEntity'.Tools::toCamelCase($entity); - $entity_id = $this->$method($data, $data_lang); + $entity_id = $this->$method($identifier, $data, $data_lang); } else if ($classname) { - $xml = $this->loadEntity($entity); - // Create entity with ObjectModel class $object = new $classname(); $object->hydrate($data); @@ -405,15 +424,22 @@ class InstallXmlLoader } else { - // Create entity in database); - $execute_type = 'INSERT IGNORE'; - if ($entity == 'access') - $execute_type = 'REPLACE'; + // Generate primary key manually + $primary = ''; + $entity_id = 0; + if (!$xml->fields['primary']) + $primary = 'id_'.$entity; + else if (strpos((string)$xml->fields['primary'], ',') === false) + $primary = (string)$xml->fields['primary']; - if (!Db::getInstance()->autoExecute(_DB_PREFIX_.$entity, array_map('pSQL', $data), $execute_type)) - $this->setError($this->language->l('An SQL error occured for entity %1$s: %2$s', $entity, Db::getInstance()->getMsgError())); - $entity_id = Db::getInstance()->Insert_ID(); + if ($primary) + { + $entity_id = $this->generatePrimary($entity, $primary); + $data[$primary] = $entity_id; + } + // Store INSERT queries in order to optimize install with grouped inserts + $this->delayed_inserts[$entity][] = array_map('pSQL', $data); if ($data_lang) { $real_data_lang = array(); @@ -425,8 +451,7 @@ class InstallXmlLoader { $insert_data_lang['id_'.$entity] = $entity_id; $insert_data_lang['id_lang'] = $id_lang; - if (!Db::getInstance()->autoExecute(_DB_PREFIX_.$entity.'_lang', array_map('pSQL', $insert_data_lang), 'INSERT IGNORE')) - $this->setError($this->language->l('An SQL error occured for entity %1$s: %2$s', $entity, Db::getInstance()->getMsgError())); + $this->delayed_inserts[$entity.'_lang'][] = array_map('pSQL', $insert_data_lang); } } } @@ -434,11 +459,56 @@ class InstallXmlLoader $this->storeId($entity, $identifier, $entity_id); } - public function createEntityConfiguration(array $data, array $data_lang = array()) + public function createEntityTab($identifier, array $data, array $data_lang) { - if (!Configuration::get($data['name'])) - Configuration::updateGlobalValue($data['name'], ($data_lang) ? $data_lang['value'] : $data['value']); - return Configuration::getIdByName($data['name']); + static $position = array(); + + $entity = 'tab'; + $xml = $this->loadEntity($entity); + + if (!isset($position[$data['id_parent']])) + $position[$data['id_parent']] = 0; + $data['position'] = $position[$data['id_parent']]++; + + // Generate primary key manually + $primary = ''; + $entity_id = 0; + if (!$xml->fields['primary']) + $primary = 'id_'.$entity; + else if (strpos((string)$xml->fields['primary'], ',') === false) + $primary = (string)$xml->fields['primary']; + + if ($primary) + { + $entity_id = $this->generatePrimary($entity, $primary); + $data[$primary] = $entity_id; + } + + // Store INSERT queries in order to optimize install with grouped inserts + $this->delayed_inserts[$entity][] = array_map('pSQL', $data); + if ($data_lang) + { + $real_data_lang = array(); + foreach ($data_lang as $field => $list) + foreach ($list as $id_lang => $value) + $real_data_lang[$id_lang][$field] = $value; + + foreach ($real_data_lang as $id_lang => $insert_data_lang) + { + $insert_data_lang['id_'.$entity] = $entity_id; + $insert_data_lang['id_lang'] = $id_lang; + $this->delayed_inserts[$entity.'_lang'][] = array_map('pSQL', $insert_data_lang); + } + } + + $this->storeId($entity, $identifier, $entity_id); + } + + public function generatePrimary($entity, $primary) + { + if (!isset($this->primaries[$entity])) + $this->primaries[$entity] = (int)Db::getInstance()->getValue('SELECT '.$primary.' FROM '._DB_PREFIX_.$entity.' ORDER BY '.$primary.' DESC'); + return ++$this->primaries[$entity]; } public function copyImages($entity, $identifier, $path, array $data, $extension = 'jpg') diff --git a/install-new/data/xml/address_format.xml b/install-new/data/xml/address_format.xml index 466bb5720..92fd69c14 100644 --- a/install-new/data/xml/address_format.xml +++ b/install-new/data/xml/address_format.xml @@ -1,6 +1,6 @@ - + diff --git a/install-new/data/xml/configuration.xml b/install-new/data/xml/configuration.xml index 15fba6fce..ca7720805 100644 --- a/install-new/data/xml/configuration.xml +++ b/install-new/data/xml/configuration.xml @@ -1,6 +1,6 @@ - + diff --git a/install-new/data/xml/country.xml b/install-new/data/xml/country.xml index 2bb63d79d..6ae23d5c8 100644 --- a/install-new/data/xml/country.xml +++ b/install-new/data/xml/country.xml @@ -1,6 +1,6 @@ - + diff --git a/install-new/data/xml/hook.xml b/install-new/data/xml/hook.xml index bcda45946..152f0b88f 100644 --- a/install-new/data/xml/hook.xml +++ b/install-new/data/xml/hook.xml @@ -1,6 +1,6 @@ - + diff --git a/install-new/data/xml/meta.xml b/install-new/data/xml/meta.xml index 1afd028dc..4e9b6700a 100644 --- a/install-new/data/xml/meta.xml +++ b/install-new/data/xml/meta.xml @@ -1,6 +1,6 @@ - + diff --git a/install-new/data/xml/state.xml b/install-new/data/xml/state.xml index 5f48d0706..ccb4f4bdb 100644 --- a/install-new/data/xml/state.xml +++ b/install-new/data/xml/state.xml @@ -1,6 +1,6 @@ - + diff --git a/install-new/data/xml/tab.xml b/install-new/data/xml/tab.xml index bc8973379..8b382c2db 100644 --- a/install-new/data/xml/tab.xml +++ b/install-new/data/xml/tab.xml @@ -1,6 +1,6 @@ - + diff --git a/install-new/index.php b/install-new/index.php index 9ac8d9c95..2f360200a 100644 --- a/install-new/index.php +++ b/install-new/index.php @@ -35,4 +35,4 @@ try catch (PrestashopInstallerException $e) { $e->displayMessage(); -} \ No newline at end of file +} diff --git a/install-new/init.php b/install-new/init.php index 8f0691213..51f2491ff 100644 --- a/install-new/init.php +++ b/install-new/init.php @@ -53,6 +53,8 @@ require_once _PS_INSTALL_PATH_.'classes/sqlLoader.php'; require_once _PS_INSTALL_PATH_.'classes/xmlLoader.php'; require_once _PS_INSTALL_PATH_.'classes/simplexml.php'; +@set_time_limit(300); + class InstallLog { /** @@ -68,8 +70,9 @@ class InstallLog } protected $fd; - protected $start_time = array(); + protected $data = array(); protected $last_time; + protected $depth = 0; public function __construct() { @@ -79,20 +82,28 @@ class InstallLog public function write($id) { - $str = "[$id]"; - $str .= ' - [Time: '.round(microtime(true) - $this->last_time, 4).']'; - if (isset($this->start_time[$id])) - $str .= ' - [Length: '.round(microtime(true) - $this->start_time[$id], 4).']'; - fwrite($this->fd, "$str\n"); + $str = str_pad("[$id]", 35, ' '); + if (isset($this->data[$id]['start'])) + $str .= str_pad(round(microtime(true) - $this->data[$id]['start'], 4).'ms', 10, ' '); + $str .= str_pad(round(microtime(true) - $this->last_time, 4).'ms', 10, ' '); + $this->data[$id]['str'] = str_repeat("\t", $this->depth - 1)."$str\n"; + $this->depth--; } public function start($id) { - $this->start_time[$id] = microtime(true); + $this->data[$id] = array('start' => microtime(true)); + $this->depth++; } public function __destruct() { + foreach ($this->data as $k => $info) + if (!isset($info['str'])) + $this->write($k); + + foreach ($this->data as $info) + fwrite($this->fd, $info['str']); fclose($this->fd); } } \ No newline at end of file diff --git a/install-new/models/install.php b/install-new/models/install.php index 79146a74a..c05c3293c 100644 --- a/install-new/models/install.php +++ b/install-new/models/install.php @@ -196,7 +196,7 @@ class InstallModelInstall extends InstallAbstractModel } } - // Copy language default images (we do this action after database in populated because we need image types informations) + // Copy language default images (we do this action after database in populated because we need image types information) foreach ($languages as $iso) $this->copyLanguageImages($iso);