Jump to content

module/tab AdminImport issue on import customers


Prestachopo

Recommended Posts

I think that the Customers function import has an error, if you check 'Delete all customers before import' in the switch case of AdminImport.php you can see this:

case $this->entities[$this->l('Customers')]:
   Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'customer');
   break;



My question is, what happen with customer_group, customer_message and customer_thread? I supose that messages and threads can still stored for log or similar purposes, but the groups contain a lost info of customers (deleted) in the database. This will cause an error because the Id's of old customers still in the customer_group table, and when create new customers, the ids stored in customer_group miss match from the new id in customer, right? May be should be:


case $this->entities[$this->l('Customers')]:
   Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'customer');
   Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'customer_group');
   break;



Probably this issue will happen in the customer_message and customer_thread tables asign incorrect ids from old customers to new customers. In that case the code will be this:


case $this->entities[$this->l('Customers')]:
   $truncate_tables = array(
       'customer', 
       'customer_group', 
       'customer_message', 
       'customer_thread'
   );
   foreach($truncate_tables as $truncate_table) {
       Db::getInstance()->Execute('TRUNCATE TABLE `' . _DB_PREFIX_ . $truncate_table . '`'); // <-- note this lost end comma in original code in all TRUNCATE querys
   }
   break;



To solve this the customer table need a 'DELETE' that keep customers IDs (auto_increment) instead a 'TRUNCATE' that reset the auto_increment.

I prefer TRUNCATE the four tables (customer and customer_*) to really clean all customer info if you setup a new Prestashop from other.

You can reproduce the error if you put this code in AuthController.php:

       if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount'))
       {
     for ($i = 1; $i <= 100; $i++) { //<-- for testing accounts create
     $_POST = array(
         'customer_firstname' => 'nombre',
         'customer_lastname' => 'apellidos',
         'email' => 'test' . rand() . '@example.com',
         'passwd' => '12345',
         'days' => 1,
         'months' => 1,
         'years' => 2001,
         'company' => 'empresa-' . rand(1,999),
         'vat_number' => '',
         'firstname' => 'nombre',
         'lastname' => 'apellidos',
         'address1' => 'direccion1',
         'address2' => 'direccion2',
         'postcode' => 28082,
         'city' => 'madrid',
         'id_country' => 6,
         'id_state' => '',
         'other' => '',
         'phone' => 987654321,
         'phone_mobile' => 612345678,
         'alias' => 'alias mi dirección ' . rand(1,999),
         'dni' => '',
         'email_create' => 1,
         'is_new_customer' => 1,
         'back' => 'my-account.php',
         'submitAccount' => 'Registrarse',
     );
     // remember the end for braket!!!

     // ... more code ...

     } /* end loop for */

   if (Tools::isSubmit('SubmitLogin'))
       // ... more code ...



Create 100 customers, then TRUNCATE customer table, and finally the error ocurr!

Best Regards.

Link to comment
Share on other sites

Look, in function truncateTables($case) can see 'the lost comma' example in many querys:

case $this->entities[$this->l('Combinations')]:
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_impact'); // <-- bingo!
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute`'); // ok
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_combination`'); // ok
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_group`'); // ok
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_group_lang`'); // ok
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute`'); // ok
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_lang`'); // ok
 break;
case $this->entities[$this->l('Manufacturers')]:
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'manufacturer'); // <-- mec mec!
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'manufacturer_lang'); // <-- fail!



Best Regards.

Link to comment
Share on other sites

Remember to me, when the bug tracker working again report another bug:

// in AdminImport.php
// function customerImport()
if (!$res)
   $res = $customer->add();
if ($res)
   $customer->addGroups(array(1));

// in Customer.php
// function add()
$row = array('id_customer' => (int)($this->id), 'id_group' => (int)$this->id_default_group);
return Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT');



This cause mysql error 'DUPLICATE ENTRY FOR PRIMARY KEY' etc...

Note: the highlight colour syntax in forum has a bug, if you post first a comment, you not view the highlight like if you put a comment after any code as you can view in the example above.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...