45 $aRawFields =
oxDb::getDb()->MetaColumns($sTableName);
46 if (is_array($aRawFields)) {
47 foreach ($aRawFields as $oField) {
48 $aFields[$oField->name] =
"{$sTableName}.{$oField->name}";
65 $aTables = $oDb->getAll(
"show tables like " . $oDb->quote($sTableName));
67 return count($aTables) > 0;
80 $aTableFields = $this->
getFields($sTableName);
81 $sTableName = strtoupper($sTableName);
82 if (is_array($aTableFields)) {
83 $sFieldName = strtoupper($sFieldName);
84 $aTableFields = array_map(
'strtoupper', $aTableFields);
85 if (in_array(
"{$sTableName}.{$sFieldName}", $aTableFields)) {
102 if (empty($this->_aTables)) {
106 foreach ($aTables as $aTableInfo) {
107 $sTableName = $aTableInfo[0];
109 $this->_aTables[] = $aTableInfo[0];
125 $aMLTables = array();
127 $sLangTableName = getLangTableName($sTable, $iLangId);
128 if ($sTable != $sLangTableName && !in_array($sLangTableName, $aMLTables)) {
129 $aMLTables[] = $sLangTableName;
147 $sTableSet = getLangTableName($sTable, $iLang);
149 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}");
150 $sSql =
"CREATE TABLE `{$sTableSet}` (" .
151 "`OXID` char(32) COLLATE latin1_general_ci NOT NULL, " .
152 "PRIMARY KEY (`OXID`)" .
153 ") " . strstr($aRes[0][1],
'ENGINE=');
169 public function getAddFieldSql($sTable, $sField, $sNewField, $sPrevField, $sTableSet = null)
172 $sTableSet = $sTable;
174 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}");
175 $sTableSql = $aRes[0][1];
178 $sTableSql = preg_replace(
'/COMMENT \\\'.*?\\\'/',
'', $sTableSql);
179 preg_match(
"/.*,\s+(['`]?" . preg_quote($sField,
'/') .
"['`]?\s+[^,]+),.*/", $sTableSql, $aMatch);
180 $sFieldSql = $aMatch[1];
183 if (!empty($sFieldSql)) {
184 $sFieldSql = preg_replace(
"/" . preg_quote($sField,
'/') .
"/", $sNewField, $sFieldSql);
185 $sSql =
"ALTER TABLE `$sTableSet` ADD " . $sFieldSql;
187 $sSql .=
" AFTER `$sPrevField`";
207 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}");
209 $sTableSql = $aRes[0][1];
211 preg_match_all(
"/([\w]+\s+)?\bKEY\s+(`[^`]+`)?\s*\([^)]+\)/iU", $sTableSql, $aMatch);
212 $aIndex = $aMatch[0];
214 $blUsingTableSet = $sTableSet ?
true :
false;
217 $sTableSet = $sTable;
220 $aIndexSql = array();
222 if (count($aIndex)) {
223 foreach ($aIndex as $sIndexSql) {
224 if (preg_match(
"/\([^)]*\b" . $sField .
"\b[^)]*\)/i", $sIndexSql)) {
227 $sIndexSql = preg_replace(
"/(.*\bKEY\s+)`[^`]+`/",
"$1", $sIndexSql);
229 if ($blUsingTableSet) {
231 $sIndexSql = preg_replace(
"/\([^\)]+\)/",
"(`$sNewField`)", $sIndexSql);
234 $sIndexSql = preg_replace(
"/\b" . $sField .
"\b/", $sNewField, $sIndexSql);
237 $aIndexSql[] =
"ADD " . $sIndexSql;
240 if (count($aIndexSql)) {
241 $aSql = array(
"ALTER TABLE `$sTableSet` " . implode(
", ", $aIndexSql));
256 if (isset($this->_iCurrentMaxLangId)) {
260 $sTable = $sTableSet =
"oxarticles";
261 $sField = $sFieldSet =
"oxtitle";
265 $sTableSet = getLangTableName($sTable, $iLang);
266 $sFieldSet = $sField .
'_' . $iLang;
269 $this->_iCurrentMaxLangId = --$iLang;
294 $aMultiLangFields = array();
296 foreach ($aFields as $sField) {
297 if (preg_match(
"/({$sTable}\.)?(?<field>.+)_1$/", $sField, $aMatches)) {
298 $aMultiLangFields[] = $aMatches[
'field'];
302 return $aMultiLangFields;
315 $sLangTable = getLangTableName($sTable, $iLang);
317 $aBaseFields = $this->
getFields($sTable);
318 $aLangFields = $this->
getFields($sLangTable);
319 $aFields = array_merge($aLangFields, $aBaseFields);
320 $aSingleLangFields = array();
322 foreach ($aFields as $sFieldName => $sField) {
323 if (preg_match(
"/(({$sTable}|{$sLangTable})\.)?(?<field>.+)_(?<lang>[0-9]+)$/", $sField, $aMatches)) {
324 if ($aMatches[
'lang'] == $iLang) {
325 $aSingleLangFields[$aMatches[
'field']] = $sField;
328 $aSingleLangFields[$sFieldName] = $sField;
332 return $aSingleLangFields;
348 $sTableSet = getLangTableName($sTable, $iNewLang);
353 if (is_array($aFields) && count($aFields) > 0) {
354 foreach ($aFields as $sField) {
355 $sNewFieldName = $sField .
"_" . $iNewLang;
357 $iPrevLang = $iNewLang - 1;
358 $sPrevField = $sField .
'_' . $iPrevLang;
360 $sPrevField = $sField;
366 $aSql[] = $this->
getAddFieldSql($sTable, $sField, $sNewFieldName, $sPrevField, $sTableSet);
369 $aSql = array_merge($aSql, (array) $this->
getAddFieldIndexSql($sTable, $sField, $sNewFieldName, $sTableSet));
388 $iLangId = (int) $iLangId;
390 if ($iLangId === 0) {
397 if (is_array($aFields) && count($aFields) > 0) {
398 foreach ($aFields as $sFieldName) {
399 $sFieldName = $sFieldName .
"_" . $iLangId;
401 if ($this->
fieldExists($sFieldName, $sTableName)) {
403 $aSql[] =
"UPDATE {$sTableName} SET {$sFieldName} = DEFAULT;";
420 $this->_iCurrentMaxLangId = null;
424 foreach ($aTable as $sTableName) {
442 if ((
int) $iLangId === 0) {
449 foreach ($this->_aSkipTablesOnReset as $sSkipTable) {
451 if (($iSkipId = array_search($sSkipTable, $aTables)) !==
false) {
452 unset($aTables[$iSkipId]);
456 foreach ($aTables as $sTableName) {
470 if (is_array($aSql) && !empty($aSql)) {
471 foreach ($aSql as $sSql) {
474 $oDb->execute($sSql);
494 $aShops = $oDb->getAll(
"select * from oxshops");
496 $aTables = $aTables ? $aTables : $oConfig->getConfigParam(
'aMultiShopTables');
499 foreach ($aShops as $aShop) {
500 $sShopId = $aShop[0];
501 $oShop =
oxNew(
'oxshop');
502 $oShop->load($sShopId);
503 $oShop->setMultiShopTables($aTables);
504 $aMallInherit = array();
505 foreach ($aTables as $sTable) {
506 $aMallInherit[$sTable] = $oConfig->getShopConfVar(
'blMallInherit_' . $sTable, $sShopId);
508 if (!$oShop->generateViews(
false, $aMallInherit) && $bSuccess) {