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 cleanTemporaryElements(): common.addState(6) for temp in list(Element.select().where(Element.status == common.TEMP)): temp.delete_instance(silent=True) log.info("Removeing temp elements DONE") common.removeState(6)
def deleteOrphanElements(): log.info("Getting elements") elements = Element.select() delete_count = 0 for element in list(elements): try: if element.parent: _ = element.parent except Element.DoesNotExist: log("deleting element %s" % element.get_id()) #element.delete_instance(silent=True) super(Element, element).delete_instance() delete_count += 1 log.info("deleted %s orphanaged elements" % delete_count)
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 deleteOrphanImages(): log.info("Getting orphanaged images") elements = Element.select() image_dq = Image.delete().where(~(Image.element << elements)) deleted_rows = image_dq.execute() log.info("Deleted %s orphanaged images" % deleted_rows)
def deleteOrphanFields(): log.info("Getting orphanaged fields") elements = Element.select() fields_dq = Field.delete().where(~(Field.element << elements)) deleted_rows = fields_dq.execute() log.info("Deleted %s orphanaged fields" % deleted_rows)
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)