From 61bd021ded319a3f84e9a7695772869b8ca0119d Mon Sep 17 00:00:00 2001 From: paladox Date: Tue, 19 Sep 2023 14:50:27 +0100 Subject: [PATCH 1/5] Add findSQLPatches and findPossibleUpgradeScripts scripts The scripts are from @Universal-Omega but I modified them to suit our needs. --- maintenance/findSQLPatches.php | 108 +++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 maintenance/findSQLPatches.php diff --git a/maintenance/findSQLPatches.php b/maintenance/findSQLPatches.php new file mode 100644 index 000000000..ac0dc0958 --- /dev/null +++ b/maintenance/findSQLPatches.php @@ -0,0 +1,108 @@ +addDescription( 'List new or updated SQL patches between two MediaWiki versions.' ); + + $this->addOption( 'from-version', 'Path for MediaWiki version to start from', true, true ); + $this->addOption( 'to-version', 'Path for MediaWiki version to end with', true, true ); + } + + public function execute() { + $fromVersionPath = $this->getOption( 'from-version-path' ); + $toVersionPath = $this->getOption( 'to-version-path' ); + $patches = []; + $this->findPatches( $fromVersionPath, $toVersionPath, $patches ); + foreach ( $patches as $patch ) { + $this->output( $patch . "\n" ); + } + + $this->output( "\nCount: " . count( $patches ) . "\n" ); + } + + private function findPatches( $fromVersionPath, $toVersionpath, &$patches ) { + $fromPatches = $this->findSqlPatches( $fromVersionPath ); + $toPatches = $this->findSqlPatches( $toVersionpath ); + foreach ( $toPatches as $patch ) { + $filename = basename( $patch ); + if ( array_key_exists( $filename, $fromPatches ) ) { + if ( $this->isPatchUpdated( $fromPatches[$filename], $patch ) ) { + $patches[] = $patch; + } + } else { + $patches[] = $patch; + } + } + } + + private function findSqlPatches( $path ) { + $patches = []; + + $files = $this->findFilesRecursively( $path ); + + foreach ( $files as $file ) { + if ( + str_contains( $file, '/postgres/' ) || + str_contains( $file, '/sqlite/' ) || + str_contains( $file, '/tests/' ) + ) { + continue; + } + + $patches[basename( $file )] = $file; + } + + return $patches; + } + + private function isPatchUpdated( $oldPatch, $newPatch ) { + // TO-DO + } + + private function findFilesRecursively( $pattern ) { + $files = glob( $pattern ); + foreach ( glob( dirname( $pattern ) . '/*', GLOB_ONLYDIR | GLOB_NOSORT ) as $dir ) { + $files = array_merge( + [], + ...[ $files, $this->findFilesRecursively( $dir . '/' . basename( $pattern ) ) ] + ); + } + + return $files; + } +} + +$maintClass = FindSQLPatches::class; +require_once RUN_MAINTENANCE_IF_MAIN; From a06998df43cae4c96a99e8f03bc7f7351371dfa7 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Sep 2023 13:52:43 +0000 Subject: [PATCH 2/5] CI: lint code to MediaWiki standards Check commit and GitHub actions for more details --- maintenance/findSQLPatches.php | 142 ++++++++++++++++----------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/maintenance/findSQLPatches.php b/maintenance/findSQLPatches.php index ac0dc0958..46128b9d1 100644 --- a/maintenance/findSQLPatches.php +++ b/maintenance/findSQLPatches.php @@ -31,77 +31,77 @@ require_once '/srv/mediawiki/1.40/maintenance/Maintenance.php'; class FindSQLPatches extends Maintenance { - public function __construct() { - parent::__construct(); - - $this->addDescription( 'List new or updated SQL patches between two MediaWiki versions.' ); - - $this->addOption( 'from-version', 'Path for MediaWiki version to start from', true, true ); - $this->addOption( 'to-version', 'Path for MediaWiki version to end with', true, true ); - } - - public function execute() { - $fromVersionPath = $this->getOption( 'from-version-path' ); - $toVersionPath = $this->getOption( 'to-version-path' ); - $patches = []; - $this->findPatches( $fromVersionPath, $toVersionPath, $patches ); - foreach ( $patches as $patch ) { - $this->output( $patch . "\n" ); - } - - $this->output( "\nCount: " . count( $patches ) . "\n" ); - } - - private function findPatches( $fromVersionPath, $toVersionpath, &$patches ) { - $fromPatches = $this->findSqlPatches( $fromVersionPath ); - $toPatches = $this->findSqlPatches( $toVersionpath ); - foreach ( $toPatches as $patch ) { - $filename = basename( $patch ); - if ( array_key_exists( $filename, $fromPatches ) ) { - if ( $this->isPatchUpdated( $fromPatches[$filename], $patch ) ) { - $patches[] = $patch; - } - } else { - $patches[] = $patch; - } - } - } - - private function findSqlPatches( $path ) { - $patches = []; - - $files = $this->findFilesRecursively( $path ); - - foreach ( $files as $file ) { - if ( - str_contains( $file, '/postgres/' ) || - str_contains( $file, '/sqlite/' ) || - str_contains( $file, '/tests/' ) - ) { - continue; - } - - $patches[basename( $file )] = $file; - } - - return $patches; - } - - private function isPatchUpdated( $oldPatch, $newPatch ) { - // TO-DO - } - - private function findFilesRecursively( $pattern ) { - $files = glob( $pattern ); - foreach ( glob( dirname( $pattern ) . '/*', GLOB_ONLYDIR | GLOB_NOSORT ) as $dir ) { - $files = array_merge( - [], - ...[ $files, $this->findFilesRecursively( $dir . '/' . basename( $pattern ) ) ] - ); - } - - return $files; - } + public function __construct() { + parent::__construct(); + + $this->addDescription( 'List new or updated SQL patches between two MediaWiki versions.' ); + + $this->addOption( 'from-version', 'Path for MediaWiki version to start from', true, true ); + $this->addOption( 'to-version', 'Path for MediaWiki version to end with', true, true ); + } + + public function execute() { + $fromVersionPath = $this->getOption( 'from-version-path' ); + $toVersionPath = $this->getOption( 'to-version-path' ); + $patches = []; + $this->findPatches( $fromVersionPath, $toVersionPath, $patches ); + foreach ( $patches as $patch ) { + $this->output( $patch . "\n" ); + } + + $this->output( "\nCount: " . count( $patches ) . "\n" ); + } + + private function findPatches( $fromVersionPath, $toVersionpath, &$patches ) { + $fromPatches = $this->findSqlPatches( $fromVersionPath ); + $toPatches = $this->findSqlPatches( $toVersionpath ); + foreach ( $toPatches as $patch ) { + $filename = basename( $patch ); + if ( array_key_exists( $filename, $fromPatches ) ) { + if ( $this->isPatchUpdated( $fromPatches[$filename], $patch ) ) { + $patches[] = $patch; + } + } else { + $patches[] = $patch; + } + } + } + + private function findSqlPatches( $path ) { + $patches = []; + + $files = $this->findFilesRecursively( $path ); + + foreach ( $files as $file ) { + if ( + str_contains( $file, '/postgres/' ) || + str_contains( $file, '/sqlite/' ) || + str_contains( $file, '/tests/' ) + ) { + continue; + } + + $patches[basename( $file )] = $file; + } + + return $patches; + } + + private function isPatchUpdated( $oldPatch, $newPatch ) { + // TO-DO + } + + private function findFilesRecursively( $pattern ) { + $files = glob( $pattern ); + foreach ( glob( dirname( $pattern ) . '/*', GLOB_ONLYDIR | GLOB_NOSORT ) as $dir ) { + $files = array_merge( + [], + ...[ $files, $this->findFilesRecursively( $dir . '/' . basename( $pattern ) ) ] + ); + } + + return $files; + } } $maintClass = FindSQLPatches::class; From 34d9a7f6b2ee465adf0b5dfdf8643fc1f7a15b51 Mon Sep 17 00:00:00 2001 From: paladox Date: Tue, 19 Sep 2023 14:54:05 +0100 Subject: [PATCH 3/5] Create findPossibleUpgradeScripts.php --- maintenance/findPossibleUpgradeScripts.php | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 maintenance/findPossibleUpgradeScripts.php diff --git a/maintenance/findPossibleUpgradeScripts.php b/maintenance/findPossibleUpgradeScripts.php new file mode 100644 index 000000000..2814cca24 --- /dev/null +++ b/maintenance/findPossibleUpgradeScripts.php @@ -0,0 +1,119 @@ +addDescription( 'List new or updated maintenance scripts between two MediaWiki versions.' ); + + $this->addOption( 'from-version-path', 'Path to MediaWiki version to start from', true, true ); + $this->addOption( 'to-version-path', 'Path to MediaWiki version to end with', true, true ); + } + + public function execute() { + $fromVersionPath = $this->getOption( 'from-version-path' ); + $toVersionPath = $this->getOption( 'to-version-path' ); + $scripts = []; + $this->findScripts( $fromVersionPath, $toVersionPath, $scripts ); + foreach ( $scripts as $script ) { + $this->output( $script . $this->findExtendedClass( $script ) . "\n" ); + } + + $this->output( "\nCount: " . count( $scripts ) . "\n" ); + } + + private function findScripts( $fromVersion, $toVersion, &$scripts ) { + $fromScripts = $this->findMaintenanceScripts( $fromVersionPath ); + $toScripts = $this->findMaintenanceScripts( $toVersionPath ); + foreach ( $toScripts as $script ) { + $filename = basename( $script ); + if ( array_key_exists( $filename, $fromScripts ) ) { + if ( $this->isScriptUpdated( $fromScripts[$filename], $script ) ) { + $scripts[] = $script; + } + } else { + $scripts[] = $script; + } + } + } + + private function findMaintenanceScripts( $path ) { + $scripts = []; + + $files1 = $this->findFilesRecursively( $path . '/**/**/maintenance/*.php' ); + $files2 = $this->findFilesRecursively( $path . '/**/**/**/maintenance/*.php' ); + $coreFiles = $this->findFilesRecursively( $path . '/maintenance/*.php' ); + + foreach ( array_merge( $files1, $files2, $coreFiles ) as $file ) { + if ( str_contains( $file, '/tests/' ) ) { + continue; + } + + $scripts[basename( $file )] = $file; + } + + + return $scripts; + } + + private function isScriptUpdated( $oldScript, $newScript ) { + // TO-DO + } + + private function findFilesRecursively( $pattern ) { + $files = glob( $pattern ); + foreach ( glob( dirname( $pattern ) . '/*', GLOB_ONLYDIR | GLOB_NOSORT ) as $dir ) { + $files = array_merge( + [], + ...[ $files, $this->findFilesRecursively( $dir . '/' . basename( $pattern ) ) ] + ); + } + + return $files; + } + + private function findExtendedClass( $script ) { + $file = file_get_contents( $script ); + if ( preg_match( '/extends\s+([^\s]+)\s+/', $file, $matches ) ) { + if ( $matches[1] !== Maintenance::class ) { + return ' (' . $matches[1] . ')'; + } + } + + return ''; + } +} + + +$maintClass = FindPossibleUpgradeScripts::class; +require_once RUN_MAINTENANCE_IF_MAIN; From 24cc25d26fc8008a00de3609ab9d3beb4cad92bd Mon Sep 17 00:00:00 2001 From: paladox Date: Tue, 19 Sep 2023 14:54:20 +0100 Subject: [PATCH 4/5] Update findSQLPatches.php --- maintenance/findSQLPatches.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maintenance/findSQLPatches.php b/maintenance/findSQLPatches.php index 46128b9d1..cc20c0ef1 100644 --- a/maintenance/findSQLPatches.php +++ b/maintenance/findSQLPatches.php @@ -28,7 +28,7 @@ * @version 1.0 */ -require_once '/srv/mediawiki/1.40/maintenance/Maintenance.php'; +require_once __DIR__ . '/../../../maintenance/Maintenance.php'; class FindSQLPatches extends Maintenance { public function __construct() { From 70995a78c9516f888c47259c6c1ad74c67f6fdc4 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Sep 2023 13:56:12 +0000 Subject: [PATCH 5/5] CI: lint code to MediaWiki standards Check commit and GitHub actions for more details --- maintenance/findPossibleUpgradeScripts.php | 162 ++++++++++----------- 1 file changed, 80 insertions(+), 82 deletions(-) diff --git a/maintenance/findPossibleUpgradeScripts.php b/maintenance/findPossibleUpgradeScripts.php index 2814cca24..ba2c2e100 100644 --- a/maintenance/findPossibleUpgradeScripts.php +++ b/maintenance/findPossibleUpgradeScripts.php @@ -31,89 +31,87 @@ require_once __DIR__ . '/../../../maintenance/Maintenance.php'; class FindPossibleUpgradeScripts extends Maintenance { - public function __construct() { - parent::__construct(); - - $this->addDescription( 'List new or updated maintenance scripts between two MediaWiki versions.' ); - - $this->addOption( 'from-version-path', 'Path to MediaWiki version to start from', true, true ); - $this->addOption( 'to-version-path', 'Path to MediaWiki version to end with', true, true ); - } - - public function execute() { - $fromVersionPath = $this->getOption( 'from-version-path' ); - $toVersionPath = $this->getOption( 'to-version-path' ); - $scripts = []; - $this->findScripts( $fromVersionPath, $toVersionPath, $scripts ); - foreach ( $scripts as $script ) { - $this->output( $script . $this->findExtendedClass( $script ) . "\n" ); - } - - $this->output( "\nCount: " . count( $scripts ) . "\n" ); - } - - private function findScripts( $fromVersion, $toVersion, &$scripts ) { - $fromScripts = $this->findMaintenanceScripts( $fromVersionPath ); - $toScripts = $this->findMaintenanceScripts( $toVersionPath ); - foreach ( $toScripts as $script ) { - $filename = basename( $script ); - if ( array_key_exists( $filename, $fromScripts ) ) { - if ( $this->isScriptUpdated( $fromScripts[$filename], $script ) ) { - $scripts[] = $script; - } - } else { - $scripts[] = $script; - } - } - } - - private function findMaintenanceScripts( $path ) { - $scripts = []; - - $files1 = $this->findFilesRecursively( $path . '/**/**/maintenance/*.php' ); - $files2 = $this->findFilesRecursively( $path . '/**/**/**/maintenance/*.php' ); - $coreFiles = $this->findFilesRecursively( $path . '/maintenance/*.php' ); - - foreach ( array_merge( $files1, $files2, $coreFiles ) as $file ) { - if ( str_contains( $file, '/tests/' ) ) { - continue; - } - - $scripts[basename( $file )] = $file; - } - - - return $scripts; - } - - private function isScriptUpdated( $oldScript, $newScript ) { - // TO-DO - } - - private function findFilesRecursively( $pattern ) { - $files = glob( $pattern ); - foreach ( glob( dirname( $pattern ) . '/*', GLOB_ONLYDIR | GLOB_NOSORT ) as $dir ) { - $files = array_merge( - [], - ...[ $files, $this->findFilesRecursively( $dir . '/' . basename( $pattern ) ) ] - ); - } - - return $files; - } - - private function findExtendedClass( $script ) { - $file = file_get_contents( $script ); - if ( preg_match( '/extends\s+([^\s]+)\s+/', $file, $matches ) ) { - if ( $matches[1] !== Maintenance::class ) { - return ' (' . $matches[1] . ')'; - } - } - - return ''; - } + public function __construct() { + parent::__construct(); + + $this->addDescription( 'List new or updated maintenance scripts between two MediaWiki versions.' ); + + $this->addOption( 'from-version-path', 'Path to MediaWiki version to start from', true, true ); + $this->addOption( 'to-version-path', 'Path to MediaWiki version to end with', true, true ); + } + + public function execute() { + $fromVersionPath = $this->getOption( 'from-version-path' ); + $toVersionPath = $this->getOption( 'to-version-path' ); + $scripts = []; + $this->findScripts( $fromVersionPath, $toVersionPath, $scripts ); + foreach ( $scripts as $script ) { + $this->output( $script . $this->findExtendedClass( $script ) . "\n" ); + } + + $this->output( "\nCount: " . count( $scripts ) . "\n" ); + } + + private function findScripts( $fromVersion, $toVersion, &$scripts ) { + $fromScripts = $this->findMaintenanceScripts( $fromVersionPath ); + $toScripts = $this->findMaintenanceScripts( $toVersionPath ); + foreach ( $toScripts as $script ) { + $filename = basename( $script ); + if ( array_key_exists( $filename, $fromScripts ) ) { + if ( $this->isScriptUpdated( $fromScripts[$filename], $script ) ) { + $scripts[] = $script; + } + } else { + $scripts[] = $script; + } + } + } + + private function findMaintenanceScripts( $path ) { + $scripts = []; + + $files1 = $this->findFilesRecursively( $path . '/**/**/maintenance/*.php' ); + $files2 = $this->findFilesRecursively( $path . '/**/**/**/maintenance/*.php' ); + $coreFiles = $this->findFilesRecursively( $path . '/maintenance/*.php' ); + + foreach ( array_merge( $files1, $files2, $coreFiles ) as $file ) { + if ( str_contains( $file, '/tests/' ) ) { + continue; + } + + $scripts[basename( $file )] = $file; + } + + return $scripts; + } + + private function isScriptUpdated( $oldScript, $newScript ) { + // TO-DO + } + + private function findFilesRecursively( $pattern ) { + $files = glob( $pattern ); + foreach ( glob( dirname( $pattern ) . '/*', GLOB_ONLYDIR | GLOB_NOSORT ) as $dir ) { + $files = array_merge( + [], + ...[ $files, $this->findFilesRecursively( $dir . '/' . basename( $pattern ) ) ] + ); + } + + return $files; + } + + private function findExtendedClass( $script ) { + $file = file_get_contents( $script ); + if ( preg_match( '/extends\s+([^\s]+)\s+/', $file, $matches ) ) { + if ( $matches[1] !== Maintenance::class ) { + return ' (' . $matches[1] . ')'; + } + } + + return ''; + } } - $maintClass = FindPossibleUpgradeScripts::class; require_once RUN_MAINTENANCE_IF_MAIN;