48 $this->_aTables = $aTables;
58 if (is_null($this->_aTables)) {
60 $aTables = array_unique($aMultilangTables);
74 $this->_aQueries = $aQueries;
94 $this->_aQueries[] = $sQuery;
105 $this->
init(
'oxshops');
107 if ($iMax = $this->
getConfig()->getConfigParam(
'iMaxShopId')) {
108 $this->setMaxShopId($iMax);
120 $this->_aMultiShopTables = $aMultiShopTables;
130 if (is_null($this->_aMultiShopTables)) {
131 $this->_aMultiShopTables = array();
146 public function generateViews($blMultishopInheritCategories =
false, $aMallInherit = null)
151 $this->_cleanInvalidViews();
164 protected function _getViewSelect($sTable, $iLang)
167 $oMetaData =
oxNew(
'oxDbMetaDataHandler');
168 $aFields = $oMetaData->getSinglelangFields($sTable, $iLang);
169 foreach ($aFields as $sCoreField => $sField) {
170 if ($sCoreField !== $sField) {
171 $aFields[$sCoreField] = $sField .
' AS ' . $sCoreField;
175 return implode(
',', $aFields);
185 protected function _getViewSelectMultilang($sTable)
190 $oMetaData =
oxNew(
'oxDbMetaDataHandler');
191 $aTables = array_merge(array($sTable), $oMetaData->getAllMultiTables($sTable));
192 foreach ($aTables as $sTableKey => $sTableName) {
193 $aTableFields = $oMetaData->getFields($sTableName);
194 foreach ($aTableFields as $sCoreField => $sField) {
195 if (!isset($aFields[$sCoreField])) {
196 $aFields[$sCoreField] = $sField;
201 return implode(
',', $aFields);
214 $oMetaData =
oxNew(
'oxDbMetaDataHandler');
215 $aTables = $oMetaData->getAllMultiTables($sTable);
216 if (count($aTables)) {
217 foreach ($aTables as $sTableKey => $sTableName) {
218 $sJoin .=
"LEFT JOIN {$sTableName} USING (OXID) ";
236 $sLangTable = getLangTableName($sTable, $iLang);
237 if ($sLangTable && $sLangTable !== $sTable) {
238 $sJoin .=
"LEFT JOIN {$sLangTable} USING (OXID) ";
252 return $this->oxshops__oxdefcat->value;
262 return (
bool) $this->oxshops__oxproductive->value;
268 protected function _cleanInvalidViews()
278 $aAllShopLanguages = $oLang->getAllShopLanguageIds();
281 $oViewsValidator =
oxNew(
'oxShopViewValidator');
283 $oViewsValidator->setShopId($this->
getId());
285 $oViewsValidator->setAllShopLanguages($aAllShopLanguages);
286 $oViewsValidator->setMultiLangTables($aMultilangTables);
287 $oViewsValidator->setMultiShopTables($aMultishopTables);
289 $aViews = $oViewsValidator->getInvalidViews();
291 foreach ($aViews as $sView) {
292 $oDb->execute(
'DROP VIEW IF EXISTS ' . $sView);
306 $iShopId = $this->
getId();
307 foreach ($aTables as $sTable) {
309 if (in_array($sTable, $aMultilangTables)) {
323 $sDefaultLangAddition =
'';
325 $sStart =
'CREATE OR REPLACE SQL SECURITY INVOKER VIEW';
332 $sLangAddition = $sLang === null ? $sDefaultLangAddition :
"_{$sLang}";
334 $sViewTable =
"oxv_{$sTable}{$sLangAddition}";
336 if ($sLang === null) {
337 $sFields = $this->_getViewSelectMultilang($sTable);
340 $sFields = $this->_getViewSelect($sTable, $iLang);
344 $sQuery =
"{$sStart} `{$sViewTable}` AS SELECT {$sFields} FROM {$sTable}{$sJoin}";
362 foreach ($aQueries as $sQuery) {
363 if (!$oDb->execute($sQuery)) {