webCOMAND

cObject::delete()

Delete the object and its embedded objects from the repository.

If the object deleted is a top-level object (not embedded in another object), the delete will effectively be approved immediately.

If the object deleted is an embedded object, it will be removed from the parent object and the parent object will be stored.  That means the delete will only be made to the working copy, which will cause the field the object is embedded in to be locked until the parent object is ultimately approved with approve(), which must be done separately after delete() is called.  The deleted embedded object will only be removed from the approved version of the parent when approve() is subsequently called.

Prototype

boolean delete(array $options = [])

Parameters

  • options - The following options are recognized.
    • OverrideProtected - If TRUE, even protected objects will be removed.  It is highly recommended that this option never be set because it is likely to corrupt the repository and make it unusable and all repository data will likely be lost.
    • RemoveContentType - If TRUE, even content types will be removed, including all of their corresponding objects.  If FALSE or not set, an exception will be thrown when delete is called on a Content Type.  This prevents the accidental or unintended consequences of deleting a Content Type, which is not recoverable.
    • SkipContentLog - If TRUE, the content log will not be updated.
    • User - User of record for this delete, which will be recorded in the version log and content log.
    • VersionNotes - String containing a note to apply to this operation in the object's version log.
    • WriteUpdateLog - TRUE by default.  If FALSE, the update log will not be written, which means that listeners will not be notified that the object has changed, including the webCOMAND user interface, which receives notifications via a web socket.

Return

TRUE if the object was removed from the repository successfully.  Otherwise, FALSE.

Example

$repo = \comand::repo();
$object = $repo->get_object_by_oid(123);
$success = $object->delete(['VersionNotes'=>'No longer needed.']);

Embedded Object Example

$repo = \comand::repo();
$object = $repo->get_object_by_oid(123);
$parent_object = $object->get_parent();
if($object->delete()) {
    $parent->approve(['VersionNotes'=>'No longer needed.']);
}