Document Deleting

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