/** * @param string $entityType * @param object $entity * @param array $arguments * @return object * @throws \Exception */ public function execute($entityType, $entity, $arguments = []) { $metadata = $this->metadataPool->getMetadata($entityType); $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName()); $this->transactionManager->start($connection); try { $this->eventManager->dispatch( 'entity_manager_delete_before', [ 'entity_type' => $entityType, 'entity' => $entity ] ); $this->eventManager->dispatchEntityEvent($entityType, 'delete_before', ['entity' => $entity]); $entity = $this->deleteExtensions->execute($entityType, $entity, $arguments); $entity = $this->deleteAttributes->execute($entityType, $entity, $arguments); $entity = $this->deleteMain->execute($entityType, $entity, $arguments); $this->eventManager->dispatchEntityEvent($entityType, 'delete_after', ['entity' => $entity]); $this->eventManager->dispatch( 'entity_manager_delete_before', [ 'entity_type' => $entityType, 'entity' => $entity ] ); $this->transactionManager->commit(); } catch (\Exception $e) { $this->transactionManager->rollBack(); throw $e; } return $entity; }
/** * Delete products. * * @return $this * @throws \Exception */ protected function _deleteProducts() { $productEntityTable = $this->_resourceFactory->create()->getEntityTable(); while ($bunch = $this->_dataSourceModel->getNextBunch()) { $idToDelete = []; foreach ($bunch as $rowNum => $rowData) { if ($this->validateRow($rowData, $rowNum) && self::SCOPE_DEFAULT == $this->getRowScope($rowData)) { $idToDelete[] = $this->_oldSku[$rowData[self::COL_SKU]]['entity_id']; } } if ($idToDelete) { $this->countItemsDeleted += count($idToDelete); $this->transactionManager->start($this->_connection); try { $this->objectRelationProcessor->delete($this->transactionManager, $this->_connection, $productEntityTable, $this->_connection->quoteInto('entity_id IN (?)', $idToDelete), ['entity_id' => $idToDelete]); $this->transactionManager->commit(); } catch (\Exception $e) { $this->transactionManager->rollBack(); throw $e; } $this->_eventManager->dispatch('catalog_product_import_bunch_delete_after', ['adapter' => $this, 'bunch' => $bunch]); } } return $this; }
/** * Delete the object * * @param \Magento\Framework\Model\AbstractModel $object * @return $this * @throws \Exception */ public function delete(\Magento\Framework\Model\AbstractModel $object) { $connection = $this->transactionManager->start($this->getConnection()); try { $object->beforeDelete(); $this->_beforeDelete($object); $this->objectRelationProcessor->delete( $this->transactionManager, $connection, $this->getMainTable(), $this->getConnection()->quoteInto($this->getIdFieldName() . '=?', $object->getId()), $object->getData() ); $this->_afterDelete($object); $object->isDeleted(true); $object->afterDelete(); $this->transactionManager->commit(); $object->afterDeleteCommit(); } catch (\Exception $e) { $this->transactionManager->rollBack(); throw $e; } return $this; }
/** * Delete entity using current object's data * * @param \Magento\Framework\DataObject|int|string $object * @return $this * @throws \Exception * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function delete($object) { try { $connection = $this->transactionManager->start($this->getConnection()); if (is_numeric($object)) { $id = (int) $object; } elseif ($object instanceof \Magento\Framework\Model\AbstractModel) { $object->beforeDelete(); $id = (int) $object->getData($this->getLinkField()); } $this->_beforeDelete($object); $this->evaluateDelete($object, $id, $connection); $this->_afterDelete($object); if ($object instanceof \Magento\Framework\Model\AbstractModel) { $object->isDeleted(true); $object->afterDelete(); } $this->transactionManager->commit(); if ($object instanceof \Magento\Framework\Model\AbstractModel) { $object->afterDeleteCommit(); } } catch (\Exception $e) { $this->transactionManager->rollBack(); throw $e; } return $this; }
/** * Delete entity using current object's data * * @param \Magento\Framework\DataObject|int|string $object * @return $this * @throws \Exception * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function delete($object) { try { $connection = $this->transactionManager->start($this->getConnection()); if (is_numeric($object)) { $id = (int) $object; } elseif ($object instanceof \Magento\Framework\Model\AbstractModel) { $object->beforeDelete(); $id = (int) $object->getId(); } $this->_beforeDelete($object); try { $where = [$this->getEntityIdField() . '=?' => $id]; $this->objectRelationProcessor->delete($this->transactionManager, $connection, $this->getEntityTable(), $this->getConnection()->quoteInto($this->getEntityIdField() . '=?', $id), [$this->getEntityIdField() => $id]); $this->loadAllAttributes($object); foreach ($this->getAttributesByTable() as $table => $attributes) { $this->getConnection()->delete($table, $where); } } catch (\Exception $e) { throw $e; } $this->_afterDelete($object); if ($object instanceof \Magento\Framework\Model\AbstractModel) { $object->isDeleted(true); $object->afterDelete(); } $this->transactionManager->commit(); if ($object instanceof \Magento\Framework\Model\AbstractModel) { $object->afterDeleteCommit(); } } catch (\Exception $e) { $this->transactionManager->rollBack(); throw $e; } return $this; }