'Commit the import job to the DB
@param ignore_errors: skip any items with errors
(does still report the errors)
@param log_items: callback function to log import items
before committing them'

def commit(self, ignore_errors=False, log_items=None):

    ATTRIBUTE = current.xml.ATTRIBUTE
    METHOD = S3ImportItem.METHOD
    import_list = []
    for item_id in self.items:
        self.resolve(item_id, import_list)
        if (item_id not in import_list):
            import_list.append(item_id)
    items = self.items
    count = 0
    mtime = None
    created = []
    cappend = created.append
    updated = []
    deleted = []
    tablename = self.table._tablename
    self.log = log_items
    failed = False
    for item_id in import_list:
        item = items[item_id]
        error = None
        if (item.accepted is not False):
            logged = False
            success = item.commit(ignore_errors=ignore_errors)
        else:
            logged = True
            success = ignore_errors
        if (not success):
            failed = True
        error = item.error
        if error:
            current.log.error(error)
            self.error = error
            element = item.element
            if (element is not None):
                if (not element.get(ATTRIBUTE.error, False)):
                    element.set(ATTRIBUTE.error, s3_unicode(self.error))
                if (not logged):
                    self.error_tree.append(deepcopy(element))
        elif (item.tablename == tablename):
            count += 1
            if ((mtime is None) or (item.mtime > mtime)):
                mtime = item.mtime
            if item.id:
                if (item.method == METHOD.CREATE):
                    cappend(item.id)
                elif (item.method == METHOD.UPDATE):
                    updated.append(item.id)
                elif (item.method in (METHOD.MERGE, METHOD.DELETE)):
                    deleted.append(item.id)
    if failed:
        return False
    self.count = count
    self.mtime = mtime
    self.created = created
    self.updated = updated
    self.deleted = deleted
    return True
