Thanks for the offer, Julian, very kind of you. 
Unfortunately the list of hardcoded table names is huge. I have already made hundreds if not thousands of edits to queries, vardefs, relationship arrays etc. with hardcoded table references and probably have thousands to go. Yes, in some places $this->table_name is used, and it is nice to see, but there are also are a number of cases where code containing queries in classes is called without instantiating the object, requiring a global variable within the function. (e.g. all the build_generic_where_clause functions)
e.g.: (in Case.php)
Code:
function build_generic_where_clause ($the_query_string) {
global $sugar_config;
$tbl_prefix = $sugar_config['dbconfig']['db_prefix'];
$where_clauses = Array();
$the_query_string = PearDatabase::quote(from_html($the_query_string));
array_push($where_clauses, $tbl_prefix . "cases.name like '$the_query_string%'");
array_push($where_clauses, $tbl_prefix . "accounts.name like '$the_query_string%'");
if (is_numeric($the_query_string)) array_push($where_clauses, $tbl_prefix . "cases.case_number like '$the_query_string%'");
$the_where = "";
foreach($where_clauses as $clause)
{
if($the_where != "") $the_where .= " or ";
$the_where .= $clause;
}
if($the_where != ""){
$the_where = "(".$the_where.")";
}
return $the_where;
} There was also a case of it in Relationship.php that was called during the install without instantiating the object that I had fixed.
The approach I am taking basically is to put this code into the initialisation function of every class:
Code:
global $sugar_config;
$this->table_prefix = $sugar_config['dbconfig']['db_prefix'];
$this->table_name = $this->table_prefix . $this->table_name;
and in more complicated cases (E.g. Case.php):
Code:
global $sugar_config;
$this->table_prefix = $sugar_config['dbconfig']['db_prefix'];
$this->table_name = $this->table_prefix . $this->table_name;
$this->rel_account_table = $this->table_prefix . $this->rel_account_table;
$this->rel_contact_table = $this->table_prefix . $this->rel_contact_table;
$this->relationship_fields = Array('account_id'=> $this->table_prefix . 'account', 'bug_id' => $this->table_prefix . 'bugs',
'task_id'=> $this->table_prefix . 'tasks', 'note_id'=> $this->table_prefix . 'notes',
'meeting_id'=> $this->table_prefix . 'meetings', 'call_id'=> $this->table_prefix . 'calls', 'email_id'=> $this->table_prefix . 'emails',
); And edit all the hardcoded references in the class to its own table to {$this->table_name} and edit references to other tables in queries in the class by prepending {$this->table_prefix} to them. Many queries using joins require that fields from other tables include the table name, which must also include the prefix... (e.g. modules\Import\UsersLastImport.php has plenty of such queries)
Another non-table prefix related code problem just found:
#4) The double quotes in the comments in the string used in the copy of the write_array_to_file function in \modules\InboundEmail\parseEncoding.php (33) need to be escaped like so:
Code:
$the_string = "<?php\n" .
"\n
if(empty(\$GLOBALS['sugarEntry'])) die('Not A Valid Entry Point');
/*********************************************************************************
* The contents of this file are subject to the SugarCRM Public License Version
* 1.1.3 (\"License\"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
* Software distributed under the License is distributed on an \"AS IS\" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* All copies of the Covered Code must include on each user interface screen:
* (i) the \"Powered by SugarCRM\" logo and
* (ii) the SugarCRM copyright notice
* in the same form as they appear in the distribution. See full license for
* requirements.
*
* The Original Code is: SugarCRM Open Source
* The Initial Developer of the Original Code is SugarCRM, Inc.
* Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
* All Rights Reserved.
* Contributor(s): ______________________________________.
********************************************************************************/
/*********************************************************************************
* Description:
* Created On: Apr 22, 2006
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
* Reserved. Contributor(s): Chris Nojima
********************************************************************************/\n\n"
The approach you suggest for me to submit these occurrences to you for check-in is just not practical. Because of the way Sugar is written it is a major change to the codebase that affects just about every file.
Perhaps once complete I could run a diff between stock 4.5.0h files and my table prefix version and send that to you for check in, but I fear that I will be too far behind where 4.5.1 is now... 
EDIT: Basically, I have already done too many undocumented changes... I should have asked for CVS access before I started I guess. I suppose I research that now and see if I can get hooked up with CVS access and at least check out where the code is now and run a few diffs to figure out what I have to make a submission of the edits possible.
So far I have edited 146 files I only have to go over 2587 more files, assuming there is no database code in the themes (I haven't checked them yet). A list of the files I have edited so far is attached.
Bookmarks