Skip to content

Commit

Permalink
Merge branch 'hotfix/3857_harvest_errors'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Eardley committed Jan 13, 2025
2 parents 288f6f7 + 9eccc49 commit a5d1d64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions portality/bll/services/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def _prepare_update_admin(article, duplicate, update_article_id, merge_duplicate

is_update = 0
if duplicate is not None:
if duplicate.id != update_article_id:
if update_article_id is not None and duplicate.id != update_article_id:
# it means that doi or ft url has been changed so that it duplicates existing article
raise exceptions.DuplicateArticleException(Messages.EXCEPTION_IDENTIFIER_CHANGE_CLASH)
elif merge_duplicate:
is_update += 1
article.merge(duplicate)
elif merge_duplicate: # requested to update article has both url and doi changed to new values - no duplicate detected
elif update_article_id is not None and merge_duplicate: # requested to update article has both url and doi changed to new values - no duplicate detected
is_update += 1
art = models.Article.pull(update_article_id)
article.merge(art)
Expand Down Expand Up @@ -227,7 +227,7 @@ def create_article(self, article, account, duplicate_check=True, merge_duplicate
# ~~!ArticleCreate:Feature->ArticleDeduplication:Feature~~
duplicate = self.get_duplicate(article)
try:
if account.has_role("admin") and update_article_id is not None: # is update_article_id is None then treat as normal publisher upload
if account.has_role("admin"): # is update_article_id is None then treat as normal publisher upload
# for testing by admin
is_update = self._prepare_update_admin(article, duplicate, update_article_id, merge_duplicate)
else:
Expand Down
17 changes: 14 additions & 3 deletions portality/tasks/harvester_helpers/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
from portality.lib.dataobj import DataObjException


SYSTEM_ACCOUNT = {
"email": app.config['ADMIN_EMAIL'],
"name": "harvest_background_job",
"role": ['admin'],
"id": "harvest_background_job"
}

sys_acc = Account(**SYSTEM_ACCOUNT)


class DefaultLogger(object):
def __init__(self):
self._log = []
Expand Down Expand Up @@ -110,12 +120,13 @@ def process_article(self, account_id, article):
Report.record_error((article.get_identifier("doi") or "< DOI MISSING >") + " - " + str(e))
return False

acc = Account.pull(account_id)
try:
id = ArticlesCrudApi.create(article.data, acc).id
# Use the admin account to have sufficient rights to update full text or doi.
# Related github issue #3857
id = ArticlesCrudApi.create(article.data, sys_acc).id
except Exception as e:
self._write_to_logger("Article caused DOAJException: {m} ... skipping".format(m=e))
Report.record_error((article.get_identifier("doi") or "< DOI MISSING >"))
return False
self._write_to_logger("Created article in DOAJ for Account:{x} with ID: {y}".format(x=account_id, y=id))
self._write_to_logger("Created article in DOAJ for Account:{x} with ID: {y}".format(x=sys_acc.id, y=id))
return True

0 comments on commit a5d1d64

Please sign in to comment.