Commit graph

36 commits

Author SHA1 Message Date
Dreamy Jazz
e7393b3cc7 Exclude boilerplate maintenance code from code coverage reports
Why:
* Maintenance scripts in core have bolierplate code that is
  added before and after the class to allow directly running
  the maintenance script.
* Running the maintenance script directly has been deprecated
  since 1.40, so this boilerplate code is only to support a now
  deprecated method of running maintenance scripts.
* This code cannot also be marked as covered, due to PHPUnit
  not recognising code coverage for files.
* Therefore, it is best to ignore this boilerplate code in code
  coverage reports as it cannot be marked as covered and also
  is for deprecated code.

What:
* Wrap the boilerplate code (requiring Maintenance.php and then
  later defining the maintenance script class and running if the
  maintenance script was called directly) with @codeCoverageIgnore
  comments.
* Some files use a different boilerplate code, however, these
  should also be marked as ignored for coverage for the same
  reason that coverage is not properly reported for files.

Bug: T371167
Change-Id: I32f5c6362dfb354149a48ce9c28da9a7fc494f7c
2024-08-27 13:22:29 +01:00
Umherirrender
9879723ef3 Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ic4d4dd61de5ab896fb6173eb579c81f164a1e4a3
2024-06-16 20:18:23 +02:00
Tim Starling
cdc5178150 user: Introduce UserOptionsStore
Refactoring:

* Break out the database access part of UserOptionsManager to a separate
  class hierarchy implementing interface UserOptionsStore. It's
  basically a key/key/string-value store, very simple. The complex
  parts of user options storage remain in UserOptionsManager.
* Bundle the UserOptionsManager caches into a per-user cache object. I
  was adding a couple more and it was getting tedious.

Start integrating GlobalPreferences with UserOptionsManager:

* Have an array of stores. There's always a local store, and extensions
  can add stores via an attribute.
* Add $global parameter to UserOptionsManager::setOption(), allowing
  this method to update or override global options.
* Rename loadOptionsFromDb to loadOptionsFromStore.
* Move the local override feature from GlobalPreferences to core.

Bug: T323076
Change-Id: Ib3623b723557c819bc0ffdf21a4ffcb070eb298b
2024-06-12 01:27:57 +00:00
Umherirrender
9bf5d724af maintenance: Use expression builder in cleanupPreferences.php
Also type-hint for IReadableDatabase

Depends-On: I15fc617eae8bc18c911525ea382e99e82b40011a
Depends-On: Ib77f8f409b48115684396bf920428adb075c2820
Change-Id: I09d07ba11e8cd6d288c1ed5ddea89b654e24cbb2
2024-04-21 20:52:43 +02:00
Amir Sarabadani
d9370003fb maintenance: Introduce getReplicaDB() and getPrimaryDB()
And start using them instead of wfGetDB(), LB/LBF connection methods or
worse, $this->getDB().

$this->getDB() reuses the database object regardless of whether you're
calling a replica or primary, leading to returning a replica on a
primary and other way around.

Bug: T330641
Change-Id: I9e2cf85ca277022284fc26b9f37db57bd12aaa81
2024-01-18 15:12:04 +01:00
Martin Urbanec
6c8b696020 Add support for conditional user defaults
Why:
Sometimes, it is necessary to have different behavior
for newly registered and existing users. For example,
this happens in the Echo or GrowthExperiments extensions.
As of now, this behavior is implemented by inserting
user_properties rows in onLocalUserCreated.

Over time, this results in a singificant amount of rows
inserted, which contributes to the user_properties table bloat,
which is already overly large (cf. T54777). This patch makes it
possible to remove such rows by supporting conditional defaults
for user properties.

What:
Add support for conditional defaults of user properties. This can be
configured via `ConditionalUserOptions` config option.

Bug: T321527
Change-Id: I1549c3137e66801c85e03e46427e27da333d68e2
2024-01-09 02:33:17 +00:00
Amir Sarabadani
5a3e6564e4 maintenance: Migrate to DeleteQueryBuilder
Bug: T353219
Change-Id: Iecb55ab3f905ee9ed4e32e9cbb58c36f8cacf669
2024-01-02 13:13:49 +01:00
Derick Alangi
74033c50cd maintenance: Begin using Maintenance::getServiceContainer()
Maintenance class provides a method for getting a fresh reference
of the MW services container instance. Let's make use of these in
maintenance scripts now that we have it.

NOTE: There are still some static methods like in refreshLinks.php
that makes use of services that we can't use this method for now.

Change-Id: Idba744057577896fc97c9ecf4724db27542bf01c
2023-09-04 10:39:58 +00:00
Amir Sarabadani
b525884e11 maintenance: Use $this->waitForReplication()
This adds reconfiguring db pools in case a replica gets depooled

Bug: T298485
Change-Id: Id052ce8ed45c51e51b071778858d27b48605bf93
2022-10-24 21:11:53 +02:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
Umherirrender
5390910ae4 Improve CleanupPreferences::deleteByWhere
- Use BatchRowIterator for the selects. The old code loops with
--dry-run, because the old code depends on the delete to select the next
batch. With the iterator a pagenation is done.
- Use a read and a write connection
- One delete per batch
- Get the default options from the service to include options from
extensions set by the UserGetDefaultOptions hook

Change-Id: I463c18c927c76ac2c234f3731a9ddbc9bec9d4f9
2022-02-21 09:19:45 +11:00
Umherirrender
ceceb2242f Remove unimplemented "bogus" parts of CleanupPreferences
Change-Id: I50b5a1bfde6f132b449eda9576ba163f1301ca13
2021-09-29 18:47:01 +02:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
Umherirrender
8f666cabcd Use Maintenance::getConfig in some maintenance scripts
This avoid global state

Change-Id: Id67d07597159a0bd2721a381775230c3cd1d5509
2019-09-01 20:55:08 +02:00
Derick Alangi
a5e2854b82 maintenance: Use addDescription() instead of accessing mDescription directly
Change-Id: I705a3fab4a6b151b81b45a3e2d7559f554986378
2019-06-11 19:02:26 +00:00
Thiemo Kreuz
b0615e1249 Remove empty and unnecessary /* @{{ … */ comments
This was the only comment I could find that uses two curly brackets
for some reason. There are a few more with one curly bracket.

Change-Id: Iaed631916064e6be4895edd4c7a3d7de491e16c2
2019-03-15 14:59:19 +01:00
Thiemo Kreuz
b7cd670cb7 maintenance: Remove unused code from several maintenance scripts
The most notable removal is done in the orphans script. This code was
really never used. Brion introduced it in 2005, already disabled.

I have all the respect for what Brion did. I just think it does not make
much sense to keep code around for so long if it does not work anyway,
and must be rewritten from scratch anyway now that we have multi-content
revisions and such.

Change-Id: I4e8050929f90e44a6e6051bf938993a8b0cdf649
2019-03-03 16:57:19 +00:00
Thiemo Kreuz
4b71077646 Remove a few obscure "done" and "empty" comments
These don't add any knowledge to what is already obvious from the
code, I find.

Change-Id: Ia613b6a059f78dbeefdfd020899bd1a6e239a731
2019-01-30 20:35:14 +00:00
Sam Wilson
6717ea5c7d Remove gadget special-case from preferences cleanup
Avoiding deletion of 'gadget-' preferences is now done in
the Gadgets extension via the hook.

Bug: T188966
Change-Id: I81a070986b6e76a2fcec52617b59e9528e52eba2
Depends-On: I5627f014827fdbf266eb7fdb00a446f81a0c3458
2018-04-06 09:44:50 +08:00
Sam Wilson
6c9a0a2a68 Add DeleteUnknownPreferences hook
This makes it possible for extensions to add to the WHERE clause
with which unknown preferences are deleted.

Bug: T188966
Change-Id: Ifb22ca42207956f2b07333da026ff0b215a83930
2018-04-03 06:56:18 +00:00
jenkins-bot
7babd362ba Merge "Rewrite pref cleanup script" 2018-01-31 18:47:59 +00:00
Chad Horohoe
326f555907 Rewrite pref cleanup script
- Keep the current hidden pref cleanup stuff, that's not harmful
  and marginally useful
- Drop preferences we dunno wtf they're about. Cuz they're probably
  deprecated or otherwise unused
- Normalize preferences into accepted value ranges. This part is kinda
  hard and I haven't figured it out, so slap a TODO

More to come, stay tuned!

Change-Id: I70047adba0034136d107ce7534294cc6fa3c1860
2018-01-30 20:12:20 +00:00
Umherirrender
ad776c7d5f Use ::class to resolve class names in maintenance scripts
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I1d4567f47f93eb1436cb98558388e48d35258666
2018-01-23 17:40:16 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Aaron Schulz
fa8e1a9b00 Clean up transactions in maintenance scripts
Add transaction methods to complement getDB().
This makes it easy to grep for direct begin()/commit()
calls to IDatabase by having script use their own
wrapper. Maintenance scripts are one of the few places
that can (and need to) use begin/commit instead of the
start/end atomic methods.

Eventually, there should be almost no direct callers
and those methods can be made stricter about throwing
errors on nested calls.

Change-Id: Ibbfc7a77c0d2a55f7fc2261087f6c3a19061e0aa
2015-12-30 23:40:35 +00:00
umherirrender
271da88127 Some bugzilla.wikimedia.org -> phabricator.wikimedia.org changes
Changed some old bugzilla links to new phabricator links in comments,
test data and error message. This reduces the need for redirects from
old bugzilla to new phabricator from our source code.

Change-Id: Id98278e26ce31656295a23f3cadb536859c4caa5
2015-09-24 17:17:25 +02:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Timo Tijhof
50e7985d4d phpcs: Fix WhiteSpace.LanguageConstructSpacing warnings
Squiz.WhiteSpace.LanguageConstructSpacing:
   Language constructs must be followed by a single space;
   expected "require_once expression" but found
   "require_once(expression)"

It is a keyword (e.g. like `new`, `return` and `print`). As
such the parentheses don't make sense.

Per our code conventions, we use a space after keywords like
these. We appeared to have an unwritten exception for `require`
that doesn't make sense. About 60% of require/include usage
was missing the space and/or had superfluous parentheses.

It is as silly as print("foo") or return("foo"), it works
because keywords have no significance for whitespace between
it and the expression that follows, and since experessions can
be wrapped in parentheses for clarity (e.g. when doing string
concatenation or mathematical operations) the parenthesis
before and after basiclaly just ignored.

Change-Id: I2df2f80b8123714bea7e0771bf94b51ad5bb4b87
2013-05-09 05:56:26 +02:00
umherirrender
b114f5e1c1 Fixed some spacing in maintenance folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9657f72996358f8c1c154cea1ea97970d973723c
2013-04-18 20:48:44 +02:00
umherirrender
7cc01d56b2 Add some __METHOD__ to begin/commit/rollback calls
Change-Id: I20dad8d6bb7a523e8a6f50bc0af5cdba57d7160f
2012-12-01 15:04:10 +01:00
MarkAHershberger
cca318981d Bug 42039 - Fix some file-related issues in the distribution
Minor issues.

Tested the removal of
maintenance/postgres/archives/patch-ipb_address_unique.sql in a new
installation but haven't tested it on an upgrade.

Change-Id: I58aa11c5acab5de427cbc000e6786a208fc6b26f
2012-11-12 09:37:28 -05:00
jeroendedauw
38c7f444e1 Use __DIR__ instead of dirname( __FILE__ )
We can now do this since we finally switched to PHP 5.3 for MW 1.20 and get rid of the silly dirname(__FILE__) stuff :)

Change-Id: Id9b2c9cd2e678197aa81c78adced5d1d31ff57b1
2012-08-27 21:45:00 +02:00
Alexandre Emsenhuber
a28e00cb4b Improve documentation of maintenance scripts.
Change-Id: I2433d23544e808e16f28805f93183b1af2409c94
2012-07-08 22:50:22 +02:00
Reedy
23477c7ef6 Remove BOM from cleanupPreferences
Change-Id: I3c049c0229bb9ed1365f2781baa44b4c8e1e1e18
2012-07-07 16:19:58 +01:00
TyA
67aa00f957 *(bug 30976) Add maintenance script to remove preferences from $wgHiddenPrefs
Change-Id: Ie74fab1edeac2c6b275c51e6af3a7924b3aac46b
2012-07-04 23:08:41 +01:00