Jump to content
musicmaster

Copy Shopdata: Script for copying shop content for upgrade

Recommended Posts

Posted (edited)
On 12/28/2015 at 2:11 PM, Rudolfo78 said:

Hi musicmaster,

I'm trying script copy_shopdata on my localhost installations - both 1.6.0.9 and I got stuck at the very beginning of copy process

 

1) old installation - I've downloaded my current installation 1.6.0.9 via FTP & exported database.sql and configured it to run localy (OS X, MAMP, Sequel Pro).

 

2) new installation - I've installed fresh installation same version 1.6.0.9 on my localhost, where I added subfolder "triple_edit" with its files, as well as script copy_shopdata files


13:45:32
1 old languages; 1 new languages. Language check ok.


accessory 1123 1
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-new.ps_accessory SELECT `id_product_1`,`id_product_2` FROM maclife-old.ps_acces' at line 1
Generated by Query 'INSERT INTO maclife-new.ps_accessory SELECT `id_product_1`,`id_product_2` FROM maclife-old.ps_accessory'

I've checked manual but I didn't find any useful information.

 

Could you please give me some advice, what should I check or revise. As I'm only basic user with some additional skills, I'm not very good in coding, syntax, etc.

 

Thanks for any advice.

 

On 12/28/2015 at 2:57 PM, musicmaster said:

I am not totally sure. But my guess is that the hyphens ("-") in the database names are the problem. They might be interpreted as "minus". The solution is to put the server names between backticks.I will have a look at it.

I have found new scenery where that error code happen, for example in this query:

SELECT d_specific_price, id_specific_price_rule, id_cart, id_product, id_shop, id_shop_group, id_currency, id_country, id_group, id_customer, id_product_attribute, price,from_quantity,reduction,reduction_tax,reduction_type,from,to INTO OUTFILE '/var/xxxxxxxxxxxxxxxxxxx/ptools/copy_shopdata_specific_price.dtx' FROM `ps_specific_price`

In this case error cause is the name of last fields of table "from" and "to", this field names are used in mysql querys, also sqlserver undertand it is part of query, not fields. the solution is close inside braquets  SELECT ........,'from','to' INTO OUTFILE...

 

 

Edited by salvavidal (see edit history)

Share this post


Link to post
Share on other sites
9 hours ago, salvavidal said:

 

I have found new scenery where that error code happen, for example in this query:

SELECT d_specific_price, id_specific_price_rule, id_cart, id_product, id_shop, id_shop_group, id_currency, id_country, id_group, id_customer, id_product_attribute, price,from_quantity,reduction,reduction_tax,reduction_type,from,to INTO OUTFILE '/var/xxxxxxxxxxxxxxxxxxx/ptools/copy_shopdata_specific_price.dtx' FROM `ps_specific_price`

In this case error cause is the name of last fields of table "from" and "to", this field names are used in mysql querys, also sqlserver undertand it is part of query, not fields. the solution is close inside braquets  SELECT ........,'from','to' INTO OUTFILE...

 

 

Hi,

I have uploaded a new version. Can you try that?

 

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, musicmaster said:

Hi,

I have uploaded a new version. Can you try that?

 

I have detected other issue, in the finish log the script write all tables that has not been copied from old shop, you remove automaticly first letters of table to remove PREFIX, but in case of my old shop had tables without PREFIX, those will appear cutted, for example, i have a table called 'updates', is a table which i created to process an internal script, that table appear like 'ates' on final log, Do you understand?, i guess you had to compare PREFIX of shop with begining of name and dont remove 3 first letter in case it doesnt match with PREFIX.

 

Than you for your big work, i will try your new version.

Edited by salvavidal (see edit history)

Share this post


Link to post
Share on other sites
1 hour ago, musicmaster said:

Hi,

I have uploaded a new version. Can you try that?

 

I have not tried because i don't need to do, i have checked code in copy_shopdata_functions.inc.php, and you have solved right with this line:

$args = "`".implode("`,`", array_intersect($newfields, $oldfields))."`";

Good job, remember to solve the other issue about cutting names which has not PREFIX in old shop, in screen appear incomplete the name.

Share this post


Link to post
Share on other sites
1 hour ago, salvavidal said:

I have detected other issue, in the finish log the script write all tables that has not been copied from old shop, you remove automaticly first letters of table to remove PREFIX, but in case of my old shop had tables without PREFIX, those will appear cutted, for example, i have a table called 'updates', is a table which i created to process an internal script, that table appear like 'ates' on final log, Do you understand?, i guess you had to compare PREFIX of shop with begining of name and dont remove 3 first letter in case it doesnt match with PREFIX.

This point is not clear enough to me. The old and the new prefix are removed as they may be different. But that applies to all tables not just those not copied. And I don't see any cutting in the code that writes the "$oldextras" (lines 170-175 in copy_shopdata_functions.inc.php).

Share this post


Link to post
Share on other sites
23 hours ago, salvavidal said:

I have detected other issue, in the finish log the script write all tables that has not been copied from old shop, you remove automaticly first letters of table to remove PREFIX, but in case of my old shop had tables without PREFIX, those will appear cutted, for example, i have a table called 'updates', is a table which i created to process an internal script, that table appear like 'ates' on final log, Do you understand?, i guess you had to compare PREFIX of shop with begining of name and dont remove 3 first letter in case it doesnt match with PREFIX.

Maybe this file solves that problem?

copy_shopdata.php

Share this post


Link to post
Share on other sites
Posted (edited)
11 hours ago, musicmaster said:

Maybe this file solves that problem?

copy_shopdata.php 11.07 kB · 0 downloads

it doesn't solve, and in my opinion is not a good solution, your are removing tables without PREFIX in your log printed when script finish, in my case i want to know which table weren't copied, even if those tables dont have PREFIX, because were tables created to work with my personal scripts, and i need to use it in new database, is good to show it in "not copied warning".

OLD TABLES						NOT COPIED (this way is shown when script finish)
actualizar_stock					ualizar_stock
tabla_auxiliar						la_auxiliar
ps_example1						example1
ps_example2						example2
ps_example3						example3
...								...
...								...

As you can see above those table in old prestashop which doesn't have PREFIX will be shown cutted on final log, you can fix it with next change in line 36:

while($row = mysqli_fetch_row($res))
{ $oldtables[] = substr($row[0], $len);
}

you have to edit with this:

while($row = mysqli_fetch_row($res))
{ $oldtables[] = substr($row[0], 0, $len) == _OLD_PREFIX_  ? substr($row[0], $len) : $row[0];
}

Thanks.

Edited by salvavidal (see edit history)

Share this post


Link to post
Share on other sites

Is this solution better? It lists the tables that are not considered.

Prefixes are used to have several shops in one database. That is useful for shops whose hosting provider only supplies one database. So the lack of a filter was a kind of bug.

copy_shopdata.php

Share this post


Link to post
Share on other sites
1 hour ago, musicmaster said:

Is this solution better? It lists the tables that are not considered.

Prefixes are used to have several shops in one database. That is useful for shops whose hosting provider only supplies one database. So the lack of a filter was a kind of bug.

copy_shopdata.php 11.38 kB · 0 downloads

Ok, you are right, in case that you have one database for several shops, my change is not good idea, i have checked you new update, and i see you have created a new array with "wrong prefix tables", also as you have said, if you have other shops with other prefix, the tables of all shops will be put inside of this array, because you only compare with _OLD_PREFIX_,

Share this post


Link to post
Share on other sites

I have found another important 'data' which have to be copied to new shop, the following values from ps_configuration:

PS_CUSTOMER_GROUP

PS_UNIDENTIFIED_GROUP

PS_GUEST_GROUP

It is very important to copy those values, that way you could avoid several errors is you have edited customer groups in original shop, if you have never edited customer group, you dont need to copy those values.

 

Share this post


Link to post
Share on other sites
1 hour ago, salvavidal said:

I have found another important 'data' which have to be copied to new shop, the following values from ps_configuration:

PS_CUSTOMER_GROUP

PS_UNIDENTIFIED_GROUP

PS_GUEST_GROUP

It is very important to copy those values, that way you could avoid several errors is you have edited customer groups in original shop, if you have never edited customer group, you dont need to copy those values.

 

Thank you for the addition. I have added them in a new version of the config file.

Share this post


Link to post
Share on other sites

a new question, if fields in old_table are in different position than fields in new_table, does script copy tables in right position? I have seen some error in tables because fields of old an new table doesnt have same positions.

Share this post


Link to post
Share on other sites
Just now, salvavidal said:

a new question, if fields in old_table are in different position than fields in new_table, does script copy tables in right position? I have seen some error in tables because fields of old an new table doesnt have same positions.

Do you mean that in the old table the order is id-name and in the new one name-id? Yes, that and missing fields in one of the tables are handled correctly.

One thing that can cause problems is when the new table has a unique key that in the old one wasn't unique.

Share this post


Link to post
Share on other sites
Posted (edited)
9 minutes ago, musicmaster said:

Do you mean that in the old table the order is id-name and in the new one name-id? Yes, that and missing fields in one of the tables are handled correctly.

One thing that can cause problems is when the new table has a unique key that in the old one wasn't unique.

not, i mean when oldtable has fields

id_name,

field2,

field3,

field4

and newtable has fields

field2,

id_name,

field3,

field4

as you can see, the same fields but different position.

 

Edited by salvavidal (see edit history)

Share this post


Link to post
Share on other sites
5 hours ago, salvavidal said:

not, i mean when oldtable has fields


id_name,

field2,

field3,

field4

and newtable has fields


field2,

id_name,

field3,

field4

as you can see, the same fields but different position.

 

I could have been clearer but that was what I meant. It is handled correctly.

Share this post


Link to post
Share on other sites
15 hours ago, rcmp_presta said:

Unfortunalelly the script doesn't work for me.

No helpdesk will be able to help you when you don't get more concrete than "It doesn't work".

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More