Document Deleting (Python)

Document Deleting (Python)
 1ot = impact.gui.output_toolbox
 2db = impact.active_database
 3
 4def StatusAsString(status):
 5    if status == ipDocumentStatus.dsNormal:
 6        StatusAsString = "Normal"
 7    elif status == ipDocumentStatus.dsDeleted:
 8        StatusAsString = "Deleted"
 9    elif status == ipDocumentStatus.dsDataPurged:
10        StatusAsString = "DataPurged"
11    else:
12        StatusAsString = "Unknown"
13    return locals().get("StatusAsString")
14
15# WARNING: This script will permanently delete the document specified below
16
17# You can search for a document ID or document series ID
18# When seaching for a document series ID the latest document version is returned
19# documentID = "e1b1ad95-f9de-40c0-9d08-0fee87e8a011"
20documentID = "c3752e5a-6d50-4cfa-8508-58922e2dd212"
21document = db.find_document_by_id( documentID )
22
23if not document.isNone():
24
25    ot.add("Found document with status: " + StatusAsString(document.status))
26
27    # can delete a document with normal status
28    if document.can_delete:
29
30        if document.delete():
31            ot.add("Successfully deleted the document")
32        else:
33            ot.add("Failed to delete the document")
34
35        ot.add("New document status: " + StatusAsString(document.status))
36
37    # can undelete a document that was previously deleted (but not yet purged)
38    if document.can_undelete:
39
40        if document.undelete():
41            ot.add("Successfully undeleted the document")
42        else:
43            ot.add("Failed to undelete the document")
44
45        ot.add("New document status: " + StatusAsString(document.status))
46
47    # delete the document again (after undelete)
48    if document.can_delete:
49
50        if document.delete():
51            ot.add("Successfully deleted the document")
52        else:
53            ot.add("Failed to delete the document")
54
55        ot.add("New document status: " + StatusAsString(document.status))
56
57    # data purge the document
58    if document.can_purge:
59
60        if document.purge():
61            ot.add("Successfully purged the document file data")
62        else:
63            ot.add("Failed to purge the document file data")
64
65        ot.add("New document status: " + StatusAsString(document.status))
66
67    # finally obliterate the document
68    if document.can_obliterate:
69
70        if document.obliterate():
71            ot.add("Successfully obliterated the document")
72        else:
73            ot.add("Failed to obliterate the document")
74
75        # the IDocument interface is no longer valid at this point
76
77else:
78
79    ot.add("Unable to find the document with ID '" + documentID + "'")
80
81ot.clear()