Remove a structure

@param   int|string|array|Structure  $structureOrPrimaryKeys
@return  int
772475
public function delete( $structureOrPrimaryKeys )
    {
        if ( $structureOrPrimaryKeys instanceof Structure )
        {
            $structure = $structureOrPrimaryKeys->resetContents();
        }
        else if ( null === $structureOrPrimaryKeys ||
                is_scalar( $structureOrPrimaryKeys ) )
        {
            $structure = $this->createStructure( array(
                'rootId' => $structureOrPrimaryKeys,
            ) );
        }
        else
        {
            $structureOrPrimaryKeys = (array) $structureOrPrimaryKeys;
            $structure = $this->createStructure( array(
                'rootId' => isset( $structureOrPrimaryKeys['rootId'] )
                            ? $structureOrPrimaryKeys['rootId']
                            : reset( $structureOrPrimaryKeys )
            ) );
        }

        return $this->save( $structure );
    }
1070210
protected function purgePrimaryKeyValue(&$record)
    {
        foreach((array) $this->ORMParameters['primaryKey'] as $field) {
            if(is_array($record) && (isset($record[$field]) || $record[$field] === null)) {
                unset($record[$field]);
            } elseif(is_object($record) && isset($record->$field) ) {
                unset($record->$field);
            }
        }
    }
845266
public function getPrimaryKey()
    {
        $pks = [];
        foreach ($this->__primaryKeys as $pk) {
            if (is_object($this->$pk)) {
                $traits = class_uses($this->$pk);
                if (isset($traits['Ornament\Model'])
                    || isset($traits['Ornament\JsonModel'])
                ) {
                    $pks[] = $this->$pk->getPrimaryKey();
                } else {
                    $pks[] = "{$this->$pk}";
                }
            } else {
                $pks[] = $this->$pk;
            }
        }
        return count($pks) == 1 ? $pks[0] : $pks;
    }
803051
public function delete( $structureOrPrimaryKeys )
    {
        if ( is_object( $structureOrPrimaryKeys ) )
        {
            $section = $structureOrPrimaryKeys->section;
        }
        else if ( is_array( $structureOrPrimaryKeys ) )
        {
            $section = $structureOrPrimaryKeys['section'];
        }
        else
        {
            $section = (string) $structureOrPrimaryKeys;
        }

        $rows = 0;
        $def  = $this->getDefinitions();
        $keys = $def->getKeys( $section );

        if ( ! empty( $keys ) )
        {
            $delete = $this->sql()
                           ->delete()
                           ->where( $this->keysWhere( $keys ) );

            $result = $this->sql()
                           ->prepareStatementForSqlObject( $delete )
                           ->execute();

            $rows += $result->getAffectedRows();
        }

        $fieldsets = $def->getFieldsets( $section );

        if ( ! empty( $fieldsets ) )
        {
            foreach ( $fieldsets as $fieldset )
            {
                $rows += $this->delete( $fieldset );
            }
        }

        return $rows;
    }
449852
public function deleteDependents(Event $event, $ids, $count) {
        $pfk = $this->getPrimaryForeignKey();

        $this->getJunctionRepository()->deleteMany(function(Query $query) use ($pfk, $ids) {
            $query->where($pfk, $ids);
        });
    }
466029
public function delete($primaryKey)
    {
        return $this->app['db']->delete($this->getTable(), [ $this->getPrimaryKey() => $primaryKey]);
    }
1224701
public function removeStructureNodeRelatedByParentId(ChildStructureNode $structureNodeRelatedByParentId)
    {
        if ($this->getStructureNodesRelatedByParentId()->contains($structureNodeRelatedByParentId)) { $structureNodeParent = new ChildStructureNodeParent();

            $structureNodeParent->setStructureNodeRelatedByParentId($structureNodeRelatedByParentId);
            if ($structureNodeRelatedByParentId->isStructureNodeRelatedByStructureNodeIdsLoaded()) {
                //remove the back reference if available
                $structureNodeRelatedByParentId->getStructureNodeRelatedByStructureNodeIds()->removeObject($this);
            }

            $structureNodeParent->setStructureNodeRelatedByStructureNodeId($this);
            $this->removeStructureNodeParentRelatedByStructureNodeId(clone $structureNodeParent);
            $structureNodeParent->clear();

            $this->collStructureNodesRelatedByParentId->remove($this->collStructureNodesRelatedByParentId->search($structureNodeRelatedByParentId));

            if (null === $this->structureNodesRelatedByParentIdScheduledForDeletion) {
                $this->structureNodesRelatedByParentIdScheduledForDeletion = clone $this->collStructureNodesRelatedByParentId;
                $this->structureNodesRelatedByParentIdScheduledForDeletion->clear();
            }

            $this->structureNodesRelatedByParentIdScheduledForDeletion->push($structureNodeRelatedByParentId);
        }


        return $this;
    }
145060
public function filterByPrimaryKeys($keys)
    {
        if (empty($keys)) {
            return $this->add(null, '1<>1', Criteria::CUSTOM);
        }
        foreach ($keys as $key) {
            $cton0 = $this->getNewCriterion(StructureNodeParentTableMap::COL_STRUCTURE_NODE_ID, $key[0], Criteria::EQUAL);
            $cton1 = $this->getNewCriterion(StructureNodeParentTableMap::COL_PARENT_ID, $key[1], Criteria::EQUAL);
            $cton0->addAnd($cton1);
            $this->addOr($cton0);
        }

        return $this;
    }
1181279
public void removeResourceFromUsersPubList(CmsRequestContext context, Collection<CmsUUID> structureIds)
    throws CmsException {

        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
        try {
            m_driverManager.removeResourceFromUsersPubList(dbc, context.getCurrentUser().getId(), structureIds);
        } catch (Exception e) {
            dbc.report(
                null,
                Messages.get().container(
                    Messages.ERR_REMOVE_RESOURCE_FROM_PUBLIST_2,
                    context.getCurrentUser().getName(),
                    structureIds),
                e);

        } finally {
            dbc.clear();
        }
    }
127502
public function unlink($relation, $primary1, $primary2)
    {
        if (is_null($this->schema)) {
            throw SystemException::forNoSchema();
        }

        $name = $this->schema->getName();
        $relations = $this->schema->getRelations();
        $table = $name . '_' . $relation;

        if (!isset($relations[$table])) {
            throw SystemException::forNoRelation($name, $relation);
        }

        $relation = $relations[$table];

        $model = $this->resource->model();
        $model[$relation['primary1']] = $primary1;
        $model[$relation['primary2']] = $primary2;

        return $model->remove($table);
    }
1237281
protected function filterLayoutLayer(array $presences, array $parentKeys = [])
    {
        $remove = [];

        foreach ($presences as $key => $presence) {

            if ($presence->type() !== MenuPresenceType::GROUP) {

                if ( ! $this->userHasPermission($presence->permissions())) {
                    $remove[] = $key;
                }
                continue;
            }

            // Use the permissions index to determine whether we need to analyse
            // the children of this node: not if all children are unconditional
            // (index is empty array) or user has all permissions.

            $combinedParentKeys   = $parentKeys;
            $combinedParentKeys[] = $key;

            $index = $this->permissionsIndex->getForNode($combinedParentKeys);

            if (is_array($index) && ( ! count($index) || $this->userHasAllPermissions($index))) {
                continue;
            }

            $childKeys = $parentKeys;
            array_push($childKeys, $key);

            $presence->setChildren(
                $this->filterLayoutLayer($presence->children(), $childKeys)
            );

            if ( ! count($presence->children())) {
                $remove[] = $key;
            }
        }

        if (count($remove)) {
            array_forget($presences, $remove);
        }

        return $presences;
    }
1261612
public function filterByPrimaryKey($key)
    {
        $this->addUsingAlias(StructureNodeParentTableMap::COL_STRUCTURE_NODE_ID, $key[0], Criteria::EQUAL);
        $this->addUsingAlias(StructureNodeParentTableMap::COL_PARENT_ID, $key[1], Criteria::EQUAL);

        return $this;
    }
1150672
protected function getAlterTableSQL(\SimpleXMLElement $structure)
	{
		$table = $this->getRealTableName($structure['name']);
		$oldFields = $this->db->getTableColumns($table);
		$oldKeys = $this->db->getTableKeys($table);
		$alters = array();

		// Get the fields and keys from the XML that we are aiming for.
		$newFields = $structure->xpath('field');
		$newKeys = $structure->xpath('key');

		// Loop through each field in the new structure.
		foreach ($newFields as $field)
		{
			$fName = (string) $field['Field'];

			if (isset($oldFields[$fName]))
			{
				// The field exists, check it's the same.
				$column = $oldFields[$fName];

				// Test whether there is a change.
				$change = ((string) $field['Type'] != $column->Type) || ((string) $field['Null'] != $column->Null)
					|| ((string) $field['Default'] != $column->Default) || ((string) $field['Extra'] != $column->Extra);

				if ($change)
				{
					$alters[] = $this->getChangeColumnSQL($table, $field);
				}

				// Unset this field so that what we have left are fields that need to be removed.
				unset($oldFields[$fName]);
			}
			else
			{
				// The field is new.
				$alters[] = $this->getAddColumnSQL($table, $field);
			}
		}

		// Any columns left are orphans
		foreach ($oldFields as $name => $column)
		{
			// Delete the column.
			$alters[] = $this->getDropColumnSQL($table, $name);
		}

		// Get the lookups for the old and new keys.
		$oldLookup = $this->getKeyLookup($oldKeys);
		$newLookup = $this->getKeyLookup($newKeys);

		// Loop through each key in the new structure.
		foreach ($newLookup as $name => $keys)
		{
			// Check if there are keys on this field in the existing table.
			if (isset($oldLookup[$name]))
			{
				$same = true;
				$newCount = count($newLookup[$name]);
				$oldCount = count($oldLookup[$name]);

				// There is a key on this field in the old and new tables. Are they the same?
				if ($newCount == $oldCount)
				{
					// Need to loop through each key and do a fine grained check.
					for ($i = 0; $i < $newCount; $i++)
					{
						$same = (((string) $newLookup[$name][$i]['Non_unique'] == $oldLookup[$name][$i]->Non_unique)
							&& ((string) $newLookup[$name][$i]['Column_name'] == $oldLookup[$name][$i]->Column_name)
							&& ((string) $newLookup[$name][$i]['Seq_in_index'] == $oldLookup[$name][$i]->Seq_in_index)
							&& ((string) $newLookup[$name][$i]['Collation'] == $oldLookup[$name][$i]->Collation)
							&& ((string) $newLookup[$name][$i]['Index_type'] == $oldLookup[$name][$i]->Index_type));

						/*
						Debug.
						echo '<pre>';
						echo '<br />Non_unique:   '.
							((string) $newLookup[$name][$i]['Non_unique'] == $oldLookup[$name][$i]->Non_unique ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Non_unique'].' vs '.$oldLookup[$name][$i]->Non_unique;
						echo '<br />Column_name:  '.
							((string) $newLookup[$name][$i]['Column_name'] == $oldLookup[$name][$i]->Column_name ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Column_name'].' vs '.$oldLookup[$name][$i]->Column_name;
						echo '<br />Seq_in_index: '.
							((string) $newLookup[$name][$i]['Seq_in_index'] == $oldLookup[$name][$i]->Seq_in_index ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Seq_in_index'].' vs '.$oldLookup[$name][$i]->Seq_in_index;
						echo '<br />Collation:    '.
							((string) $newLookup[$name][$i]['Collation'] == $oldLookup[$name][$i]->Collation ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Collation'].' vs '.$oldLookup[$name][$i]->Collation;
						echo '<br />Index_type:   '.
							((string) $newLookup[$name][$i]['Index_type'] == $oldLookup[$name][$i]->Index_type ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Index_type'].' vs '.$oldLookup[$name][$i]->Index_type;
						echo '<br />Same = '.($same ? 'true' : 'false');
						echo '</pre>';
						 */

						if (!$same)
						{
							// Break out of the loop. No need to check further.
							break;
						}
					}
				}
				else
				{
					// Count is different, just drop and add.
					$same = false;
				}

				if (!$same)
				{
					$alters[] = $this->getDropKeySQL($table, $name);
					$alters[] = $this->getAddKeySQL($table, $keys);
				}

				// Unset this field so that what we have left are fields that need to be removed.
				unset($oldLookup[$name]);
			}
			else
			{
				// This is a new key.
				$alters[] = $this->getAddKeySQL($table, $keys);
			}
		}

		// Any keys left are orphans.
		foreach ($oldLookup as $name => $keys)
		{
			if (strtoupper($name) == 'PRIMARY')
			{
				$alters[] = $this->getDropPrimaryKeySQL($table);
			}
			else
			{
				$alters[] = $this->getDropKeySQL($table, $name);
			}
		}

		return $alters;
	}
566292
function delete_meta($meta_key) {
		return $this->edit_meta( $meta_key, function($id, $key, $path) {
			if ( $path ) {
				# Patch -- XXX unserialize and count up?
				$old = static::_get_meta($id, $key);
				if ( $old === false ) $old = array();
				$traverser = new RecursiveDataStructureTraverser($old);
				while ( $path ) {
					# nothing to delete?
					if ( ! $traverser->exists($path[0]) ) return;
					$traverser = $traverser->traverse_to(array($path[0]));
					array_shift($path);
				}
				$traverser->unset_on_parent();
				static::_set_meta($id, $key, $old);  # XXX reserialize and count down?
			} else {
				static::_delete_meta($id, $key);
			}
		});
	}
706343
public function delete(EntityDefinition $definition, array $ids, WriteContext $writeContext): DeleteResult
    {
        $this->validateWriteInput($ids);

        $commandQueue = new WriteCommandQueue();

        $fields = $definition->getPrimaryKeys();

        $resolved = [];
        foreach ($ids as $raw) {
            $mapped = [];

            /** @var Field $field */
            foreach ($fields as $field) {
                if (!($field instanceof StorageAware)) {
                    continue;
                }

                if (array_key_exists($field->getPropertyName(), $raw)) {
                    $mapped[$field->getStorageName()] = $raw[$field->getPropertyName()];
                    continue;
                }

                if ($field instanceof ReferenceVersionField) {
                    $mapped[$field->getStorageName()] = $writeContext->getContext()->getVersionId();
                    continue;
                }

                if ($field instanceof VersionField) {
                    $mapped[$field->getStorageName()] = $writeContext->getContext()->getVersionId();
                    continue;
                }

                $fieldKeys = $fields
                    ->filter(function (Field $field) {
                        return !$field instanceof VersionField && !$field instanceof ReferenceVersionField;
                    })
                    ->map(function (Field $field) {
                        return $field->getPropertyName();
                    });

                throw new IncompletePrimaryKeyException($fieldKeys);
            }

            $resolved[] = $mapped;
        }

        if (!$definition instanceof MappingEntityDefinition) {
            $restrictions = $this->foreignKeyResolver->getAffectedDeleteRestrictions($definition, $resolved, $writeContext->getContext());

            if (!empty($restrictions)) {
                $restrictions = array_map(function ($restriction) {
                    return new RestrictDeleteViolation($restriction['pk'], $restriction['restrictions']);
                }, $restrictions);

                throw new RestrictDeleteViolationException($definition, $restrictions, $this->registry);
            }
        }

        $cascades = [];
        if (!$definition instanceof MappingEntityDefinition) {
            $cascadeDeletes = $this->foreignKeyResolver->getAffectedDeletes($definition, $resolved, $writeContext->getContext());

            $cascadeDeletes = array_column($cascadeDeletes, 'restrictions');
            foreach ($cascadeDeletes as $cascadeDelete) {
                $cascades = array_merge_recursive($cascades, $cascadeDelete);
            }

            foreach ($cascades as $affectedDefinitionClass => &$cascade) {
                $affectedDefinition = $this->registry->get($affectedDefinitionClass);

                $cascade = array_map(function ($key) use ($affectedDefinition) {
                    $payload = $key;

                    if (!\is_array($key)) {
                        $payload = ['id' => $key];
                    }

                    return new EntityWriteResult($key, $payload, $affectedDefinition, null);
                }, $cascade);
            }
        }

        $skipped = [];
        foreach ($resolved as $mapped) {
            $mappedBytes = array_map(function ($id) {
                return Uuid::fromHexToBytes($id);
            }, $mapped);

            $existence = $this->gateway->getExistence($definition, $mappedBytes, [], $commandQueue);

            if (!$existence->exists()) {
                $skipped[$definition->getClass()][] = new EntityWriteResult($mapped, $mapped, $definition, $existence);
                continue;
            }

            $commandQueue->add(
                $definition,
                new DeleteCommand(
                    $definition,
                    $mappedBytes,
                    $existence
                )
            );
        }

        $writeContext->setLanguages($this->languageLoader->loadLanguages());
        $identifiers = $this->getWriteResults($commandQueue);
        $this->gateway->execute($commandQueue->getCommandsInOrder(), $writeContext);

        return new DeleteResult(
            array_merge_recursive($identifiers, $cascades),
            $skipped
        );
    }
298844
public function dropPrimaryKey($name, $table = null)
    {
        return $this->db->alterTable($this->getTable($table))
                        ->dropConstraint($name)
                        ->execute();
    }
279821
protected static int removeTreeStructure(BinaryTree curStruc) {

        BinaryTree equalStruc = curStruc.getEqual();
        BinaryTree notEqualStruc = curStruc.getNotEqual();
        curStruc = null;

        if (equalStruc != null) {
            removeTreeStructure(equalStruc);
        }

        if (notEqualStruc != null) {
            removeTreeStructure(notEqualStruc);
        }

        return 0;
    }