Store: Enable ConfirmEdit to use MicroStash for captcha storage

ConfirmEdit uses MainStash as the backend to write its captchas. We
are migrating this extension to use the MicroStash store instead which
is more suitable.

This patch will store the captcha in MicroStash, read it from there
or fallback to MainStash if lookup was not successful. The code will
then clear both stores once after processing.

Migration plan
==============

step .1: Write to microstash store only, read from it or
         fallback to mainstash store. Then delete from
         both backends.

step .2: Read from microstash store only, delete from the
         microstash store, and remove dead code afterward.

Bug: T336004
Change-Id: Ie7c50a6efe7a0aefc97a712b2ad961e7837cc4cf
This commit is contained in:
Derick Alangi 2023-11-20 18:34:02 +01:00
parent 2e24b873a8
commit bb201b86e4
No known key found for this signature in database
GPG key ID: 01D205B3F82BADDA

View file

@ -7,12 +7,17 @@ use MediaWiki\MediaWikiServices;
class CaptchaCacheStore extends CaptchaStore {
/** @var BagOStuff */
private $store;
private $mainStashStore;
/** @var BagOStuff */
private $microStashStore;
public function __construct() {
parent::__construct();
$this->store = MediaWikiServices::getInstance()->getMainObjectStash();
$services = MediaWikiServices::getInstance();
$this->mainStashStore = $services->getMainObjectStash();
$this->microStashStore = $services->getMicroStash();
}
/**
@ -21,14 +26,14 @@ class CaptchaCacheStore extends CaptchaStore {
public function store( $index, $info ) {
global $wgCaptchaSessionExpiration;
$store = $this->store;
$store->set(
$store->makeKey( 'captcha', $index ),
$microStashStore = $this->microStashStore;
$microStashStore->set(
$microStashStore->makeKey( 'captcha', $index ),
$info,
$wgCaptchaSessionExpiration,
// Assume the write will reach the master DC before the user sends the
// HTTP POST request attempted to solve the captcha and perform an action
$store::WRITE_BACKGROUND
$microStashStore::WRITE_BACKGROUND
);
}
@ -36,16 +41,26 @@ class CaptchaCacheStore extends CaptchaStore {
* @inheritDoc
*/
public function retrieve( $index ) {
$store = $this->store;
return $store->get( $store->makeKey( 'captcha', $index ) ) ?: false;
$microStashStore = $this->microStashStore;
$data = $microStashStore->get( $microStashStore->makeKey( 'captcha', $index ) );
if ( !$data ) {
$mainStashStore = $this->mainStashStore;
$data = $mainStashStore->get( $mainStashStore->makeKey( 'captcha', $index ) );
}
return $data;
}
/**
* @inheritDoc
*/
public function clear( $index ) {
$store = $this->store;
$store->delete( $store->makeKey( 'captcha', $index ) );
$mainStashStore = $this->mainStashStore;
$mainStashStore->delete( $mainStashStore->makeKey( 'captcha', $index ) );
$microStashStore = $this->microStashStore;
$microStashStore->delete( $microStashStore->makeKey( 'captcha', $index ) );
}
public function cookiesNeeded() {