Skip image upload to Wikidata (nearby -> green pins) (#6349)
Some checks failed
Android CI / Run tests and generate APK (push) Has been cancelled

* Skip image upload to Wikidata if item already has image

* Re-run CI

* no more Failed to update Wikidata for green pins
This commit is contained in:
Sonal Yadav 2025-06-22 19:10:15 +05:30 committed by GitHub
parent ca5c7ec966
commit 09da7b8d68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 13 deletions

View file

@ -472,7 +472,10 @@ class UploadWorker(
if (wikiDataPlace != null) { if (wikiDataPlace != null) {
if (!contribution.hasInvalidLocation()) { if (!contribution.hasInvalidLocation()) {
var revisionID: Long? = null var revisionID: Long? = null
val p18WasSkipped = !wikiDataPlace.imageValue.isNullOrBlank()
try { try {
if (!p18WasSkipped) {
// Only set P18 if the place does not already have a picture
revisionID = revisionID =
wikidataEditService.createClaim( wikidataEditService.createClaim(
wikiDataPlace, wikiDataPlace,
@ -489,9 +492,11 @@ class UploadWorker(
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.blockingAwait() .blockingAwait()
Timber.d("Updated WikiItem place ${place.name} with image ${place.pic}") Timber.d("Updated WikiItem place ${place.name} with image ${place.pic}")
}
} }
showSuccessNotification(contribution)
} }
// Always show success notification, whether P18 was set or skipped
showSuccessNotification(contribution)
} catch (exception: Exception) { } catch (exception: Exception) {
Timber.e(exception) Timber.e(exception)
} }
@ -500,6 +505,7 @@ class UploadWorker(
wikidataEditService.handleImageClaimResult( wikidataEditService.handleImageClaimResult(
contribution.wikidataPlace!!, contribution.wikidataPlace!!,
revisionID, revisionID,
p18WasSkipped = p18WasSkipped
) )
} }
} else { } else {

View file

@ -196,13 +196,16 @@ class WikidataEditService @Inject constructor(
return wikidataClient.setClaim(claim, COMMONS_APP_TAG).blockingSingle() return wikidataClient.setClaim(claim, COMMONS_APP_TAG).blockingSingle()
} }
fun handleImageClaimResult(wikidataItem: WikidataItem, revisionId: Long?) { fun handleImageClaimResult(wikidataItem: WikidataItem, revisionId: Long?, p18WasSkipped: Boolean = false) {
if (revisionId != null) { if (revisionId != null) {
wikidataEditListener?.onSuccessfulWikidataEdit() wikidataEditListener?.onSuccessfulWikidataEdit()
showSuccessToast(wikidataItem.name) showSuccessToast(wikidataItem.name)
} else { } else if (!p18WasSkipped) {
Timber.d("Unable to make wiki data edit for entity %s", wikidataItem) Timber.d("Unable to make wiki data edit for entity %s", wikidataItem)
showLongToast(context, context.getString(R.string.wikidata_edit_failure)) showLongToast(context, context.getString(R.string.wikidata_edit_failure))
} else {
Timber.d("Wikidata edit skipped for entity %s because P18 already exists", wikidataItem)
// No error shown to user, as this is not a failure
} }
} }

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Authors:
* Vlad5250
-->
<resources>
<string name="crash_dialog_title">کامَنٕز گوو رُکِتھ</string>
<string name="crash_dialog_text">Oops. کیہہ تام گوو غلط!</string>
<string name="crash_dialog_comment_prompt">ؤنِیوٚ اَسہِ توٚہہِ کیاہ ٲسِیوٚ کران، تہٕ کٕریٚو تہِ اَسہِ سٕتی شیر بذریعہِ برقی خط. یُس مَدَتھ کَرِ اَسہِ اَتھ شہَرنَس منٛز!</string>
<string name="crash_dialog_ok_toast">شُکریہ!</string>
</resources>