def deleteOrphanElements(): """this will delete elements with no parent and are not root elements""" roots = [mtm.root for mtm in common.PM.getMediaTypeManager(returnAll=True)] if not roots: return lost_children = Element.select().where(Element.parent >> None, ~(Element.id << roots)) for lost_child in lost_children: log.info("Element %s is lost. Begone." % lost_child.id) Element.delete().where(Element.id << lost_children).execute()
def deleteOrphanElements(): """this will delete elements with no parent and are not root elements""" roots = [mtm.root for mtm in common.PM.getMediaTypeManager(returnAll=True)] if not roots: return lost_children = Element.select().where(Element.parent >> None, ~(Element.id << roots)) for lost_child in lost_children: log.info("Element %s is lost. Begone." % lost_child.id) for element in Element.select().where(~(Element.id << roots)): try: element.parent except element.DoesNotExist: log.info("Element %s parents are dead. Begone." % element.id) Element.delete().where(Element.id == element.id).execute() Element.delete().where(Element.id << lost_children).execute()
def cleanTemporaryElements(): log.info("Getting temp elements") elements_dq = Element.delete().where(Element.status == common.TEMP) deleted_rows = elements_dq.execute() log.info("Deleted %s temp elements" % deleted_rows)