Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/195505
Change subject: Database: Set targetURL only when status is published ...................................................................... Database: Set targetURL only when status is published Currently we update translation record in CX database for save and publish actions. For both, we update the translation URL. But translation URL update should happen only when publishing happens. Otherwise, we just calculate a URL and add to record, a URL that does not exist. Changed the upsert query to save the translation to separate insert and update queries. Bug: T91365 Change-Id: I4cd9aa09bcac5318e3ee93e32abe1bf2d49be331 --- M api/ApiContentTranslationPublish.php M includes/Translation.php 2 files changed, 54 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/05/195505/1 diff --git a/api/ApiContentTranslationPublish.php b/api/ApiContentTranslationPublish.php index 7cdc517..ae481a4 100644 --- a/api/ApiContentTranslationPublish.php +++ b/api/ApiContentTranslationPublish.php @@ -222,8 +222,7 @@ ); $targetURL = ContentTranslation\SiteMapper::getPageURL( $params['to'], $targetTitle ); } - - $translation = new ContentTranslation\Translation( array( + $translation = array( 'sourceTitle' => $params['sourcetitle'], 'targetTitle' => $params['title'], 'sourceLanguage' => $params['from'], @@ -231,15 +230,19 @@ 'sourceURL' => ContentTranslation\SiteMapper::getPageURL( $params['from'], $params['sourcetitle'] ), - 'targetURL' => $targetURL, 'status' => $params['status'], 'progress' => $params['progress'], - // XXX Do not overwrite startedTranslator when we have "draft save" feature. + // XXX Do not overwrite startedTranslator when we have collaborative editing! 'startedTranslator' => $translator->getGlobalUserId(), 'lastUpdatedTranslator' => $translator->getGlobalUserId(), - ) ); - $translation->save(); - $translationId = $translation->getTranslationId(); + ); + // Save targetURL only when the status is published. + if ( $params['status'] === 'published' ) { + $translation['targetURL'] = $targetURL; + }; + $cxtranslation = new ContentTranslation\Translation( $translation ); + $cxtranslation->save(); + $translationId = $cxtranslation->getTranslationId(); $translator->addTranslation( $translationId ); if ( $params['status'] === 'draft' ) { // Save the draft diff --git a/includes/Translation.php b/includes/Translation.php index 9cf1ca1..f2b4d07 100644 --- a/includes/Translation.php +++ b/includes/Translation.php @@ -9,7 +9,7 @@ $this->translation = $translation; } - public function save() { + public function create() { $dbw = Database::getConnection( DB_MASTER ); $values = array( 'translation_source_title' => $this->translation['sourceTitle'], @@ -17,25 +17,59 @@ 'translation_source_language' => $this->translation['sourceLanguage'], 'translation_target_language' => $this->translation['targetLanguage'], 'translation_source_url' => $this->translation['sourceURL'], - 'translation_target_url' => $this->translation['targetURL'], 'translation_status' => $this->translation['status'], - // XXX do not overwrite when we have "draft save" feature. - 'translation_start_timestamp' => $dbw->timestamp(), 'translation_last_updated_timestamp' => $dbw->timestamp(), 'translation_progress' => $this->translation['progress'], - 'translation_started_by' => $this->translation['startedTranslator'], 'translation_last_update_by' => $this->translation['lastUpdatedTranslator'], ); - $dbw->upsert( + $values['translation_start_timestamp'] = $dbw->timestamp(); + $values['translation_started_by'] = $this->translation['startedTranslator']; + if ( $this->translation['status'] === 'published' ) { + $values['translation_target_url'] = $this->translation['targetURL']; + } + $dbw->insert( 'cx_translations', - $values, - array( 'translation_id' ), $values, __METHOD__ ); + $this->translation['id'] = $dbw->insertId(); + } - if ( !isset( $this->translation['id'] ) ) { - $this->translation['id'] = $dbw->insertId(); + public function update() { + $dbw = Database::getConnection( DB_MASTER ); + $values = array( + 'translation_source_title' => $this->translation['sourceTitle'], + 'translation_target_title' => $this->translation['targetTitle'], + 'translation_source_language' => $this->translation['sourceLanguage'], + 'translation_target_language' => $this->translation['targetLanguage'], + 'translation_source_url' => $this->translation['sourceURL'], + 'translation_status' => $this->translation['status'], + 'translation_last_updated_timestamp' => $dbw->timestamp(), + 'translation_progress' => $this->translation['progress'], + 'translation_last_update_by' => $this->translation['lastUpdatedTranslator'], + ); + if ( $this->translation['status'] === 'published' ) { + $values['translation_target_url'] = $this->translation['targetURL']; + } + $dbw->update( + 'cx_translations', + $values, + array( 'translation_id' => $this->translation['id'] ), + __METHOD__ + ); + } + + public function save() { + $existingTranslation = Translation::find( + $this->translation['sourceLanguage'], + $this->translation['targetLanguage'], + $this->translation['sourceTitle'] + ); + if ( $existingTranslation === null ) { + $this->create(); + } else { + $this->translation['id'] = $existingTranslation->getTranslationId(); + $this->update(); } } -- To view, visit https://gerrit.wikimedia.org/r/195505 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4cd9aa09bcac5318e3ee93e32abe1bf2d49be331 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits