Commit a52cf400 by Scott Vivian

Fix issue with capitalized table prefixes in plugins

The init_queries plugin function now receives table names in original case.
Potentially breaking change if qa_db_add_table_prefix is manually wrapped with strtolower, however, I have not found any code in the wild that would break from this change.
Q2A core code also now using case-sensitive comparisons (there were several instances of tables not being normalized anyway).
Fixes #45.
parent 5b93f9e2
......@@ -532,17 +532,12 @@
}
function qa_array_to_lower_keys($array)
function qa_array_to_keys($array)
/*
Return $array with all keys converted to lower case
Return array with all values from $array as keys
*/
{
$keyarray=array();
foreach ($array as $value)
$keyarray[strtolower($value)]=true;
return $keyarray;
return array_combine($array, array_fill(0, count($array), true));
}
......@@ -551,12 +546,12 @@
Return a list of tables missing from the database, [table name] => [column/index definitions]
*/
{
$keydbtables=qa_array_to_lower_keys(qa_db_list_tables());
$keydbtables=qa_array_to_keys(qa_db_list_tables());
$missing=array();
foreach ($definitions as $rawname => $definition)
if (!isset($keydbtables[strtolower(qa_db_add_table_prefix($rawname))]))
if (!isset($keydbtables[qa_db_add_table_prefix($rawname)]))
$missing[$rawname]=$definition;
return $missing;
......@@ -568,12 +563,12 @@
Return a list of columns missing from $table in the database, given the full definition set in $definition
*/
{
$keycolumns=qa_array_to_lower_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^'.$table)));
$keycolumns=qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^'.$table)));
$missing=array();
foreach ($definition as $colname => $coldefn)
if ( (!is_int($colname)) && !isset($keycolumns[strtolower($colname)]) )
if ( (!is_int($colname)) && !isset($keycolumns[$colname]) )
$missing[$colname]=$coldefn;
return $missing;
......@@ -738,10 +733,10 @@
// Write-lock all Q2A tables before we start so no one can read or write anything
$keydbtables=qa_array_to_lower_keys(qa_db_list_tables());
$keydbtables=qa_array_to_keys(qa_db_list_tables());
foreach ($definitions as $rawname => $definition)
if (isset($keydbtables[strtolower(qa_db_add_table_prefix($rawname))]))
if (isset($keydbtables[qa_db_add_table_prefix($rawname)]))
$locks[]='^'.$rawname.' WRITE';
$locktablesquery='LOCK TABLES '.implode(', ', $locks);
......@@ -1027,7 +1022,7 @@
// Up to here: Version 1.4 developer preview
case 25:
$keycolumns=qa_array_to_lower_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^blobs')));
$keycolumns=qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^blobs')));
// might be using blobs table shared with another installation, so check if we need to upgrade
if (isset($keycolumns['filename']))
......@@ -1108,7 +1103,7 @@
case 34:
if (!QA_FINAL_EXTERNAL_USERS) {
$keytables=qa_array_to_lower_keys(qa_db_read_all_values(qa_db_query_sub('SHOW TABLES')));
$keytables=qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW TABLES')));
// might be using messages table shared with another installation, so check if we need to upgrade
if (isset($keytables[qa_db_add_table_prefix('messages')]))
......@@ -1305,7 +1300,7 @@
case 48:
if (!QA_FINAL_EXTERNAL_USERS) {
$keycolumns=qa_array_to_lower_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^messages')));
$keycolumns=qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^messages')));
// might be using messages table shared with another installation, so check if we need to upgrade
if (isset($keycolumns['type']))
......@@ -1332,7 +1327,7 @@
case 51:
if (!QA_FINAL_EXTERNAL_USERS) {
$keycolumns=qa_array_to_lower_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^userfields')));
$keycolumns=qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^userfields')));
// might be using userfields table shared with another installation, so check if we need to upgrade
if (isset($keycolumns['permit']))
......@@ -1347,7 +1342,7 @@
case 52:
if (!QA_FINAL_EXTERNAL_USERS) {
$keyindexes=qa_array_to_lower_keys(qa_db_read_all_assoc(qa_db_query_sub('SHOW INDEX FROM ^users'), null, 'Key_name'));
$keyindexes=qa_array_to_keys(qa_db_read_all_assoc(qa_db_query_sub('SHOW INDEX FROM ^users'), null, 'Key_name'));
if (isset($keyindexes['created']))
qa_db_upgrade_progress('Skipping upgrading users table since it was already upgraded by another Q2A site sharing it.');
......@@ -1387,7 +1382,7 @@
case 55:
if (!QA_FINAL_EXTERNAL_USERS) {
$keycolumns=qa_array_to_lower_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^users')));
$keycolumns=qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^users')));
// might be using messages table shared with another installation, so check if we need to upgrade
if (isset($keycolumns['wallposts']))
......@@ -1412,7 +1407,7 @@
case 57:
if (!QA_FINAL_EXTERNAL_USERS) {
// might be using messages table shared with another installation, so check if we need to upgrade
$keycolumns = qa_array_to_lower_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^messages')));
$keycolumns = qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^messages')));
if (isset($keycolumns['fromhidden']))
qa_db_upgrade_progress('Skipping upgrading messages table since it was already upgraded by another Q2A site sharing it.');
......
......@@ -403,7 +403,8 @@
function qa_db_list_tables_lc()
/*
Return an array of the names of all tables in the Q2A database, converted to lower case
Return an array of the names of all tables in the Q2A database, converted to lower case.
No longer used by Q2A and shouldn't be needed.
*/
{
return array_map('strtolower', qa_db_list_tables());
......
......@@ -149,7 +149,7 @@
$module=qa_load_module($moduletype, $modulename);
$queries=$module->init_queries(qa_db_list_tables_lc());
$queries=$module->init_queries(qa_db_list_tables());
if (!empty($queries)) {
if (!is_array($queries))
......@@ -243,7 +243,7 @@
$buttons=array('super' => 'Create Super Administrator');
} else {
$tables=qa_db_list_tables_lc();
$tables=qa_db_list_tables();
$moduletypes=qa_list_module_types();
......
......@@ -42,7 +42,7 @@
$pluginoptionmodules = array();
$tables = qa_db_list_tables_lc();
$tables = qa_db_list_tables();
$moduletypes = qa_list_module_types();
foreach ($moduletypes as $type) {
......
......@@ -26,12 +26,12 @@
class qa_event_logger {
public function init_queries($tableslc)
public function init_queries($table_list)
{
if (qa_opt('event_logger_to_database')) {
$tablename=qa_db_add_table_prefix('eventlog');
if (!in_array($tablename, $tableslc)) {
if (!in_array($tablename, $table_list)) {
require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-db-maxima.php';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment