'Constructor
@param tree: the element tree to import
@param files: files attached to the import (for upload fields)
@param job_id: restore job from database (record ID or job_id)
@param strategy: the import strategy
@param update_policy: the update policy
@param conflict_policy: the conflict resolution policy
@param last_sync: the last synchronization time stamp (datetime)
@param onconflict: custom conflict resolver function'

def __init__(self, table, tree=None, files=None, job_id=None, strategy=None, update_policy=None, conflict_policy=None, last_sync=None, onconflict=None):

    self.error = None
    self.error_tree = etree.Element(current.xml.TAG.root)
    self.table = table
    self.tree = tree
    self.files = files
    self.directory = Storage()
    self.mandatory_fields = Storage()
    self.elements = Storage()
    self.items = Storage()
    self.references = []
    self.job_table = None
    self.item_table = None
    self.count = 0
    self.created = []
    self.updated = []
    self.deleted = []
    self.log = None
    if (strategy is None):
        METHOD = S3ImportItem.METHOD
        strategy = [METHOD.CREATE, METHOD.UPDATE, METHOD.DELETE, METHOD.MERGE]
    if (not isinstance(strategy, (tuple, list))):
        strategy = [strategy]
    self.strategy = strategy
    if update_policy:
        self.update_policy = update_policy
    else:
        self.update_policy = S3ImportItem.POLICY.OTHER
    if conflict_policy:
        self.conflict_policy = conflict_policy
    else:
        self.conflict_policy = S3ImportItem.POLICY.OTHER
    self.mtime = None
    self.last_sync = last_sync
    self.onconflict = onconflict
    if job_id:
        self.__define_tables()
        jobtable = self.job_table
        if str(job_id).isdigit():
            query = (jobtable.id == job_id)
        else:
            query = (jobtable.job_id == job_id)
        row = current.db(query).select(jobtable.job_id, jobtable.tablename, limitby=(0, 1)).first()
        if (not row):
            raise SyntaxError('Job    record    not    found')
        self.job_id = row.job_id
        self.second_pass = True
        if (not self.table):
            tablename = row.tablename
            try:
                table = current.s3db[tablename]
            except:
                pass
    else:
        self.job_id = uuid.uuid4()
        self.second_pass = False
