'Add new entries into archive. We use learn phase in case the task corrects title or url via some plugins.'

def on_task_learn(self, task, config):

    if isinstance(config, bool):
        tag_names = []
    else:
        tag_names = config
    tags = []
    for tag_name in set(tag_names):
        tags.append(get_tag(tag_name, task.session))
    count = 0
    processed = []
    for entry in ((task.entries + task.rejected) + task.failed):
        if (entry in processed):
            continue
        else:
            processed.append(entry)
        ae = task.session.query(ArchiveEntry).filter((ArchiveEntry.title == entry[u'title'])).filter((ArchiveEntry.url == entry[u'url'])).first()
        if ae:
            source = get_source(task.name, task.session)
            if (source not in ae.sources):
                log.debug((u'Adding    `%s`    into    `%s`    sources' % (task.name, ae)))
                ae.sources.append(source)
            for tag_name in tag_names:
                atag = get_tag(tag_name, task.session)
                if (atag not in ae.tags):
                    log.debug((u'Adding    tag    %s    into    %s' % (tag_name, ae)))
                    ae.tags.append(atag)
        else:
            ae = ArchiveEntry()
            ae.title = entry[u'title']
            ae.url = entry[u'url']
            if (u'description' in entry):
                ae.description = entry[u'description']
            ae.task = task.name
            ae.sources.append(get_source(task.name, task.session))
            if tags:
                ae.tags.extend(tags)
            log.debug((u'Adding    `%s`    with    %i    tags    to    archive' % (ae, len(tags))))
            task.session.add(ae)
            count += 1
    if count:
        log.verbose((u'Added    %i    new    entries    to    archive' % count))
