inserts articles into heaptable

@param string $sHeapTable heap table name
@param string $sCatAdd    category id filter (part of sql)

@return bool
555897
protected function _insertArticles($sHeapTable, $sCatAdd)
    {
        $oDB = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        $iExpLang = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("iExportLanguage");
        if (!isset($iExpLang)) {
            $iExpLang = \OxidEsales\Eshop\Core\Registry::getSession()->getVariable("iExportLanguage");
        }

        $oArticle = oxNew(\OxidEsales\Eshop\Application\Model\Article::class);
        $oArticle->setLanguage($iExpLang);

        $sO2CView = getViewName('oxobject2category', $iExpLang);
        $sArticleTable = getViewName("oxarticles", $iExpLang);

        $insertQuery = "insert into {$sHeapTable} select {$sArticleTable}.oxid from {$sArticleTable}, {$sO2CView} as oxobject2category where ";
        $insertQuery .= $oArticle->getSqlActiveSnippet();

        if (!\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("blExportVars")) {
            $insertQuery .= " and {$sArticleTable}.oxid = oxobject2category.oxobjectid and {$sArticleTable}.oxparentid = '' ";
        } else {
            $insertQuery .= " and ( {$sArticleTable}.oxid = oxobject2category.oxobjectid or {$sArticleTable}.oxparentid = oxobject2category.oxobjectid ) ";
        }

        $sSearchString = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("search");
        if (isset($sSearchString)) {
            $insertQuery .= "and ( {$sArticleTable}.OXTITLE like " . $oDB->quote("%{$sSearchString}%");
            $insertQuery .= " or {$sArticleTable}.OXSHORTDESC like " . $oDB->quote("%$sSearchString%");
            $insertQuery .= " or {$sArticleTable}.oxsearchkeys like " . $oDB->quote("%$sSearchString%") . " ) ";
        }

        if ($sCatAdd) {
            $insertQuery .= $sCatAdd;
        }

        // add minimum stock value
        if (\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('blUseStock') && ($dMinStock = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("sExportMinStock"))) {
            $dMinStock = str_replace([";", " ", "/", "'"], "", $dMinStock);
            $insertQuery .= " and {$sArticleTable}.oxstock >= " . $oDB->quote($dMinStock);
        }

        $insertQuery .= " group by {$sArticleTable}.oxid";

        return $oDB->execute($insertQuery) ? true : false;
    }
894367
public function insert($insertData) {
		$this->provider('cache')->cacheClear('db', $this->getDao()->getTableName());
        $obj = $this->getConnection();
        $obj->insert($this->getDao()->getTableName(), $insertData);
        return $obj->count;
	}
981196
public function arr2xmldb_table($xmlarr) {

        global $CFG;

        $result = true;

        // Debug the table
        // traverse_xmlize($xmlarr);                   //Debug
        // print_object ($GLOBALS['traverse_array']);  //Debug
        // $GLOBALS['traverse_array']="";              //Debug

        // Process table attributes (name, comment, previoustable and nexttable)
        if (isset($xmlarr['@']['NAME'])) {
            $this->name = trim($xmlarr['@']['NAME']);
        } else {
            $this->errormsg = 'Missing NAME attribute';
            $this->debug($this->errormsg);
            $result = false;
        }
        if (isset($xmlarr['@']['COMMENT'])) {
            $this->comment = trim($xmlarr['@']['COMMENT']);
        } else if (!empty($CFG->xmldbdisablecommentchecking)) {
            $this->comment = '';
        } else {
            $this->errormsg = 'Missing COMMENT attribute';
            $this->debug($this->errormsg);
            $result = false;
        }

        // Iterate over fields
        if (isset($xmlarr['#']['FIELDS']['0']['#']['FIELD'])) {
            foreach ($xmlarr['#']['FIELDS']['0']['#']['FIELD'] as $xmlfield) {
                if (!$result) { //Skip on error
                    continue;
                }
                $name = trim($xmlfield['@']['NAME']);
                $field = new xmldb_field($name);
                $field->arr2xmldb_field($xmlfield);
                $this->fields[] = $field;
                if (!$field->isLoaded()) {
                    $this->errormsg = 'Problem loading field ' . $name;
                    $this->debug($this->errormsg);
                    $result = false;
                }
            }
        } else {
            $this->errormsg = 'Missing FIELDS section';
            $this->debug($this->errormsg);
            $result = false;
        }

        // Perform some general checks over fields
        if ($result && $this->fields) {
            // Check field names are ok (lowercase, a-z _-)
            if (!$this->checkNameValues($this->fields)) {
                $this->errormsg = 'Some FIELDS name values are incorrect';
                $this->debug($this->errormsg);
                $result = false;
            }
            // Compute prev/next.
            $this->fixPrevNext($this->fields);
            // Order fields
            if ($result && !$this->orderFields($this->fields)) {
                $this->errormsg = 'Error ordering the fields';
                $this->debug($this->errormsg);
                $result = false;
            }
        }

        // Iterate over keys
        if (isset($xmlarr['#']['KEYS']['0']['#']['KEY'])) {
            foreach ($xmlarr['#']['KEYS']['0']['#']['KEY'] as $xmlkey) {
                if (!$result) { //Skip on error
                    continue;
                }
                $name = trim($xmlkey['@']['NAME']);
                $key = new xmldb_key($name);
                $key->arr2xmldb_key($xmlkey);
                $this->keys[] = $key;
                if (!$key->isLoaded()) {
                    $this->errormsg = 'Problem loading key ' . $name;
                    $this->debug($this->errormsg);
                    $result = false;
                }
            }
        } else {
            $this->errormsg = 'Missing KEYS section (at least one PK must exist)';
            $this->debug($this->errormsg);
            $result = false;
        }

        // Perform some general checks over keys
        if ($result && $this->keys) {
            // Check keys names are ok (lowercase, a-z _-)
            if (!$this->checkNameValues($this->keys)) {
                $this->errormsg = 'Some KEYS name values are incorrect';
                $this->debug($this->errormsg);
                $result = false;
            }
            // Compute prev/next.
            $this->fixPrevNext($this->keys);
            // Order keys
            if ($result && !$this->orderKeys($this->keys)) {
                $this->errormsg = 'Error ordering the keys';
                $this->debug($this->errormsg);
                $result = false;
            }
            // TODO: Only one PK
            // TODO: Not keys with repeated fields
            // TODO: Check fields and reffieds exist in table
        }

        // Iterate over indexes
        if (isset($xmlarr['#']['INDEXES']['0']['#']['INDEX'])) {
            foreach ($xmlarr['#']['INDEXES']['0']['#']['INDEX'] as $xmlindex) {
                if (!$result) { //Skip on error
                    continue;
                }
                $name = trim($xmlindex['@']['NAME']);
                $index = new xmldb_index($name);
                $index->arr2xmldb_index($xmlindex);
                $this->indexes[] = $index;
                if (!$index->isLoaded()) {
                    $this->errormsg = 'Problem loading index ' . $name;
                    $this->debug($this->errormsg);
                    $result = false;
                }
            }
        }

        // Perform some general checks over indexes
        if ($result && $this->indexes) {
            // Check field names are ok (lowercase, a-z _-)
            if (!$this->checkNameValues($this->indexes)) {
                $this->errormsg = 'Some INDEXES name values are incorrect';
                $this->debug($this->errormsg);
                $result = false;
            }
            // Compute prev/next.
            $this->fixPrevNext($this->indexes);
            // Order indexes
            if ($result && !$this->orderIndexes($this->indexes)) {
                $this->errormsg = 'Error ordering the indexes';
                $this->debug($this->errormsg);
                $result = false;
            }
            // TODO: Not indexes with repeated fields
            // TODO: Check fields exist in table
        }

        // Set some attributes
        if ($result) {
            $this->loaded = true;
        }
        $this->calculateHash();
        return $result;
    }
1288100
public function IsInCategoryPath($sCategoryId)
    {
        $oBreadCrumb = $this->GetBreadcrumb();
        $oMatchingNode = $oBreadCrumb->FindItemWithProperty('id', $sCategoryId);
        if ($oMatchingNode) {
            return true;
        } else {
            return false;
        }
    }
1293327
function(sCategory) {
        var filtersArray = this._categoryFilters;
        // Don't do anything if category is already enabled
        // Use Array.indexOf if available...
        if(filtersArray.indexOf) {
             if(filtersArray.indexOf(sCategory) >  -1) {
                return;
            }
        }
        // ...or do it the old-fashioned way
        else {
            for(var i=0; i<filtersArray.length; i++) {
               if(filtersArray[i] === sCategory){
                    return;
                }
            }
        }

        this._categoryFilters.push(sCategory);
        this._filterLogs();
        var elCheckbox = this.getCheckbox(sCategory);
        if(elCheckbox) {
            elCheckbox.checked = true;
        }
    }
1150871
public function write($sessid, $sessdata)
    {
        $this->_cache->set(
            $sessid,
            $sessdata,
            array('expiry' => $this->_sessionExpiryInterval)
        );
        $sql  = 'INSERT INTO tbl_sessions (SESSION_ID, SESSION_DATA) 
            values (:SESSID, :SESSDATA) ON DUPLICATE KEY 
            UPDATE SESSION_DATA=:SDATA, LAST_ACCESSED=NOW()';
        $stmt = $this->_db->prepare($sql);
        $stmt->execute(
            array(
             ':SESSID'   => $sessid,
             ':SESSDATA' => $sessdata,
             ':SDATA'    => $sessdata,
            )
        );

        return true;

    }
1129502
protected function addCategoryData($iCategoryID, $bActiveCategory = false)
    {
        $obCategoryItem = CategoryItem::make($iCategoryID);
        if ($obCategoryItem->isEmpty()) {
            return;
        }

        $this->arResult[] = [
            'id'     => $obCategoryItem->id,
            'name'   => $obCategoryItem->name,
            'slug'   => $obCategoryItem->slug,
            'active' => $bActiveCategory,
            'item'   => $obCategoryItem,
        ];

        if (!empty($obCategoryItem->parent_id)) {
            $this->addCategoryData($obCategoryItem->parent_id);
        }
    }
1158735
public function isAssignedToCategory($sCatId)
    {
        // variant handling
        $sOXID = $this->getId();
        if (isset($this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
            $sOXID = $this->oxarticles__oxparentid->value;
        }

        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $sSelect = $this->_generateSelectCatStr($sOXID, $sCatId);
        $sOXID = $oDb->getOne($sSelect);
        // article is assigned to passed category!
        if (isset($sOXID) && $sOXID) {
            return true;
        }

        // maybe this category is price category ?
        if (\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('bl_perfLoadPrice') && $this->_blLoadPrice) {
            $dPriceFromTo = $this->getPrice()->getBruttoPrice();
            if ($dPriceFromTo > 0) {
                $sSelect = $this->_generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo);
                $sOXID = $oDb->getOne($sSelect);
                // article is assigned to passed category!
                if (isset($sOXID) && $sOXID) {
                    return true;
                }
            }
        }

        return false;
    }
780130
public function isDataSet($pCoord) {
		//	Check if the requested entry is the current object, or exists in the cache
		if (parent::isDataSet($pCoord)) {
			if ($this->_currentObjectID == $pCoord) {
				return true;
			}
			//	Check if the requested entry still exists in cache
			$success = wincache_ucache_exists($this->_cachePrefix.$pCoord.'.cache');
			if ($success === false) {
				//	Entry no longer exists in Wincache, so clear it from the cache array
				parent::deleteCacheData($pCoord);
				throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
			}
			return true;
		}
		return false;
	}
865759
protected function addPatternData ($xml, $table, $arrOrder, $intParentID)
	{
			// Get all content patterns
			$objContentPattern = $this->Database->prepare("SELECT * FROM tl_pattern WHERE pid=?")
									   ->execute($intParentID);
			
			// Add the rows
			while ($objContentPattern->next())
			{
				$this->addDataRow($xml, $table, $objContentPattern->row(), $arrOrder);
				
				if (in_array($objContentPattern->type, $GLOBALS['TL_CTP_SUB']))
				{
					$this->addPatternData($xml, $table, $arrOrder, $objContentPattern->id);
				}
			}
	
	}
727740
public function write($sessionid, $sessiondata)
    {
        $adapter = $this->getAdapter();

        $data = [
          'time' => time(),
          'data' => $sessiondata
        ];

        if ($adapter instanceof PostgreSQL) {
            $data['data'] = bin2hex($data['data']);
        }

        $sess = $this->getDbData($sessionid);

        if ($this->disableLog) {
            Log::temporaryDisable('sql');
        }

        if ($sess === null) {
            // the record doesn't exists in database, lets insert it
            $data['id'] = $sessionid;

            try {
                $adapter->insert($this->getTableName(), $data)->exec();
                return true;

            } catch (DbException $e) {
                Log::emergency($e);
                return false;

            } finally {
                if ($this->disableLog) {
                    Log::restoreTemporaryDisablement();
                }

            }

        } else {
            // the record data already exists in db

            try {
                $adapter->update($this->getTableName(), $data)->where('id', $sessionid)->exec();
                return true;

            } catch (DbException $e) {
                Log::emergency($e);
                return false;

            } finally {
                if ($this->disableLog) {
                    Log::restoreTemporaryDisablement();
                }

            }
        }
    }
224151
private function extractBulkInsertTableColumnsInfo(): void
  {
    // Return immediately if designation type is not appropriate for this method.
    if ($this->designationType!='bulk_insert') return;

    // Check if table is a temporary table or a non-temporary table.
    $table_is_non_temporary = MetaDataLayer::checkTableExists($this->bulkInsertTableName);

    // Create temporary table if table is non-temporary table.
    if (!$table_is_non_temporary)
    {
      MetaDataLayer::callProcedure($this->routineName);
    }

    // Get information about the columns of the table.
    $description = MetaDataLayer::describeTable($this->bulkInsertTableName);

    // Drop temporary table if table is non-temporary.
    if (!$table_is_non_temporary)
    {
      MetaDataLayer::dropTemporaryTable($this->bulkInsertTableName);
    }

    // Check number of columns in the table match the number of fields given in the designation type.
    $n1 = count($this->bulkInsertKeys);
    $n2 = count($description);
    if ($n1!=$n2)
    {
      throw new RoutineLoaderException("Number of fields %d and number of columns %d don't match.", $n1, $n2);
    }

    $this->bulkInsertColumns = self::extractColumnsFromTableDescription($description);
  }
865220
public function AddArticle($sArticleId, $dAmount = 1, $sComment = null)
    {
        $dNewAmount = 0;
        $aItemData = array();
        $oItem = TdbPkgShopWishlistArticle::GetNewInstance();
        /** @var $oItem TdbPkgShopWishlistArticle */
        if ($oItem->LoadFromFields(array('pkg_shop_wishlist_id' => $this->id, 'shop_article_id' => $sArticleId))) {
            $aItemData = $oItem->sqlData;
            $aItemData['amount'] += $dAmount;
        } else {
            $aItemData['pkg_shop_wishlist_id'] = $this->id;
            $aItemData['shop_article_id'] = $sArticleId;
            $aItemData['amount'] = $dAmount;
            $aItemData['datecreated'] = date('Y-m-d H:i:s');
        }
        if (!is_null($sComment)) {
            $aItemData['comment'] = $oItem->LoadFromRow($aItemData);
        }
        $oItem->LoadFromRow($aItemData);
        $oItem->AllowEditByAll(true);
        $oItem->Save();
        $dNewAmount = $aItemData['amount'];

        return $dNewAmount;
    }
311604
protected function _updateArticleVarName($sUpdate, $sArtId)
    {
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $sUpdate = "update oxarticles set " . $sUpdate . " where oxid = " . $oDb->quote($sArtId);
        $oDb->Execute($sUpdate);
    }
33753
protected function _getFilterSql($sCatId, $aFilter)
    {
        $sArticleTable = getViewName('oxarticles');
        $aIds = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC)->getAll($this->_getFilterIdsSql($sCatId, $aFilter));
        $sIds = '';

        if ($aIds) {
            foreach ($aIds as $aArt) {
                if ($sIds) {
                    $sIds .= ', ';
                }
                $sIds .= \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quote(current($aArt));
            }

            if ($sIds) {
                $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
            }
            // bug fix #0001695: if no articles found return false
        } elseif (!(current($aFilter) == '' && count(array_unique($aFilter)) == 1)) {
            $sFilterSql = " and false ";
        }

        return $sFilterSql;
    }
1306789
public function isDataSet($pCoord)
    {
        if ($pCoord === $this->currentObjectID) {
            return true;
        }

        //    Check if the requested entry exists in the cache
        $query = "SELECT id FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
        $cellResultSet = $this->DBHandle->query($query, SQLITE_ASSOC);
        if ($cellResultSet === false) {
            throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
        } elseif ($cellResultSet->numRows() == 0) {
            //    Return null if requested entry doesn't exist in cache
            return false;
        }
        return true;
    }
1012673
protected function ParseContentData($sContent)
    {
        $sRatingUser = '';
        $sRatingShopTitle = '';
        $sRatingShop = '';

        if (!empty($sContent)) {
            $sContent = preg_replace('/\s+/', ' ', $sContent);
            if (preg_match('#<p>(.+?)</p>#sim', $sContent, $matches)) {
                $count = count($matches);
                if ($count > 1) {
                    $sRatingUser = preg_replace('#<strong>(.*?)</strong>\s*#sim', '', $matches[1]);
                }
                if ($count > 3) {
                    $sRatingShop = preg_replace('#<strong>(.*?)</strong>\s*#sim', '', $matches[3]);
                    if (preg_match('#<strong>(.*?)</strong>#', $sRatingShop, $strongMatches)) {
                        if (count($strongMatches) > 1) {
                            $sRatingShopTitle = $strongMatches[1];
                        }
                    }
                }
            }
        }
        $sRet = '';
        if (!empty($sRatingUser)) {
            $sRet .= '<div>'.$sRatingUser.'</div>';
        }
        if (!empty($sRatingShopTitle)) {
            $sRet .= '<div>'.$sRatingShopTitle.'</div>';
        }
        if (!empty($sRatingShop)) {
            $sRet .= '<div>'.$sRatingShop.'</div>';
        }

        return $sRet;
    }