cubrid-cms / joomla-cubrid

This repository is for joomla CMS based on CUBRID Database
GNU General Public License v2.0
0 stars 6 forks source link

Correcting errors during making a sample site after installation of joomla cms #4

Open cubrid-admin opened 6 years ago

cubrid-admin commented 6 years ago

Installation이 완료된 후 샘플 사이트를 만드는 과정에서 많은 오류가 발견될 것입니다.

이 오류 원인의 대부분은 cubrid에서 처리할 수 없는 sql이 사용되기 때문입니다. joomla의 php 파일들에 포함된 sql에서 cubrid가 처리하지 못하는 sql을 찾아내어 처리가 가능하도록 수정하는 작업이 본 이슈의 해결 방안입니다.

힌트를 한가지 드립니다.

cubrid의 sql 처리 방식에서 table이름과 column 이름에 keyword 혹은 reserved word가 사용될 수 없습니다.

SELECT `folder` AS `type`,`element` AS `name`,`params` AS `params`,`extension_id` AS `id` FROM jml_extensions WHERE enabled = 1 AND type = 'plugin' AND state IN (0,1) AND access IN (1,1,5) ORDER BY ordering

위 query는 syntax 오류가 발생하는 전형적이 예입니다. access는 keyword인데 column 이름으로 사용되고 있습니다.

cubrid-admin commented 6 years ago

우선 아래 query가 포함된 php파일을 찾아 수정해 보시기 바랍니다.

SELECT `folder` AS `type`,`element` AS `name`,`params` AS `params`,`extension_id` AS `id` FROM jml_extensions WHERE enabled = 1 AND type = 'plugin' AND state IN (0,1) AND access IN (1,1,5) ORDER BY ordering

수정할 때 해당 keyword column 이름에 $db->quoteName(keyword-column-name)을 활용하시기 바랍니다.

quoteName은 database driver에 포함되어 있는 함수로 미리 정의된 "`"를 해당 string에 quoting하는 기능입니다. cubrid에서는 "`"나 "[, ]"을 keyword와 id를 구분하기 위해 사용합니다.

1차 수정된 파일을 commit해서 올리면 확인해 보겠습니다.

cubrid-admin commented 6 years ago

Location: libraries\src\Plugin

PluginHelper.php

$db = \JFactory::getDbo(); $query = $db->getQuery(true) ->select( $db>quoteName( array( 'folder', 'element', 'params', 'extension_id' ), array( 'type', 'name', 'params', 'id' ) ) ) ->from('#__extensions') ->where('enabled = 1') ->where('type = ' . $db>quote('plugin')) ->where('state IN (0,1)') ->where('access IN (' . $levels . ')') ->order('ordering');

$db>setQuery($query);

generated query is as followings:

SELECT `folder` AS `type`,`element` AS `name`,`params` AS `params`,`extension_id` AS `id` FROM jml_extensions WHERE enabled = 1 AND type = 'plugin' AND state IN (0,1) AND access IN (1,1,5) ORDER BY ordering

In WHERE clause of this query, "access IN (1,1,5)" has a reserved word 'access', so the query can't be processed.

cubrid-admin commented 6 years ago

Several columns are found with column names that belong to the keyword in Joomla's database schema. They are as followings:

access action comment count data file header key language level module name object password position priority string table time value

These column names are used in many SQL's on Joomla's php source code. So we have to change to use qualified name with back quote " ` " on php code.

cubrid-admin commented 6 years ago

This file is the result of the following shell script for finding keyword as column names on Joomla's php files.

grep -R -w 'access|action|comment|count|data|file|header|key|language|level|module|name|object|password|position|priority|string|table|time|value' --exclude -dir=tests --include=.php | grep select > keyword-column-sql.txt grep -R -w 'access|action|comment|count|data|file|header|key|language|level|module|name|object|password|position|priority|string|table|time|value' --exclude -dir=tests --include=.php | grep where >> keyword-column-sql.txt

grep -R -w 'access|action|comment|count|data|file|header|key|language|level|module|name|object|password|position|priority|string|table|time|value' --exclude -dir=tests --include=*.php | grep order >> keyword-column-sql.txt

grep -R -w 'access|action|comment|count|data|file|header|key|language|level|module|name|object|password|position|priority|string|table|time|value' --exclude -dir=tests --include=*.php | grep group >> keyword-column-sql.txt

grep -R -w 'access|action|comment|count|data|file|header|key|language|level|module|name|object|password|position|priority|string|table|time|value' --exclude -dir=tests --include=*.php | grep having >> keyword-column-sql.txt

grep -R -w 'access|action|comment|count|data|file|header|key|language|level|module|name|object|password|position|priority|string|table|time|value' --exclude -dir=tests --include=*.php | grep set >> keyword-column-sql.txt

keyowrd-column might be used at the following location of a query:

'select' clause 'where' clause 'order by' clause 'group by' clause 'set' clause in Update Query The above shell script includes all of cases in being used as keyword-column in Select and Update query.

As the result, about 106 lines in 83 files using the keywords as column names are found on Joomla's php.