/** * Execute full indexation * * @return void */ public function executeFull() { $results = []; foreach ($this->getTables() as $table => $columns) { if (!count($columns)) { continue; } foreach ($columns as $idx => $col) { $columns[$idx] = '`' . $col . '`'; } $select = $this->connection->select(); $fromColumns = new \Zend_Db_Expr('CONCAT(' . implode(",' ',", $columns) . ') as data_index'); $select->from($table, $fromColumns); $result = $this->connection->query($select); while ($row = $result->fetch()) { $data = $row['data_index']; $this->split($data, $results); } } $indexTable = $this->resource->getTableName('mst_misspell_index'); $this->connection->delete($indexTable); $rows = []; foreach ($results as $word => $freq) { $rows[] = ['keyword' => $word, 'trigram' => $this->text->getTrigram($word), 'frequency' => $freq / count($results)]; if (count($rows) > 1000) { $this->connection->insertArray($indexTable, ['keyword', 'trigram', 'frequency'], $rows); $rows = []; } } if (count($rows) > 0) { $this->connection->insertArray($indexTable, ['keyword', 'trigram', 'frequency'], $rows); } $this->connection->delete($this->resource->getTableName('mst_misspell_suggest')); }
/** * Delete products from flat table(s) * * @param int|array $productId * @param null|int $storeId * @return void */ public function deleteProductsFromStore($productId, $storeId = null) { if (!is_array($productId)) { $productId = [$productId]; } if (null === $storeId) { foreach ($this->storeManager->getStores() as $store) { $this->connection->delete($this->productIndexerHelper->getFlatTableName($store->getId()), ['entity_id IN(?)' => $productId]); } } else { $this->connection->delete($this->productIndexerHelper->getFlatTableName((int) $storeId), ['entity_id IN(?)' => $productId]); } }
/** * @param string|int $nodeId * @return bool|Node|void */ public function removeNode($nodeId) { $info = $this->getNodeInfo($nodeId); if (!$info) { return false; } if ($nodeId) { $this->_db->beginTransaction(); try { /** * DELETE FROM my_tree WHERE left_key >= $left_key AND right_key <= $right_key */ $this->_db->delete($this->_table, $this->_left . ' >= ' . $info[$this->_left] . ' AND ' . $this->_right . ' <= ' . $info[$this->_right]); /** * UPDATE my_tree SET left_key = IF(left_key > $left_key, left_key – ($right_key - $left_key + 1), * left_key), right_key = right_key – ($right_key - $left_key + 1) WHERE right_key > $right_key */ $sql = 'UPDATE ' . $this->_table . ' SET ' . $this->_left . ' = IF(' . $this->_left . ' > ' . $info[$this->_left] . ', ' . $this->_left . ' - ' . ($info[$this->_right] - $info[$this->_left] + 1) . ', ' . $this->_left . '), ' . $this->_right . ' = ' . $this->_right . ' - ' . ($info[$this->_right] - $info[$this->_left] + 1) . ' WHERE ' . $this->_right . ' > ' . $info[$this->_right]; $this->_db->query($sql); $this->_db->commit(); return new Node($info, $this->getKeys()); } catch (\Exception $e) { $this->_db->rollBack(); echo $e->getMessage(); } } }
/** * Clear changelog table by version_id * * @param int $versionId * @return boolean * @throws \Exception */ public function clear($versionId) { $changelogTableName = $this->resource->getTableName($this->getName()); if (!$this->connection->isTableExists($changelogTableName)) { throw new \Exception("Table {$changelogTableName} does not exist"); } $this->connection->delete($changelogTableName, ['version_id <= ?' => (int) $versionId]); return true; }
/** * {@inheritdoc} */ public function deleteIndex($dimensions, \Traversable $documents) { foreach ($this->dataTypes as $dataType) { foreach ($this->batch->getItems($documents, $this->batchSize) as $batchDocuments) { $documentsId = array_column($batchDocuments, 'id'); $this->connection->delete($this->getTableName($dataType, $dimensions), ['id' => $documentsId]); } } }
/** * Delete options and selections. * * @param array $productIds * * @return \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType */ protected function deleteOptionsAndSelections($productIds) { $optionTable = $this->_resource->getTableName('catalog_product_bundle_option'); $optionValueTable = $this->_resource->getTableName('catalog_product_bundle_option_value'); $valuesIds = $this->connection->fetchAssoc($this->connection->select()->from(['bov' => $optionValueTable], ['value_id'])->joinLeft(['bo' => $optionTable], 'bo.option_id = bov.option_id', ['option_id'])->where('parent_id IN (?)', $productIds)); $this->connection->delete($optionTable, $this->connection->quoteInto('value_id IN (?)', array_keys($valuesIds))); $productIdsInWhere = $this->connection->quoteInto('parent_id IN (?)', $productIds); $this->connection->delete($optionTable, $this->connection->quoteInto('parent_id IN (?)', $productIdsInWhere)); $this->connection->delete($optionTable, $this->connection->quoteInto('parent_product_id IN (?)', $productIdsInWhere)); return $this; }
/** * @param Node $node * @return $this * @throws \Exception */ public function removeNode($node) { // For reorder old node branch $dataReorderOld = [$this->_orderField => new \Zend_Db_Expr($this->_conn->quoteIdentifier($this->_orderField) . '-1')]; $conditionReorderOld = $this->_conn->quoteIdentifier($this->_parentField) . '=' . $node->getData($this->_parentField) . ' AND ' . $this->_conn->quoteIdentifier($this->_orderField) . '>' . $node->getData($this->_orderField); $this->_conn->beginTransaction(); try { $condition = $this->_conn->quoteInto("{$this->_idField}=?", $node->getId()); $this->_conn->delete($this->_table, $condition); // Update old node branch $this->_conn->update($this->_table, $dataReorderOld, $conditionReorderOld); $this->_conn->commit(); } catch (\Exception $e) { $this->_conn->rollBack(); throw new \Exception('Can\'t remove tree node'); } parent::removeNode($node); return $this; }
/** * Removes all data from the table * * @param string $table * @return void */ protected function _emptyTable($table) { $this->_connection->delete($table); }
/** * Delete unnecessary links. * * @return $this */ protected function _deleteData() { $linkTable = $this->_resource->getTableName('catalog_product_super_link'); $relationTable = $this->_resource->getTableName('catalog_product_relation'); if ($this->_entityModel->getBehavior() == \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND && !empty($this->_productSuperData['product_id']) && !empty($this->_simpleIdsToDelete)) { $quoted = $this->_connection->quoteInto('IN (?)', [$this->_productSuperData['product_id']]); $quotedChildren = $this->_connection->quoteInto('IN (?)', $this->_simpleIdsToDelete); $this->_connection->delete($linkTable, "parent_id {$quoted} AND product_id {$quotedChildren}"); $this->_connection->delete($relationTable, "parent_id {$quoted} AND child_id {$quotedChildren}"); } return $this; }
/** * Garbage collection * * @param int $maxLifeTime * @return bool * @SuppressWarnings(PHPMD.ShortMethodName) */ public function gc($maxLifeTime) { $where = ['session_expires < ?' => time() - $maxLifeTime]; $this->_write->delete($this->_sessionTable, $where); return true; }
/** * Process delete action * * @param TransactionManagerInterface $transactionManager * @param Connection $connection * @param string $table * @param string $condition * @param array $involvedData * @return void * @throws \LogicException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function delete(TransactionManagerInterface $transactionManager, Connection $connection, $table, $condition, array $involvedData) { $connection->delete($table, $condition); }
/** * Clean rule price index * * @return $this */ protected function deleteOldData() { $this->connection->delete($this->getTable('catalogrule_product_price')); return $this; }
/** * Delete processed records * * @param string $documentName * @return void */ public function deleteProcessedRecords($documentName) { $this->resourceAdapter->delete($documentName, "`processed` = 1"); }
/** * Delete custom option type values * * @param array $optionIds * @return $this */ protected function _deleteSpecificTypeValues(array $optionIds) { $this->_connection->delete($this->_tables['catalog_product_option_type_value'], $this->_connection->quoteInto('option_id IN (?)', $optionIds)); return $this; }
/** * @param array $productIds * @throws \Magento\Framework\Exception\LocalizedException * @return void */ protected function deleteOldLinks($productIds) { if ($this->getBehavior() != \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND) { $this->connection->delete($this->productLink->getMainTable(), $this->connection->quoteInto('product_id IN (?) AND link_type_id = ' . $this->getLinkTypeId(), $productIds)); } }