ActiveTuning Posted February 21, 2003 Share Posted February 21, 2003 I need to install 2.2 MS1. I have a quick question though. Is there any way to setup the table names in MySQL so that all the osC tables have a name prefix (like osc_products), etc? Link to comment Share on other sites More sharing options...
Christian Lescuyer Posted February 21, 2003 Share Posted February 21, 2003 With a decent editor, it's very easy to do. Open includes/application_top.php. You will see that all table names are defined in there. Select lines with the table names. Replace all ', ' Or with vi: :%g/define('TABLE/s/', '/&osc_/ (not tested :)) Christian Lescuyer Link to comment Share on other sites More sharing options...
ActiveTuning Posted February 21, 2003 Author Share Posted February 21, 2003 So all I have to do is edit includes/application_top.php in both catalog and admin folders, and then just edit the names of the tables in the database and everything will work fine? Link to comment Share on other sites More sharing options...
nms Posted February 21, 2003 Share Posted February 21, 2003 Except for the backup-util, where there is an array with the tables in it.... I allready edited the configure.php and application_top to have a defined PREFIX. The only thing I now need to build is a SQL-preprocessor which does the same trick on the SQL-file which is in the install-folder. Then also integrate this PREFIX in the backup-util and viola, a complete solution for everyone... Link to comment Share on other sites More sharing options...
ActiveTuning Posted February 22, 2003 Author Share Posted February 22, 2003 Just to let everybody know, it worked :) Thanks! Link to comment Share on other sites More sharing options...
Guest Posted February 24, 2003 Share Posted February 24, 2003 Lucky... very lucky.... that the "other" shop was not active.... I did the following. Edited /includes/configure.php and changed all the table names to have a prefix. Edited /includes/application_top.php changed all the table names to have a prefix... Edited /admin/backup and changed all the table names in the "WHY THE ___ are you using string literals when there are constants you freaks" Can I repeat that.... Why do you use string literals in your code when there are constant defined? Unless there is a very, very good reason for this I can only see it as very BAD programming. I covered all of the things mentioned in this thread, using sed and vi to prefix all the tables. Including the oscommerce.sql file. I greped the directory for occurances of table name.... (my only mistake was not use -R). All looked rosey.... Bang! On install it deleted the other shop.... installed the new tables as prefixed and then bombed out that it could not find it's tables. So... I now have two shops to install tommorrow, and have wasted 2 hours work at 30 quid an hour. Repeating again.... Why do you bother defining table constants, and then just simply NOT use them. That has got to be silly! I suggest a table prefix system in the configuration / install pages as a top priority for the next release. Yours, not impressed. :evil: Paul Link to comment Share on other sites More sharing options...
Guest Posted February 24, 2003 Share Posted February 24, 2003 Okay, sorry for being .... you know, but I was unimpresed with that. The other shop needed upgrading to 2.2 anyway. If anyone has any brighter ideas about prefixing the tables to install multiple shops in one DB please let me know. In the meantime, I am going to hassle the sysadmins "again" about creating me a series of DBs for these shops. Sysadmins always cost time, trying to them to do things. Thanks. Link to comment Share on other sites More sharing options...
Christian Lescuyer Posted February 24, 2003 Share Posted February 24, 2003 I'm sorry you had a problem. It was good you didn't try on a production shop. I am unaware of table names in configure.php, or admin/backup.php. All table names should be specified in application_top.php. Are you using version 2.1? Christian Lescuyer Link to comment Share on other sites More sharing options...
Guest Posted February 24, 2003 Share Posted February 24, 2003 Version is 2.2ms1 downloaded today. You are correct.... My mistake regarding configure.php. application_top.php has the constants defined. I have found references to the tables as string literals in the following places.... /admin/backup.php : 245 /catalog/install/functions/database.php :201 /catalog/install/templates/upgrade_3.php:104 and beyond There are possibly more as well. Am I the only one who sees these as a liability in the code? Thanks for your reply. I may be able to find the time to correct these, and contribute, but as I am not that experienced with your framework, I think the work might be best carried out by someone who is. I could move the DB table constants to tables-config.php adding a PREFIX value (as someone already has in this thread) and include that somewhere sensible, then remove all string literal references to the table names replacing with use of the constants. Do you think that is enough? A preprocessor for the SQL file would be good. What does PHPbb do I wonder? Link to comment Share on other sites More sharing options...
Christian Lescuyer Posted February 25, 2003 Share Posted February 25, 2003 Thank you very much. I have entered a bug report: http://www.oscommerce.com/community/bugs,976 These are definitely bugs and should be corrected. A PREFIX system has been asked a number of time, but we have a feature freeze on 2.2 and I don't think this is in it. On the other hand, we'll be able to have definitive contributions for 2.2 Christian Lescuyer Link to comment Share on other sites More sharing options...
Guest Posted February 25, 2003 Share Posted February 25, 2003 Just knocked this up, if it of use to anyone. I may get a few more processors complete to prefix sites, at least before you upload them. # bash shell script to process SQL init file for OSC. # Adds table_prefixes_ to all DROP, CREATE and INSERT statements # NOT TESTED (enough) # Paul Campbell 2003 <[email protected]> TAB_PREFIX="test_prefix" ROOT_PATH="/www/your-domain.com" CATALOG_PATH="${ROOT_PATH}/catalog" ADMIN_PATH="${ROOT_PATH}/private/admin" SQL_FILE="install/oscommerce.sql" # Process oscommerce.sql SQL init file. sed "s/IF EXISTS /IF EXISTS ${TAB_PREFIX}_/" ${CATALOG_PATH}/${SQL_FILE} > ${CATALOG_PATH}/${SQL_FILE}.tmp sed "s/CREATE TABLE /CREATE TABLE ${TAB_PREFIX}_/" ${CATALOG_PATH}/${SQL_FILE}.tmp > ${CATALOG_PATH}/${SQL_FILE}.tmp2 sed "s/INSERT INTO /INSERT INTO ${TAB_PREFIX}_/" ${CATALOG_PATH}/${SQL_FILE}.tmp2 > ${CATALOG_PATH}/${SQL_FILE} rm ${CATALOG_PATH}/${SQL_FILE}.tmp* Link to comment Share on other sites More sharing options...
Christian Lescuyer Posted February 26, 2003 Share Posted February 26, 2003 Another bit: application_top.php. This is a Perl file. You will need to adjust the paths. The idea is to copy application_top.php from the CVS tree (in the cvs directory) to the destination tree, adding the table prefix where necessary. #!/usr/bin/perl -i # Christian Lescuyer [email protected] # V1.0 Creation use strict; use Getopt::Long; use Cwd; ############################################################################### # Process options ############################################################################### my $dir = ""; GetOptions("d=s" => $dir); die "Usage: $0 -d <install dir> <prefix>n" if (($dir eq '') || ($ARGV[0] eq '')); ############################################################################### # Variables definitions ############################################################################### our $prefix = $ARGV[0]; our $source_dir = "/home/oscommerce/cvs/"; my $admin_path = "/admin/admin/includes/application_top.php"; my $catalog_path = "/catalog/catalog/includes/application_top.php"; ############################################################################### # Process both files ############################################################################### process($admin_path); process($catalog_path); ############################################################################### # Process function ############################################################################### sub process { my $file = shift; open(IN, "<" . $source_dir . $file) or die "Can't open $file for reading.n"; open(OUT, ">" . $dir . $file) or die "Can't open $file for writing.n"; while (<IN>) { chomp; if (/define('TABLE_/) { s/^(.*')(.*');)$/$1$prefix$2/; print OUT $_ . "n"; } else { print OUT $_ . "n"; } } close(IN); close(OUT); } Christian Lescuyer Link to comment Share on other sites More sharing options...
Guest Posted February 26, 2003 Share Posted February 26, 2003 I took your script... ported my bash one to Perl, merged the two and added a few things to process the install database function. It does NOT process the upgrade file. Any comments suggestions? #!/usr/bin/perl # OSCommerce Table Prefix Botch Script # Paul Campbell 2003 <[email protected]> # (process function modified from code by Christian Lescuyer <[email protected]>) # Comments and suggestions to either of above or at # http://www.oscommerce.com/forums/ forum: "installation and configuration" # Requires UNIX command shell utils "unzip, basename, mv" # WARNING! DOES _NOT_ PROCESS UPGRADE FUNCTIONS # Preforms Tasks... # Unpack zip file # Copy out /admin/ and /catalog/ # process oscommerce.sql file # process application_top files # process db install functions # Constants my $sql_file = "/catalog/install/oscommerce.sql"; my $admin_top = "/admin/includes/application_top.php"; my $catalog_top = "/catalog/includes/application_top.php"; my $db_funcs = "/catalog/install/includes/functions/database.php"; # Get all values # HINT: place these one per line in txt file and use: # cat values.txt | this-script.pl # EG: # /mnt/source/oscommercems2.2.zip # /www/yourdomain.com # test_prefix_ print "Where is the ZIP?n"; $zip_file=<STDIN>; chomp( $zip_file ); print "Where do you want to install it?n"; our $install_dir=<STDIN>; chomp( $install_dir ); print "What is the table prefix you wish to insert?n"; our $prefix=<STDIN>; chomp( $prefix ); print "Unpacking $zip_file to $install_dir.....n"; print "If it exists it will be overwtritten.n"; `unzip -o $zip_file -d $install_dir`; $_=`basename $zip_file`; s/.zip//; $osc_dir=$install_dir."/".$_; chomp( $osc_dir ); # copying out catalog and admin print "Copying out catalog and admin from $osc_dir to $install_dirn"; $cmd="cp ".$osc_dir."/admin ".$install_dir."/ -R"; `$cmd`; $cmd="cp ".$osc_dir."/catalog ".$install_dir."/ -R"; `$cmd`; # Processing SQL file print "Processing $sql_file...n"; open( SQL_IN, "<" . $install_dir . $sql_file ) or die "Can't open ".$install_dir.$sql_file." for reading...n"; open( SQL_OUT, ">" . $install_dir . $sql_file.".tmp" ) or die "Can't open ".$install_dir.$sql_file.".tmp for writing...n"; while( <SQL_IN> ) { s/DROP TABLE IF EXISTS /DROP TABLE IF EXISTS $prefix/; s/CREATE TABLE /CREATE TABLE $prefix/; s/INSERT INTO /INSERT INTO $prefix/; print SQL_OUT; } close( SQL_IN ); close( SQL_OUT ); `mv $install_dir$sql_file.tmp $install_dir$sql_file`; process_top( $admin_top ); process_top( $catalog_top ); # process install db functions print "Processing $install_dir$db_funcs...n"; open( IN, "<".$install_dir.$db_funcs ) or die "Can't open $install_dir$db_funcs for reading."; open( OUT, ">".$install_dir.$db_funcs.".tmp" ) or die "Can't open $install_dir$db_funcs.tmp for writing."; while( <IN> ) { chomp; if ( /osc_db_query("drop table if exists/ ) { s/, /, $prefix/g; $new=$prefix."address_book"; s/address_book/$new/; print OUT $_."n"; } else { if ( /from configuration/ ) { s/from / $prefix/; print OUT $_."n"; } else { print OUT $_."n"; } } } close( IN ); close( OUT ); `mv $install_dir$db_funcs.tmp $install_dir$db_funcs`; # Functions. sub process_top { # Origin: OSCommerce forum | by Christian Lescuyer [email protected] # Modified: Paul Campbell <[email protected]> $file = shift; print "Processing $install_dir$file...n"; # Process application_top.php open( TOP_IN, "<" .$install_dir.$file ) or die "Can't open ".$install_dir.$file." for reading."; open( TOP_OUT, ">". $install_dir.$file.".tmp" ) or die "Can't open ".$install_dir.$file.".tmp for writing."; while( <TOP_IN> ) { chomp; if (/define('TABLE_/) { s/^(.*')(.*');)$/$1$prefix$2/; print TOP_OUT $_."n"; } else { print TOP_OUT $_."n"; } } close( TOP_IN ); close( TOP_OUT ); `mv $install_dir$file.tmp $install_dir$file`; } Link to comment Share on other sites More sharing options...
Christian Lescuyer Posted February 28, 2003 Share Posted February 28, 2003 Seems ok to me. No time to test it right now, though. Christian Lescuyer Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.