Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4114742
TestHandler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
TestHandler.php
View Options
<?php
namespace
MediaWiki\Extension\OATHAuth\Hook
;
use
MediaWiki\Hook\UnitTestsAfterDatabaseSetupHook
;
use
MediaWiki\Hook\UnitTestsBeforeDatabaseTeardownHook
;
use
Wikimedia\Rdbms\ILoadBalancer
;
class
TestHandler
implements
UnitTestsAfterDatabaseSetupHook
,
UnitTestsBeforeDatabaseTeardownHook
{
public
function
__construct
(
private
readonly
ILoadBalancer
$loadBalancer
,
)
{
}
/**
* If OATHAuth uses a different DB from the wiki default, create the tables in that DB.
* Largely follows UnitTestsHookHandler in CentralAuth.
* @inheritDoc
*/
public
function
onUnitTestsAfterDatabaseSetup
(
$db
,
$prefix
)
{
$originalPrefix
=
$db
->
tablePrefix
();
$db
->
tablePrefix
(
$prefix
);
if
(
!
$db
->
tableExists
(
'oathauth_types'
,
__METHOD__
)
)
{
$engine
=
$db
->
getType
();
$db
->
sourceFile
(
__DIR__
.
"/../../sql/$engine/tables-generated.sql"
);
}
$db
->
tablePrefix
(
$originalPrefix
);
}
public
function
onUnitTestsBeforeDatabaseTeardown
()
{
$schema
=
json_decode
(
file_get_contents
(
__DIR__
.
'/../../sql/tables.json'
),
true
);
$tables
=
array_map
(
static
fn
(
$tableSchema
)
=>
$tableSchema
[
'name'
],
$schema
);
$dbw
=
$this
->
loadBalancer
->
getMaintenanceConnectionRef
(
DB_PRIMARY
);
foreach
(
$tables
as
$table
)
{
$dbw
->
dropTable
(
$table
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 00:24 (5 d, 11 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e5/43/d98ac5a4f3723698dc73bbe62b10
Default Alt Text
TestHandler.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment