Salvo Posted January 31, 2004 Share Posted January 31, 2004 Hi all I need some help here: I have two osc.. with many products with two languages language_id = 1 English language_id = 4 Italian Now I have an other osc which I have many product but I have the two languages as: language_id = 1 English language_id = 2 Italian I need to change the language italian to have the same id = 2 or 4 Unfortunatelly I have many products in both osc otherwise I would do it manually. I need a small script that would change the "2 to 4" or " 4 to 2 " in a table affected by languages.. CAN someone help with this small script? Thanks Salvo Link to comment Share on other sites More sharing options...
mitchd Posted January 31, 2004 Share Posted January 31, 2004 Ok, this is quick and dirty, but I tested it against my 2.2-ms3-cvs from earlier this month and it worked fine. I changed my languages_id from 1 to 2 and then back to 1. BTW, I have both a languages_id and a language_id. I guess maybe you know what you are trying to change. YMMV. USE AT YOUR OWN RISK. ETC, ETC, ETC. DON'T BLAME ME. So, back up your database, copy the code below into a file under your admin directory (e.g. catalog/admin/db_change.php), and load it up in your browser. You've got three fields that should be self-explanatory: field_name, old_value, new_value. If all goes well it will tell you what it changed. You will need php 4.1, i think, for the get_defined_constants() function. I do not check your input or anything like that. You probably want to delete the file when you are done with it. Oh, and I'm running MySQL .... I'm not sure if osC supports other databases, but if it does this might not work if you are running some other DB, I don't know. <?php require('includes/application_top.php'); if (isset($_GET['field_name']) && isset($_GET['old_value']) && isset($_GET['new_value'])) { print "Changing ". $_GET['field_name'] ." from ". $_GET['old_value'] ." to ". $_GET['new_value'] ." in all tables...<br><br>"; foreach (get_defined_constants() as $k => $v) { if (substr($k,0,6) == "TABLE_") { $describe_qry = tep_db_query('describe '. $v); while ($row = tep_db_fetch_array($describe_qry)) { if ($row['Field'] == $_GET['field_name'] ) { if (tep_db_query('UPDATE '. $v .' SET '. $_GET['field_name'] .'="'. $_GET['new_value'] .'" WHERE '. $_GET['field_name'] .'="'. $_GET['old_value'] .'"')) { print "Changed ". $_GET['field_name'] ." from ". $_GET['old_value'] ." to ". $_GET['new_value'] ." in table ". $v ."<br>"; } else { print "Couldn't change value in table ". $v ."<br>"; } } } } } print "<br>done.</body></html>"; exit; } ?> <html> <head> <title></title> </head> <body> <form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="get"> <input type="text" name="field_name" value="field_name"> <br> <input type="text" name="old_value" value="old_value"> <br> <input type="text" name="new_value" value="new_value"> <br> <input type="submit"> </form> </body> </html> Hope that helps, Mitch [EDIT]: watch out for line wraps ... Link to comment Share on other sites More sharing options...
mitchd Posted January 31, 2004 Share Posted January 31, 2004 Oh, if you don't trust that ... you could do it pretty easy by hand. Just find all the tables where you want to change it and do: UPDATE <table_name> SET language_id=<new_value> WHERE language_id=<old_value>; I had 3 tables with languages_id and I think 5 or 6 with language_id, so it wouldn't be that much work. Mitch Link to comment Share on other sites More sharing options...
Salvo Posted January 31, 2004 Author Share Posted January 31, 2004 Thank for the answer.. I will try it tomorrow and let you know... Salvo Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.