44 $aRawFields =
oxDb::getDb()->MetaColumns( $sTableName );
45 if (is_array($aRawFields)) {
46 foreach ( $aRawFields as $oField ) {
47 $aFields[] = $oField->name;
63 $aTables = $oDb->getAll(
"show tables like ". $oDb->quote($sTableName));
64 return count($aTables) > 0;
77 $aTableFields = $this->
getFields( $sTableName );
79 if ( is_array($aTableFields) ) {
80 $sFieldName = strtoupper( $sFieldName );
81 $aTableFields = array_map(
'strtoupper', $aTableFields);
82 if ( in_array( $sFieldName, $aTableFields ) ) {
99 if ( empty($this->_aTables) ) {
103 foreach ( $aTables as $aTableInfo) {
104 $sTableName = $aTableInfo[0];
106 $this->_aTables[] = $aTableInfo[0];
121 $aMLTables = array();
123 $sLangTableName = getLangTableName($sTable, $iLangId );
124 if ($sTable != $sLangTableName && !in_array($sLangTableName, $aMLTables)) {
125 $aMLTables[] = $sLangTableName;
142 $sTableSet = getLangTableName($sTable, $iLang);
144 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}" );
145 $sSql =
"CREATE TABLE `{$sTableSet}` (".
146 "`OXID` char(32) COLLATE latin1_general_ci NOT NULL, ".
147 "PRIMARY KEY (`OXID`)".
148 ") ".strstr($aRes[0][1],
'ENGINE=');
163 public function getAddFieldSql( $sTable, $sField, $sNewField, $sPrevField, $sTableSet = null )
166 $sTableSet = $sTable;
168 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}" );
169 $sTableSql = $aRes[0][1];
172 $sTableSql = preg_replace(
'/COMMENT \\\'.*?\\\'/',
'', $sTableSql);
173 preg_match(
"/.*,\s+(['`]?".preg_quote($sField,
'/').
"['`]?\s+[^,]+),.*/", $sTableSql, $aMatch );
174 $sFieldSql = $aMatch[1];
177 if ( !empty($sFieldSql) ) {
178 $sFieldSql = preg_replace(
"/".preg_quote($sField,
'/').
"/", $sNewField, $sFieldSql );
179 $sSql =
"ALTER TABLE `$sTableSet` ADD " . $sFieldSql;
181 $sSql .=
" AFTER `$sPrevField`";
201 $aRes =
oxDb::getDb()->getAll(
"show create table {$sTable}" );
203 $sTableSql = $aRes[0][1];
205 preg_match_all(
"/([\w]+\s+)?\bKEY\s+(`[^`]+`)?\s*\([^)]+\)/iU", $sTableSql, $aMatch);
206 $aIndex = $aMatch[0];
208 $blUsingTableSet = $sTableSet ?
true :
false;
211 $sTableSet = $sTable;
214 $aIndexSql = array();
216 if ( count($aIndex) ) {
217 foreach ( $aIndex as $sIndexSql ) {
218 if ( preg_match(
"/\([^)]*\b" . $sField .
"\b[^)]*\)/i", $sIndexSql ) ) {
221 $sIndexSql = preg_replace(
"/(.*\bKEY\s+)`[^`]+`/",
"$1", $sIndexSql );
223 if ( $blUsingTableSet ) {
225 $sIndexSql = preg_replace(
"/\([^\)]+\)/",
"(`$sNewField`)", $sIndexSql );
228 $sIndexSql = preg_replace(
"/\b" . $sField .
"\b/", $sNewField, $sIndexSql );
231 $aIndexSql[] =
"ADD ". $sIndexSql;
234 if ( count($aIndexSql) ) {
235 $aSql = array(
"ALTER TABLE `$sTableSet` ".implode(
", ", $aIndexSql));
250 if ( isset($this->_iCurrentMaxLangId) ) {
254 $sTable = $sTableSet =
"oxarticles";
255 $sField = $sFieldSet =
"oxtitle";
259 $sTableSet = getLangTableName($sTable, $iLang);
260 $sFieldSet = $sField.
'_'.$iLang;
263 $this->_iCurrentMaxLangId = --$iLang;
287 $aMultiLangFields = array();
289 foreach ( $aFields as $sField ) {
290 if ( preg_match(
"/(.+)_1$/", $sField, $aMatches) ) {
291 $aMultiLangFields[] = $aMatches[1];
295 return $aMultiLangFields;
308 $aFields = array_merge($this->
getFields( $sTable ), $this->
getFields(getLangTableName($sTable, $iLang) ));
309 $aSingleLangFields = array();
311 foreach ( $aFields as $sField ) {
312 if ( preg_match(
"/(.+)_([0-9]+)$/", $sField, $aMatches) ) {
313 if ($aMatches[2] == $iLang) {
314 $aSingleLangFields[$aMatches[1]] = $sField;
317 $aSingleLangFields[$sField] = $sField;
321 return $aSingleLangFields;
339 $sTableSet = getLangTableName($sTable, $iNewLang);
344 if ( is_array($aFields) && count($aFields) > 0 ) {
345 foreach ( $aFields as $sField ) {
346 $sNewFieldName = $sField .
"_" . $iNewLang;
348 $iPrevLang = $iNewLang-1;
349 $sPrevField = $sField.
'_'.$iPrevLang;
351 $sPrevField = $sField;
357 $aSql[] = $this->
getAddFieldSql( $sTable, $sField, $sNewFieldName, $sPrevField, $sTableSet );
360 $aSql = array_merge($aSql, (array) $this->
getAddFieldIndexSql($sTable, $sField, $sNewFieldName, $sTableSet));
379 $iLangId = (int)$iLangId;
381 if ( $iLangId === 0 ) {
388 if ( is_array($aFields) && count($aFields) > 0 ) {
389 foreach ( $aFields as $sFieldName ) {
390 $sFieldName = $sFieldName .
"_" . $iLangId;
392 if ( $this->
fieldExists( $sFieldName, $sTableName ) ) {
394 $aSql[] =
"UPDATE {$sTableName} SET {$sFieldName} = DEFAULT;";
399 if ( !empty($aSql) ) {
413 $this->_iCurrentMaxLangId = null;
417 foreach ( $aTable as $sTableName ) {
435 if ( (
int)$iLangId === 0 ) {
442 foreach ( $this->_aSkipTablesOnReset as $sSkipTable ) {
444 if ( ($iSkipId = array_search( $sSkipTable, $aTables )) !==
false ) {
445 unset( $aTables[$iSkipId] );
449 foreach ( $aTables as $sTableName ) {
465 if ( is_array($aSql) && !empty($aSql) ) {
466 foreach ( $aSql as $sSql) {
469 $oDb->execute( $sSql );
489 $aShops = $oDb->getAll(
"select * from oxshops" );
491 $aTables = $aTables ? $aTables : $oConfig->getConfigParam(
'aMultiShopTables' );
494 foreach ( $aShops as $aShop ) {
495 $sShopId = $aShop[0];
496 $oShop =
oxNew(
'oxshop' );
497 $oShop->load( $sShopId );
498 $oShop->setMultiShopTables( $aTables );
499 $blMultishopInherit = $oConfig->getShopConfVar(
'blMultishopInherit_oxcategories', $sShopId );
500 $aMallInherit = array();
501 foreach ( $aTables as $sTable ) {
502 $aMallInherit[$sTable] = $oConfig->getShopConfVar(
'blMallInherit_' . $sTable, $sShopId );
504 if ( !$oShop->generateViews( $blMultishopInherit, $aMallInherit ) && $bSuccess ) {