Mglaser has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/376671 )

Change subject: Added migration scripts for...
......................................................................

Added migration scripts for...

* ... SemanticForms to PageForms
* ... reset of $smwgNamespaceIndex to default

Change-Id: Ib949c1a9e5f5359b51fd1a2c6d9d8b7bc6d3a6b1
(cherry picked from commit d718733959870ccfc296b182e8759b697bb9ae9d)
---
A maintenance/ChangeSMWOffsetNamespaceIds.php
A maintenance/MigrateSemanticFormsToPageForms.php
2 files changed, 207 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceSMWConnector 
refs/changes/71/376671/1

diff --git a/maintenance/ChangeSMWOffsetNamespaceIds.php 
b/maintenance/ChangeSMWOffsetNamespaceIds.php
new file mode 100644
index 0000000..5b4f524
--- /dev/null
+++ b/maintenance/ChangeSMWOffsetNamespaceIds.php
@@ -0,0 +1,92 @@
+<?php
+
+require '../../../maintenance/Maintenance.php';
+
+class ChangeSMWOffsetNamespaceIds extends Maintenance {
+
+       protected $namespaceIdMap = [
+               700 => 100,
+               701 => 101,
+               702 => 102,
+               703 => 103,
+               704 => 104,
+               705 => 105,
+               706 => 106
+       ];
+
+       protected $tablesAndFields = [
+               'archive' => [ 'ar_namespace' ],
+               'page' => [ 'page_namespace' ],
+               'pagelinks' => [ 'pl_namespace' ],
+               'templatelinks' => [ 'tl_namespace' ],
+               'logging' => [ 'log_namespace' ],
+               'job' => [ 'job_namespace' ],
+               'redirect' => [ 'rd_namespace' ],
+               'recentchanges' => [ 'rc_namespace' ],
+               'querycache' =>  [ 'qc_namespace' ],
+               'querycachetwo' =>  [ 'qcc_namespace', 'qcc_namespacetwo' ],
+               'protected_titles' => [ 'pt_namespace' ],
+               'watchlist' => [ 'wl_namespace' ]
+       ];
+
+
+       public function execute() {
+               $this->output(
+<<<HERE
+
+WARNING: This script will perform changes directly on the database! If you have
+not yet created a backup, please abort and do so now!
+
+HERE
+               );
+               wfCountDown( 5 );
+
+               $this->output( "Too late ..." );
+
+               foreach( $this->tablesAndFields as $tableName => $fieldNames ) {
+                       foreach( $fieldNames as $fieldName ) {
+                               $this->output("\Processing 
$tableName.$fieldName ..." );
+                               $this->fixNamespaceIds(
+                                       $tableName,
+                                       $fieldName
+                               );
+                               $this->output( "\n" );
+                       }
+               }
+       }
+
+       protected function fixNamespaceIds( $tableName, $fieldName ) {
+               foreach( $this->namespaceIdMap as $oldNS => $newNS ) {
+                       $this->output( "\nNamespace '$oldNS': " );
+                       $numberOfEntriesToChange = $this->getDB( DB_SLAVE )
+                               ->selectRowCount(
+                                       $tableName,
+                                       '*',
+                                       [
+                                               $fieldName => $oldNS
+                                       ]
+                               );
+                       if( $numberOfEntriesToChange === 0 ) {
+                               $this->output( "Nothing to do.");
+                               continue;
+                       }
+                       $this->output( "Found: $numberOfEntriesToChange\n");
+                       $this->output( "Changing ..." );
+
+                       $res = $this->getDB( DB_MASTER )->update(
+                               $tableName,
+                               [
+                                       $fieldName => $newNS
+                               ],
+                               [
+                                       $fieldName => $oldNS
+                               ]
+                       );
+                       $this->output( " done." );
+               }
+       }
+
+}
+
+$maintClass = 'ChangeSMWOffsetNamespaceIds';
+require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file
diff --git a/maintenance/MigrateSemanticFormsToPageForms.php 
b/maintenance/MigrateSemanticFormsToPageForms.php
new file mode 100644
index 0000000..58c4f1b
--- /dev/null
+++ b/maintenance/MigrateSemanticFormsToPageForms.php
@@ -0,0 +1,115 @@
+<?php
+
+require '../../../maintenance/Maintenance.php';
+
+class MigrateSemanticFormsToPageForms extends Maintenance {
+
+       protected $propHasDefaultFormVariants = [
+               'لديه استمارة افتراضية',
+               'Fa servir el formulari per defecte',
+               'Hat Standardformular',
+               'Έχει προεπιλεγμένη φόρμα',
+               'Has default form',
+               'Usa el formulario por defecto',
+               'فرم پیش‌فرض دارد',
+               'Oletuslomake',
+               'Utilise le formulaire',
+               'משתמש בטופס',
+               'Memiliki formulir bawaan',
+               'Usa il modulo predefinito',
+               'Heeft standaard formulier',
+               'Har standardskjema',
+               '预设表单',
+               '預設表單'
+       ];
+
+       protected $pagesToChange = [];
+
+       public function execute() {
+               $this->output( "Searching for pages with [[Has default 
form::+]] ..." );
+               foreach( $this->propHasDefaultFormVariants as $propName ) {
+                       $this->executeAsk( $propName );
+               }
+               $count = count( $this->pagesToChange );
+               $this->output( " done.\nFound: " . $count );
+               if( $count === 0 ) {
+                       $this->output( "\nNothing to do.\n" );
+                       return;
+               }
+
+               $this->output( "\nModifying..." );
+               foreach( $this->pagesToChange as $pageName => $dummyVal ) {
+                       $this->replacePropertyByParserFunction( $pageName );
+               }
+               $this->output( "\n... done.\n" );
+       }
+
+       protected function executeAsk( $propName ) {
+               global $wgRequest;
+                $api = new ApiMain(
+                       new DerivativeRequest(
+                               $wgRequest,
+                               array(
+                                       'action' => 'askargs',
+                                       'conditions' => "$propName::+",
+                                       'parameters' => 'limit=9999'
+                               )
+                       )
+               );
+
+               $api->execute();
+               $data = $api->getResult()->getResultData();
+
+               if( !empty( $data['query'] ) && !empty( 
$data['query']['results'] ) ) {
+                       foreach( $data['query']['results'] as $pageName => 
$printout ) {
+                               $this->pagesToChange[$pageName] = true;
+                       }
+               }
+       }
+
+       protected function replacePropertyByParserFunction( $pageName ) {
+               $this->output( "\n\t$pageName" );
+               $wikiPage = Wikipage::factory( Title::newFromText( $pageName ) 
);
+               $content = $wikiPage->getContent();
+               if( $content instanceof WikitextContent === false ) {
+                       $this->output( "--> No WikiText. Can not modify." );
+                       return;
+               }
+               $wikiText = $content->getNativeData();
+               $wikiText = preg_replace_callback(
+                       '#\[\[(.*?)::(.*?)\]\]#',
+                       function( $matches ) {
+                               //Normalize "Has_default form" --> "Has default 
form"
+                               $propName = str_replace( '_', ' ', $matches[1] 
);
+                               if( in_array( $propName, 
$this->propHasDefaultFormVariants ) ) {
+                                       return '{{#default_form:' . 
$this->extractFormName( $matches[2] ).'}}';
+                               }
+                               return $matches[0];
+                       },
+                       $wikiText
+               );
+               $status = $wikiPage->doEditContent(
+                       ContentHandler::makeContent( $wikiText, 
$wikiPage->getTitle()),
+                       "SemanticForms to PageForms, done by ".self::class
+               );
+
+               if( $status->isOK() ) {
+                       $this->output( ' OK.');
+               }
+               else {
+                       $this->output( 'Error: ' . 
$status->getMessage()->plain() );
+               }
+       }
+
+       protected function extractFormName( $formNameAndMaybeAlias ) {
+               //This is not actually neccessary as
+               //{{#default_form:SomeForm|Alias}} (derived from [[Has default 
from::SomeForm|Alias]])
+               //will work the same as
+               //{{#default_form:SomeForm}}
+               $parts = explode( '|', $formNameAndMaybeAlias );
+               return $parts[0];
+       }
+}
+
+$maintClass = 'MigrateSemanticFormsToPageForms';
+require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib949c1a9e5f5359b51fd1a2c6d9d8b7bc6d3a6b1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceSMWConnector
Gerrit-Branch: REL1_27_dev
Gerrit-Owner: Mglaser <gla...@hallowelt.biz>
Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz>

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

Reply via email to