Commit graph

27 commits

Author SHA1 Message Date
Umherirrender
9efd9ca45e Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool

* php internal functions like floor/round/ceil documented to return
  float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
2022-03-01 18:19:33 +01:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
James D. Forrester
20fd877da4 Drop experimental FileJournal system without deprecation
The feature was introduced in 2012 with d19f54602f (just before
the gerrit migration).

Change-Id: Ia3f59ad0ddeb1f610947b14e22b0694ff4c6ed84
2021-11-01 14:08:09 +11:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Umherirrender
e4d1a2c8bd Use __CLASS__/::class to define callback for array_map/_filter/usort
Change-Id: I3519dd5a1ce1ea688de602190cd74755c400c717
2021-01-22 16:39:29 +00:00
jenkins-bot
8056eb74e9 Merge "filebackend: inject the proxy backend logger into FileBackendMultiWrite sub-backends" 2021-01-19 02:00:48 +00:00
jenkins-bot
fbb516d8e3 Merge "filebackend: fix bogus replication error log entries in FileBackendMultiWrite" 2021-01-19 01:59:27 +00:00
Aaron Schulz
69f8dec28e filebackend: inject the proxy backend logger into FileBackendMultiWrite sub-backends
Bug: T270994
Change-Id: Ide2cbe10dd0b19c79eb1337338eb141e414532b8
2021-01-19 01:32:18 +00:00
Aaron Schulz
fb4175df83 filebackend: fix bogus replication error log entries in FileBackendMultiWrite
This messages should be DEBUG level instead of ERROR level.
Also use __METHOD__ for consistency with other log messages.

Bug: T270994
Change-Id: I1449f618747d48bd1205adfc968cc6a92ecf1ac7
2021-01-04 16:09:01 -08:00
Aaron Schulz
c4766ef222 filebackend: add more logging to SwiftFileBackend for "conservative" sync mode
Bug: T270994
Change-Id: I0597adb3d6ade1a867f6fa469ed6959c72b8b403
2021-01-04 23:52:29 +00:00
Reedy
40e522747c Fix some includes/libs PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I92e2cbf39d2851d215e8be456e86bb99524dea5f
2020-05-16 02:32:53 +01:00
Aaron Schulz
45f0cdbcbb filebackend: make sure $scopeLock reference is valid in FileBackendMultiWrite
Change-Id: I404a4dd2a6df4d416d0e053b29693221aac62f8b
2020-02-07 21:34:42 -08:00
Aryeh Gregor
c250d07bac Unit tests for FileBackend
Currently 62.79% coverage, 108/172 lines.

One oddity discovered during testing was that the "quick" variants of
most methods don't have an $opts parameter. It seems like just an
oversight, so I added it.

Bug: T234227
Change-Id: If2978065392cd6dcf693a588bb1ce6b5d43828f2
2019-10-30 09:35:13 +02:00
Aaron Schulz
752ad738e9 filebackend: reduce unnecessary stat calls in FileBackend some cases
* Only call FileBackend::clearCache() only specific file paths.
  Make FSFileBackend respect specific path lists in doClearCache().
* Detect FSFileBackendList errors during initialization rather than
  doing additional stat calls beforehand.
* Simplify FSFileBackend::doPrepareInternal() by removing is_readable()
  check as well as is_writable() when mkdir() was just successfully run.
* Simplify FSFileBackend::isPathUsableInternal() to just look at the
  parent directory (more likely to exist and be cacheable). Since files
  are renamed into place, there isn't much need to sanity check the
  target file path itself.
* Add a process cache for "usable directories" to FSFileBackend.
* Use is_dir() in TempFSFile to avoid triggering access() syscalls
  each time.

Change-Id: Ib2c76f4c4117b9beffd89370498aa57b5972f167
2019-10-22 02:29:26 +00:00
Daimona Eaytoy
114ee6e412 Fix new phan errors, part 6
Bug: T231636
Change-Id: I1870b6cbeb31e54fde5e675fec51446b330e06c5
2019-10-20 17:53:48 +00:00
Aaron Schulz
903f1810c8 filebackend: improve internal use of FileBackend constants
Add more result constants and split up FileBackend::UNKNOWN for
clarity. This follows up 5719815f3b, which added that constant.

Make internal FileBackendStore::doGet* methods distinguish I/O errors
from missing files; the return types of public FileBackend methods are
unchanged. Avoid process caching any mtime/size/sha1 values in the
case of I/O errors. Use error constants consistently for stat methods
when given invalid paths.

Also:
* Factor out FileBackendStore::processCacheAndPersistStatEntries() method
  to reduce significant code duplication.
* Consolidate duplicated isPathUsable() checks in FileOp subclasses to
  FileOp::precheck().
* Remove null process cache value check from FileBackend::getFileStat()
  as null values are never stored in the process cache to begin with.
* Reformat some oddly wrapped lines to look cleaner.

Change-Id: Id0e4b0da0bb2ed3184847b35142d587c7f3d953d
2019-09-03 19:31:17 -07:00
Aaron Schulz
4ff2d43a80 filebackend: improve FileBackendMultiWrite consistencyCheck()/resyncFiles()
Report file stat errors and sha1/stat mismatches in consistencyCheck().
This will trigger resyncFiles() which will make second attempt to check
the consistency while also fixing any problems if possible. Make sure
that it also bails out if such errors occur again.

Improve consistencyCheck()/resyncFiles() variable naming and add more
comments to FileBackend::UNKNOWN.

Also replace wfDebugLog() calls with PSR logger calls and wfTimestamp()
calls with ConvertibleTimestamp::convert() calls.

Bug: T231086
Change-Id: I69bcee636c6d99970e9a6448bb8296c0790c7254
2019-08-30 18:40:27 +00:00
Aaron Schulz
95e68098ca filebackend: update code comments and break some long lines
Change-Id: I072e15c7c51490888284561260958e405fb061ca
2019-08-24 03:32:12 -07:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Kunal Mehta
e7186d68bd Upgrade to newer phan
MediaWiki core now runs phan 1.2.6, bringing in nearly 2+ years of upstream
fixes.

Configuration was moved from `tests/phan` to `.phan/`. The legacy bash wrapper
script is still kept in the repository in its own location for any extensions
that are still using it. It should be removed before 1.33 is released.

Since there's a lot of new issues being flagged, all currently failing issues
are suppressed, and will be fixed in follow-up patches.

We're dropping the jetbrains/phpstorm-stubs repository in favor of just
the minimal stubs we need. Stubs for PHP extensions are kept in
the new `.phan/internal_stubs` directory, since they're in a slightly
different format than normal stubs.

Normal stubs are kept in `.phan/stubs`. wikidiff2 and excimer are kept with
these since we're also the upstream for them.

Change-Id: I3fe437befa17f4fbaf97aa6271f659b56021f396
2019-03-23 18:06:35 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Max Semenik
55497cdc1a Phan: resolve and reenable PhanAccessMethodProtected
Change-Id: I2bd7c787012f4f54600f3289d9d0d725f87788bc
2018-01-23 09:31:13 -08:00
Aaron Schulz
82e2c924e4 Remove "@author Aaron Schulz" annotations
Bug: T139301
Change-Id: Ib5248e8e27d60611c7373bce4b29dd5e85aa3489
2017-06-27 15:24:14 -07:00
Umherirrender
be42e09aa8 build: Prepare for mediawiki/mediawiki-codesniffer to 0.9.0
The used phpcs has a bug, so the version 0.9.0 could not be enforced at the moment.
Will be fixed in next version, see T167168

Changed:
- Remove duplicate newline at end of file
- Add space between function and ( for closures
- and -> &&, or -> ||

Change-Id: I4172fb08861729bccd55aecbd07e029e2638d311
2017-06-26 17:14:31 +00:00
Timo Tijhof
50a035cd6b Clean up get_class($this) -> static::class in /includes/cache and /includes/libs
* get_class()        -> __CLASS__ (same as self::class)
* get_called_class() -> static::class
* get_class($this)   -> static::class

Change-Id: I22c62851bcc88405f4bdd77258d6e28ec1a14924
2017-03-07 21:06:06 +00:00
Aaron Schulz
99339b4598 Make multi-write backend "template" config work as expected
* FileBackendGroup now applies the usual config for these sub-backends,
  the same config get() applies.
* Also make sure FileBackendMultiWrite::concatenate() uses the status wrapper.

Bug: T146904
Change-Id: I1e9b5027dbac11ea9484cd16851e5db998574429
2016-09-29 13:20:06 -07:00
Aaron Schulz
616fabe05a Move FileBackendMultiWrite to /libs
Change-Id: I8079693a62db390028cd9f72b2bd7a81ae1164c3
2016-09-23 20:19:11 +00:00
Renamed from includes/filebackend/FileBackendMultiWrite.php (Browse further)