52 $aRawFields =
oxDb::getDb()->MetaColumns($sTableName);
53 if (is_array($aRawFields)) {
54 foreach ($aRawFields as $oField) {
55 $aFields[$oField->name] =
"{$sTableName}.{$oField->name}";
72 $aTables = $oDb->getAll(
"show tables like " . $oDb->quote($sTableName));
74 return count($aTables) > 0;
87 $aTableFields = $this->
getFields($sTableName);
88 $sTableName = strtoupper($sTableName);
89 if (is_array($aTableFields)) {
90 $sFieldName = strtoupper($sFieldName);
91 $aTableFields = array_map(
'strtoupper', $aTableFields);
92 if (in_array(
"{$sTableName}.{$sFieldName}", $aTableFields)) {
131 foreach ($this->
getIndices($tableName) as $index) {
132 if ($indexName === $index[
'Column_name']) {
149 if (empty($this->_aTables)) {
153 foreach ($aTables as $aTableInfo) {
154 $sTableName = $aTableInfo[0];
156 $this->_aTables[] = $aTableInfo[0];
172 $aMLTables = array();
174 $sLangTableName = getLangTableName($sTable, $iLangId);
175 if ($sTable != $sLangTableName && !in_array($sLangTableName, $aMLTables)) {
176 $aMLTables[] = $sLangTableName;
194 $sTableSet = getLangTableName($sTable, $iLang);
196 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}");
197 $sSql =
"CREATE TABLE `{$sTableSet}` (" .
198 "`OXID` char(32) COLLATE latin1_general_ci NOT NULL, " .
199 "PRIMARY KEY (`OXID`)" .
200 ") " . strstr($aRes[0][1],
'ENGINE=');
216 public function getAddFieldSql($sTable, $sField, $sNewField, $sPrevField, $sTableSet = null)
219 $sTableSet = $sTable;
221 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}");
222 $sTableSql = $aRes[0][1];
225 $sTableSql = preg_replace(
'/COMMENT \\\'.*?\\\'/',
'', $sTableSql);
226 preg_match(
"/.*,\s+(['`]?" . preg_quote($sField,
'/') .
"['`]?\s+[^,]+),.*/", $sTableSql, $aMatch);
227 $sFieldSql = $aMatch[1];
230 if (!empty($sFieldSql)) {
231 $sFieldSql = preg_replace(
"/" . preg_quote($sField,
'/') .
"/", $sNewField, $sFieldSql);
232 $sSql =
"ALTER TABLE `$sTableSet` ADD " . $sFieldSql;
234 $sSql .=
" AFTER `$sPrevField`";
254 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}");
256 $sTableSql = $aRes[0][1];
258 preg_match_all(
"/([\w]+\s+)?\bKEY\s+(`[^`]+`)?\s*\([^)]+\)/iU", $sTableSql, $aMatch);
259 $aIndex = $aMatch[0];
261 $blUsingTableSet = $sTableSet ?
true :
false;
264 $sTableSet = $sTable;
267 $aIndexSql = array();
269 if (count($aIndex)) {
270 foreach ($aIndex as $sIndexSql) {
271 if (preg_match(
"/\([^)]*\b" . $sField .
"\b[^)]*\)/i", $sIndexSql)) {
274 $sIndexSql = preg_replace(
"/(.*\bKEY\s+)`[^`]+`/",
"$1", $sIndexSql);
276 if ($blUsingTableSet) {
278 $sIndexSql = preg_replace(
"/\([^\)]+\)/",
"(`$sNewField`)", $sIndexSql);
281 $sIndexSql = preg_replace(
"/\b" . $sField .
"\b/", $sNewField, $sIndexSql);
284 $aIndexSql[] =
"ADD " . $sIndexSql;
287 if (count($aIndexSql)) {
288 $aSql = array(
"ALTER TABLE `$sTableSet` " . implode(
", ", $aIndexSql));
303 if (isset($this->_iCurrentMaxLangId)) {
307 $sTable = $sTableSet =
"oxarticles";
308 $sField = $sFieldSet =
"oxtitle";
312 $sTableSet = getLangTableName($sTable, $iLang);
313 $sFieldSet = $sField .
'_' . $iLang;
316 $this->_iCurrentMaxLangId = --$iLang;
341 $aMultiLangFields = array();
343 foreach ($aFields as $sField) {
344 if (preg_match(
"/({$sTable}\.)?(?<field>.+)_1$/", $sField, $aMatches)) {
345 $aMultiLangFields[] = $aMatches[
'field'];
349 return $aMultiLangFields;
362 $sLangTable = getLangTableName($sTable, $iLang);
364 $aBaseFields = $this->
getFields($sTable);
365 $aLangFields = $this->
getFields($sLangTable);
370 $aFields = array_merge($aBaseFields, $aLangFields);
371 $aSingleLangFields = array();
373 foreach ($aFields as $sFieldName => $sField) {
374 if (preg_match(
"/(({$sTable}|{$sLangTable})\.)?(?<field>.+)_(?<lang>[0-9]+)$/", $sField, $aMatches)) {
375 if ($aMatches[
'lang'] == $iLang) {
376 $aSingleLangFields[$aMatches[
'field']] = $sField;
379 $aSingleLangFields[$sFieldName] = $sField;
383 return $aSingleLangFields;
409 $iLangId = (int) $iLangId;
411 if ($iLangId === 0) {
418 if (is_array($aFields) && count($aFields) > 0) {
419 foreach ($aFields as $sFieldName) {
420 $sFieldName = $sFieldName .
"_" . $iLangId;
422 if ($this->
fieldExists($sFieldName, $sTableName)) {
424 $aSql[] =
"UPDATE {$sTableName} SET {$sFieldName} = DEFAULT;";
441 $this->_iCurrentMaxLangId = null;
445 foreach ($aTable as $sTableName) {
463 if ((
int) $iLangId === 0) {
470 foreach ($this->_aSkipTablesOnReset as $sSkipTable) {
472 if (($iSkipId = array_search($sSkipTable, $aTables)) !==
false) {
473 unset($aTables[$iSkipId]);
477 foreach ($aTables as $sTableName) {
491 if (is_array($aSql) && !empty($aSql)) {
492 foreach ($aSql as $sSql) {
495 $oDb->execute($sSql);
517 $aShops = $oDb->getAll(
"select * from oxshops");
519 $aTables = $aTables ? $aTables : $oConfig->getConfigParam(
'aMultiShopTables');
522 foreach ($aShops as $aShop) {
523 $sShopId = $aShop[0];
524 $oShop =
oxNew(
'oxshop');
525 $oShop->load($sShopId);
526 $oShop->setMultiShopTables($aTables);
527 $aMallInherit = array();
528 foreach ($aTables as $sTable) {
529 $aMallInherit[$sTable] = $oConfig->getShopConfVar(
'blMallInherit_' . $sTable, $sShopId);
531 if (!$oShop->generateViews(
false, $aMallInherit) && $bSuccess) {
549 foreach ($this->aForceOriginalFields as $aFieldname) {
550 if (array_key_exists($aFieldname, $aFields)) {
551 unset($aFields[$aFieldname]);
566 $aMultiLanguageTables = $this->
getConfig()->getConfigParam(
'aMultiLangTables');
568 if (!is_array($aMultiLanguageTables) || empty($aMultiLanguageTables)) {
572 foreach ($aMultiLanguageTables as $sTable) {
577 for ($i=1;$i<=$iMaxLang;$i++) {
596 $sTableSet = getLangTableName($sTable, $iLanguageId);
601 if (is_array($aFields) && count($aFields) > 0) {
602 foreach ($aFields as $sField) {
603 $sNewFieldName = $sField .
"_" . $iLanguageId;
604 if ($iLanguageId > 1) {
605 $iPrevLang = $iLanguageId - 1;
606 $sPrevField = $sField .
'_' . $iPrevLang;
608 $sPrevField = $sField;
614 $aSql[] = $this->
getAddFieldSql($sTable, $sField, $sNewFieldName, $sPrevField, $sTableSet);
617 $aSql = array_merge($aSql, (array) $this->
getAddFieldIndexSql($sTable, $sField, $sNewFieldName, $sTableSet));