def _run_update_personID_table_from_paper():
    '''
    Runs the update on the papers which have been modified since the last run
    This is removing no-longer existing papers from the personid table.

    @note: Update recommended monthly.
    @warning: quite resource intensive.
    '''
    last_log = get_user_log(userinfo='daemon',
                            action='UPITFP',
                            only_most_recent=True)
    if len(last_log) >= 1:
        #select only the most recent papers
        recently_modified, min_date = get_papers_recently_modified(
            date=last_log[0][2])
        insert_user_log(
            'daemon',
            '-1',
            'UPITFP',
            'bibsched',
            'status',
            comment='bibauthorid_daemon, update_personID_table_from_paper',
            timestamp=min_date[0][0])
        bibtask.write_message(
            "update_personID_table_from_paper: Running on: " +
            str(recently_modified),
            stream=sys.stdout,
            verbose=0)
        update_personID_table_from_paper(recently_modified)
    else:
        # Should not process all papers, hence authornames population writes
        # the appropriate log. In case the log is missing, process everything.
        recently_modified, min_date = get_papers_recently_modified()
        insert_user_log(
            'daemon',
            '-1',
            'UPITFP',
            'bibsched',
            'status',
            comment='bibauthorid_daemon, update_personID_table_from_paper',
            timestamp=min_date[0][0])
        bibtask.write_message(
            "update_personID_table_from_paper: Running on: " +
            str(recently_modified),
            stream=sys.stdout,
            verbose=0)
        update_personID_table_from_paper(recently_modified)
def _run_update_personID_table_from_paper():
    '''
    Runs the update on the papers which have been modified since the last run
    This is removing no-longer existing papers from the personid table.

    @note: Update recommended monthly.
    @warning: quite resource intensive.
    '''
    last_log = get_user_log(userinfo='daemon', action='UPITFP', only_most_recent=True)
    if len(last_log) >= 1:
        #select only the most recent papers
        recently_modified, min_date = get_papers_recently_modified(date=last_log[0][2])
        insert_user_log('daemon', '-1', 'UPITFP', 'bibsched', 'status', comment='bibauthorid_daemon, update_personID_table_from_paper', timestamp=min_date[0][0])
        bibtask.write_message("update_personID_table_from_paper: Running on: " + str(recently_modified), stream=sys.stdout, verbose=0)
        update_personID_table_from_paper(recently_modified)
    else:
        # Should not process all papers, hence authornames population writes
        # the appropriate log. In case the log is missing, process everything.
        recently_modified, min_date = get_papers_recently_modified()
        insert_user_log('daemon', '-1', 'UPITFP', 'bibsched', 'status', comment='bibauthorid_daemon, update_personID_table_from_paper', timestamp=min_date[0][0])
        bibtask.write_message("update_personID_table_from_paper: Running on: " + str(recently_modified), stream=sys.stdout, verbose=0)
        update_personID_table_from_paper(recently_modified)
def _run_update_personID_table_from_paper(record_ids=None, all_records=False):
    """
    Runs the update on the papers which have been modified since the last run
    This is removing no-longer existing papers from the personid table.

    @note: Update recommended monthly.
    @warning: quite resource intensive.
    """
    if not record_ids and not all_records:
        last_log = get_user_log(userinfo="daemon", action="UPITFP", only_most_recent=True)
        if len(last_log) >= 1:
            # select only the most recent papers
            recently_modified, min_date = get_papers_recently_modified(date=last_log[0][2])
            insert_user_log(
                "daemon",
                "-1",
                "UPITFP",
                "bibsched",
                "status",
                comment="bibauthorid_daemon, update_personID_table_from_paper",
                timestamp=min_date[0][0],
            )

            if not recently_modified:
                bibtask.write_message(
                    "update_personID_table_from_paper: " "All person entities up to date.", stream=sys.stdout, verbose=0
                )
            else:
                bibtask.write_message(
                    "update_personID_table_from_paper: Running on: " + str(recently_modified),
                    stream=sys.stdout,
                    verbose=0,
                )
                update_personID_table_from_paper(recently_modified)
        else:
            # Should not process all papers, hence authornames population writes
            # the appropriate log. In case the log is missing, process everything.
            recently_modified, min_date = get_papers_recently_modified()
            insert_user_log(
                "daemon",
                "-1",
                "UPITFP",
                "bibsched",
                "status",
                comment="bibauthorid_daemon, update_personID_table_from_paper",
                timestamp=min_date[0][0],
            )
            bibtask.write_message(
                "update_personID_table_from_paper: Running on: " + str(recently_modified), stream=sys.stdout, verbose=0
            )
            update_personID_table_from_paper(recently_modified)
        # @todo: develop a method that removes the respective VAs from the database
        # as well since no reference will be there for them any longer. VAs can be
        # found by searching for the authornames ID in the VA table. The
        # method has to kill RA data based on the VA (cf. del_ra_data_by_vaid in
        # ra utils as a reference), all VA2RA links, all VA data, all VAs and
        # finally all doclist refs that point to the respective bibrefs.
    else:
        update_personID_table_from_paper(record_ids)
def _run_update_personID_table_from_paper(record_ids=None, all_records=False):
    '''
    Runs the update on the papers which have been modified since the last run
    This is removing no-longer existing papers from the personid table.

    @note: Update recommended monthly.
    @warning: quite resource intensive.
    '''
    if not record_ids and not all_records:
        last_log = get_user_log(userinfo='daemon',
                                action='UPITFP',
                                only_most_recent=True)
        if len(last_log) >= 1:
            #select only the most recent papers
            recently_modified, min_date = get_papers_recently_modified(
                date=last_log[0][2])
            insert_user_log(
                'daemon',
                '-1',
                'UPITFP',
                'bibsched',
                'status',
                comment='bibauthorid_daemon, update_personID_table_from_paper',
                timestamp=min_date[0][0])

            if not recently_modified:
                bibtask.write_message(
                    "update_personID_table_from_paper: "
                    "All person entities up to date.",
                    stream=sys.stdout,
                    verbose=0)
            else:
                bibtask.write_message(
                    "update_personID_table_from_paper: Running on: " +
                    str(recently_modified),
                    stream=sys.stdout,
                    verbose=0)
                update_personID_table_from_paper(recently_modified)
        else:
            # Should not process all papers, hence authornames population writes
            # the appropriate log. In case the log is missing, process everything.
            recently_modified, min_date = get_papers_recently_modified()
            insert_user_log(
                'daemon',
                '-1',
                'UPITFP',
                'bibsched',
                'status',
                comment='bibauthorid_daemon, update_personID_table_from_paper',
                timestamp=min_date[0][0])
            bibtask.write_message(
                "update_personID_table_from_paper: Running on: " +
                str(recently_modified),
                stream=sys.stdout,
                verbose=0)
            update_personID_table_from_paper(recently_modified)
        # @todo: develop a method that removes the respective VAs from the database
        # as well since no reference will be there for them any longer. VAs can be
        # found by searching for the authornames ID in the VA table. The
        # method has to kill RA data based on the VA (cf. del_ra_data_by_vaid in
        # ra utils as a reference), all VA2RA links, all VA data, all VAs and
        # finally all doclist refs that point to the respective bibrefs.
    else:
        update_personID_table_from_paper(record_ids)