Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311440

Change subject: Implement hook for deleted pages
......................................................................

Implement hook for deleted pages

Change-Id: If25f56c31b94f8d6db204deffe3fa732ebaeafc5
---
M src/CognateHooks.php
M src/CognateStore.php
M tests/phpunit/CognateStoreTest.php
3 files changed, 40 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cognate 
refs/changes/40/311440/1

diff --git a/src/CognateHooks.php b/src/CognateHooks.php
index bc06317..8bd0c19 100644
--- a/src/CognateHooks.php
+++ b/src/CognateHooks.php
@@ -50,14 +50,24 @@
        }
 
        public static function onArticleDeleteComplete(
-               &$article,
+               WikiPage &$article,
                User &$user,
                $reason,
                $id,
                Content $content = null,
                LogEntry $logEntry
        ) {
-               // TODO remove language link from central storage
+               global $wgCognateNamespaces, $wgLanguageCode;
+
+               $title = $article->getTitle();
+               if ( !in_array( $title->getNamespace(), $wgCognateNamespaces ) 
) {
+                       return true;
+               }
+
+               $interlanguage = MediaWikiServices::getInstance()->getService( 
'CognateStore' );
+               $interlanguage->deletePage( $wgLanguageCode, 
$article->getTitle()->getDBkey() );
+
+               return true;
        }
 
        /**
diff --git a/src/CognateStore.php b/src/CognateStore.php
index 2b8fc22..8a37ee7 100644
--- a/src/CognateStore.php
+++ b/src/CognateStore.php
@@ -38,6 +38,23 @@
        }
 
        /**
+        * @param string $language Language code, taken from $wgLanguageCode
+        * @param string $title Page title
+        * @return bool
+        */
+       public function deletePage( $language, $title ) {
+               $pageData = [
+                       'ilt_language' => $language,
+                       'ilt_title' => $title
+               ];
+               $dbw = $this->loadBalancer->getConnection( DB_MASTER );
+               $result = $dbw->delete( self::TABLE_NAME, $pageData, __METHOD__ 
);
+               $this->loadBalancer->reuseConnection( $dbw );
+
+               return $result;
+       }
+
+       /**
         * Get the language codes where a translations is available
         *
         * @param string $language Language code to exclude
diff --git a/tests/phpunit/CognateStoreTest.php 
b/tests/phpunit/CognateStoreTest.php
index 373fe57..7016c43 100644
--- a/tests/phpunit/CognateStoreTest.php
+++ b/tests/phpunit/CognateStoreTest.php
@@ -46,4 +46,15 @@
                $this->assertArrayEquals( [ 'de', 'eo' ], $languages );
        }
 
+       public function testSaveAndDeletePageResultsInNoEntry() {
+               $this->interlanguage->savePage( 'en', 'My_test_page' );
+               $this->interlanguage->deletePage( 'en', 'My_test_page' );
+               $this->assertSelect(
+                       'inter_language_titles',
+                       [ 'ilt_language', 'ilt_title' ],
+                       [ 'ilt_title != "UTPage"' ],
+                       []
+               );
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/311440
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If25f56c31b94f8d6db204deffe3fa732ebaeafc5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cognate
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to