public function testSetMinimuimShouldNotIncreaseUnlimited() { MemoryMock::setLimit('-1'); MemoryLimit::setMinimumMemoryLimit(1024 * 1024 * 20); $this->assertEquals('-1', MemoryMock::getLimit()); }
/** * Sets up the environment for seo url calculation */ public function baseSetup() { MemoryLimit::setMinimumMemoryLimit(1024 * 1024 * 512); @set_time_limit(0); $keys = array_keys($this->template->registered_plugins['function']); if (!in_array('sCategoryPath', $keys)) { $this->template->registerPlugin(Smarty::PLUGIN_FUNCTION, 'sCategoryPath', array($this, 'sSmartyCategoryPath')); } if (!in_array('createSupplierPath', $keys)) { $this->template->registerPlugin(Smarty::PLUGIN_FUNCTION, 'createSupplierPath', array($this, 'createSupplierPath')); } $this->data = $this->template->createData(); $this->data->assign('sConfig', $this->config); $this->data->assign('sRouter', $this); $this->data->assign('sCategoryStart', Shopware()->Shop()->getCategory()->getId()); }
/** * Rebuilds the search index for the shopware default search query builder. */ public function build() { MemoryLimit::setMinimumMemoryLimit(1024 * 1024 * 512); @set_time_limit(0); $this->setNextUpdateTimestamp(); // Truncate search index table $this->connection->executeUpdate('TRUNCATE TABLE `s_search_index`'); // Get a list of all tables and columns in this tables that should be processed by search /** * Example return: * tableID | table | where | referenz_table | fieldIDs | fields | foreign_key * 1 | s_articles | NULL | NULL | 3,4 | name, keywords | NULL * 2 | s_categories | NULL | s_articles_categories | 1,2 | metakeywords, description | categoryID */ $tables = $this->getSearchTables(); if (!empty($tables)) { foreach ($tables as $table) { // Set primary key $table['elementID'] = empty($table['foreign_key']) && $table['table'] != 's_articles' ? 'articleID' : 'id'; // Build sql query to fetch values from this table $sql = 'SELECT ' . $table['elementID'] . ' as id, ' . $table['fields'] . ' FROM ' . $table['table']; // If any where condition is set, add to query if (!empty($table['where'])) { $sql .= ' WHERE ' . $table['where']; } // Get all fields & values from current table $getTableKeywords = $this->connection->fetchAll($sql); // If no result, return if (empty($getTableKeywords)) { continue; } // Build array from columns fieldIDs and fields $fields = array_combine(explode(', ', $table["fieldIDs"]), explode(', ', $table["fields"])); $keywords = []; $sqlIndex = []; // Go through every row of result foreach ($getTableKeywords as $currentRow => $row) { // Go through every column of result foreach ($fields as $fieldID => $field) { // Split string from column into keywords $field_keywords = $this->termHelper->splitTerm($row[$field]); if (empty($field_keywords)) { continue; } foreach ($field_keywords as &$keyword) { $keyword = $this->connection->quote($keyword); $keywords[] = $keyword; } // SQL-queries to fill s_search_index $sqlIndex[] = 'SELECT sk.id as keywordID, ' . $row['id'] . ' as elementID, ' . $fieldID . ' as fieldID ' . 'FROM s_search_keywords sk ' . 'WHERE sk.keyword IN (' . implode(', ', $field_keywords) . ')'; } // If no new keywords were found, proceed with next table if (empty($keywords)) { continue; } // If last row or more then 5000 keywords fetched, write results to index if ($currentRow == count($getTableKeywords) - 1 || count($keywords) > 5000) { $keywords = array_unique($keywords); // Remove duplicates $sql_keywords = 'INSERT IGNORE INTO `s_search_keywords` (`keyword`) VALUES'; $sql_keywords .= ' (' . implode('), (', $keywords) . ')'; // Insert Keywords $this->connection->executeUpdate($sql_keywords); $keywords = []; // Update index $sqlIndex = implode("\n\nUNION ALL\n\n", $sqlIndex); $sqlIndex = "INSERT IGNORE INTO s_search_index (keywordID, elementID, fieldID)\n\n" . $sqlIndex; $this->connection->executeUpdate($sqlIndex); $sqlIndex = []; } } } } $this->cleanupIndex(); $this->cleanupKeywords(); }