Pimcore\Model\Object\Localizedfield\Dao::delete PHP Method

delete() public method

public delete ( boolean $deleteQuery = true )
$deleteQuery boolean
    public function delete($deleteQuery = true)
    {
        $object = $this->model->getObject();
        try {
            $context = $this->model->getContext();
            if ($context && $context["containerType"] == "fieldcollection") {
                $containerKey = $context["containerKey"];
                $container = Object\Fieldcollection\Definition::getByKey($containerKey);
            } else {
                $container = $object->getClass();
            }
            if ($deleteQuery) {
                $id = $object->getId();
                $tablename = $this->getTableName();
                $this->db->delete($tablename, $this->db->quoteInto("ooo_id = ?", $id));
                if (!$container instanceof Object\Fieldcollection\Definition) {
                    $validLanguages = Tool::getValidLanguages();
                    foreach ($validLanguages as $language) {
                        $queryTable = $this->getQueryTableName() . "_" . $language;
                        $this->db->delete($queryTable, $this->db->quoteInto("ooo_id = ?", $id));
                    }
                }
            }
            $childDefinitions = $container->getFieldDefinition("localizedfields")->getFielddefinitions();
            if (is_array($childDefinitions)) {
                foreach ($childDefinitions as $fd) {
                    if (method_exists($fd, "delete")) {
                        $params = [];
                        $params["context"] = $this->model->getContext() ? $this->model->getContext() : [];
                        if ($params["context"]["containerType"] == "fieldcollection") {
                            $params["context"]["subContainerType"] = "localizedfield";
                        }
                        $fd->delete($object, $params);
                    }
                }
            }
        } catch (\Exception $e) {
            Logger::error($e);
            $this->createUpdateTable();
        }
        // remove relations
        if ($container instanceof Object\Fieldcollection\Definition) {
            $objectId = $object->getId();
            $index = $context["index"];
            $containerName = $context["fieldname"];
            $sql = $this->db->quoteInto("src_id = ?", $objectId) . " AND ownertype = 'localizedfield' AND " . $this->db->quoteInto("ownername LIKE ?", "/fieldcollection~" . $containerName . "/" . $index . "/%");
            $this->db->delete("object_relations_" . $object->getClassId(), $sql);
        } else {
            $this->db->delete("object_relations_" . $this->model->getObject()->getClassId(), $this->db->quoteInto("ownertype = 'localizedfield' AND ownername = 'localizedfield' AND src_id = ?", $this->model->getObject()->getId()));
        }
    }