2020-05-08 06:29:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
|
|
|
|
use MediaWiki\Block\DatabaseBlockStore;
|
|
|
|
|
use MediaWiki\Block\Restriction\NamespaceRestriction;
|
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
2024-07-09 15:36:08 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2021-05-26 03:35:05 +00:00
|
|
|
use MediaWiki\Tests\Unit\DummyServicesTrait;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2020-05-08 06:29:23 +00:00
|
|
|
use Psr\Log\NullLogger;
|
2023-10-31 07:33:37 +00:00
|
|
|
use Wikimedia\IPUtils;
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Integration tests for DatabaseBlockStore.
|
|
|
|
|
*
|
|
|
|
|
* @author DannyS712
|
|
|
|
|
* @group Blocking
|
|
|
|
|
* @group Database
|
|
|
|
|
* @covers \MediaWiki\Block\DatabaseBlockStore
|
2023-10-31 07:33:37 +00:00
|
|
|
* @coversDefaultClass \MediaWiki\Block\DatabaseBlockStore
|
2020-05-08 06:29:23 +00:00
|
|
|
*/
|
|
|
|
|
class DatabaseBlockStoreTest extends MediaWikiIntegrationTestCase {
|
2021-05-26 03:35:05 +00:00
|
|
|
use DummyServicesTrait;
|
|
|
|
|
|
2024-07-30 21:52:32 +00:00
|
|
|
private User $sysop;
|
|
|
|
|
private int $expiredBlockId = 11111;
|
|
|
|
|
private int $unexpiredBlockId = 22222;
|
|
|
|
|
private int $autoblockId = 33333;
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $options
|
|
|
|
|
* - config: Override the ServiceOptions config
|
|
|
|
|
* - constructorArgs: Override the constructor arguments
|
|
|
|
|
* @return DatabaseBlockStore
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
private function getStore( array $options = [] ): DatabaseBlockStore {
|
2020-05-08 06:29:23 +00:00
|
|
|
$overrideConfig = $options['config'] ?? [];
|
|
|
|
|
$overrideConstructorArgs = $options['constructorArgs'] ?? [];
|
|
|
|
|
|
|
|
|
|
$defaultConfig = [
|
2024-07-09 15:36:08 +00:00
|
|
|
MainConfigNames::AutoblockExpiry => 86400,
|
|
|
|
|
MainConfigNames::BlockCIDRLimit => [ 'IPv4' => 16, 'IPv6' => 19 ],
|
|
|
|
|
MainConfigNames::BlockDisablesLogin => false,
|
|
|
|
|
MainConfigNames::PutIPinRC => true,
|
|
|
|
|
MainConfigNames::UpdateRowsPerQuery => 10,
|
2020-05-08 06:29:23 +00:00
|
|
|
];
|
|
|
|
|
$config = array_merge( $defaultConfig, $overrideConfig );
|
|
|
|
|
|
|
|
|
|
// This ensures continuation after hooks
|
|
|
|
|
$hookContainer = $this->createMock( HookContainer::class );
|
|
|
|
|
$hookContainer->method( 'run' )
|
|
|
|
|
->willReturn( true );
|
|
|
|
|
|
|
|
|
|
// Most tests need read only to be false
|
2021-05-26 03:35:05 +00:00
|
|
|
$readOnlyMode = $this->getDummyReadOnlyMode( false );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
2021-09-05 21:12:06 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2020-05-08 06:29:23 +00:00
|
|
|
$defaultConstructorArgs = [
|
|
|
|
|
'serviceOptions' => new ServiceOptions(
|
|
|
|
|
DatabaseBlockStore::CONSTRUCTOR_OPTIONS,
|
|
|
|
|
$config
|
|
|
|
|
),
|
|
|
|
|
'logger' => new NullLogger(),
|
2021-05-05 21:34:14 +00:00
|
|
|
'actorStoreFactory' => $services->getActorStoreFactory(),
|
2020-05-08 06:29:23 +00:00
|
|
|
'blockRestrictionStore' => $services->getBlockRestrictionStore(),
|
|
|
|
|
'commentStore' => $services->getCommentStore(),
|
|
|
|
|
'hookContainer' => $hookContainer,
|
2024-03-13 23:09:30 +00:00
|
|
|
'dbProvider' => $services->getDBLoadBalancerFactory(),
|
2020-05-08 06:29:23 +00:00
|
|
|
'readOnlyMode' => $readOnlyMode,
|
2021-06-03 10:25:17 +00:00
|
|
|
'userFactory' => $services->getUserFactory(),
|
Move DatabaseBlock read query methods to DatabaseBlockStore
* Move to DatabaseBlockStore the DatabaseBlock methods newFromID,
getQueryInfo, getRangeCond, newFromRow, isExemptedFromAutoblocks,
doAutoblock, updateTimestamp, getAutoblockExpiry, newFromTarget,
newListFromTarget.
* Split DatabaseBlock::getBlocksForIPList. Now
BlockManager::getBlocksForIPList() is responsible for XFF header
validation and trusted proxy handling. DatabaseBlockStore::
newListFromIPs() just does the queries and constructs the Block
objects.
* In DatabaseBlockStore::newFromRow() and doAutoblock(), use the
DatabaseBlock constructor instead of calling many setter methods. Add
constructor options decodedExpiry, decodedTimestamp, id,
parentBlockId and restrictions to support this.
* Move isExemptedFromAutoblocks() to its own service. Remove the cache
since in my testing with production eval.php, the WAN cache fetch is
10 times slower than just using the message cache, contradicting the
comment written in 2008.
* Fix AuthManagerTest which was previously passing an unrecognised
"restrictions" option to DatabaseBlock. Now that the option actually
works, we have to use the right type.
Bug: T255433
Change-Id: I5049e60be1681f67fcca133e569e315792dc42dd
2023-10-31 05:58:23 +00:00
|
|
|
'tempUserConfig' => $services->getTempUserConfig(),
|
|
|
|
|
'blockUtils' => $services->getBlockUtils(),
|
|
|
|
|
'autoblockExemptionList' => $services->getAutoblockExemptionList(),
|
2020-05-08 06:29:23 +00:00
|
|
|
];
|
|
|
|
|
$constructorArgs = array_merge( $defaultConstructorArgs, $overrideConstructorArgs );
|
|
|
|
|
|
|
|
|
|
return new DatabaseBlockStore( ...array_values( $constructorArgs ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $options
|
|
|
|
|
* - target: The intended target, an unblocked user by default
|
|
|
|
|
* - autoblock: Whether this block is autoblocking
|
|
|
|
|
* @return DatabaseBlock
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
private function getBlock( array $options = [] ): DatabaseBlock {
|
2020-05-08 06:29:23 +00:00
|
|
|
$target = $options['target'] ?? $this->getTestUser()->getUser();
|
|
|
|
|
$autoblock = $options['autoblock'] ?? false;
|
|
|
|
|
|
|
|
|
|
return new DatabaseBlock( [
|
2021-06-02 09:44:38 +00:00
|
|
|
'by' => $this->sysop,
|
2020-05-08 06:29:23 +00:00
|
|
|
'address' => $target,
|
|
|
|
|
'enableAutoblock' => $autoblock,
|
|
|
|
|
] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check that an autoblock corresponds to a parent block. The following are not
|
|
|
|
|
* required to be equal, so are not tested:
|
|
|
|
|
* - target
|
|
|
|
|
* - type
|
|
|
|
|
* - expiry
|
|
|
|
|
* - autoblocking
|
|
|
|
|
*
|
|
|
|
|
* @param DatabaseBlock $block
|
|
|
|
|
* @param DatabaseBlock $autoblock
|
|
|
|
|
*/
|
|
|
|
|
private function assertAutoblockEqualsBlock(
|
|
|
|
|
DatabaseBlock $block,
|
|
|
|
|
DatabaseBlock $autoblock
|
|
|
|
|
) {
|
|
|
|
|
$this->assertSame( $autoblock->getParentBlockId(), $block->getId() );
|
|
|
|
|
$this->assertSame( $autoblock->isHardblock(), $block->isHardblock() );
|
|
|
|
|
$this->assertSame( $autoblock->isCreateAccountBlocked(), $block->isCreateAccountBlocked() );
|
|
|
|
|
$this->assertSame( $autoblock->getHideName(), $block->getHideName() );
|
|
|
|
|
$this->assertSame( $autoblock->isEmailBlocked(), $block->isEmailBlocked() );
|
|
|
|
|
$this->assertSame( $autoblock->isUsertalkEditAllowed(), $block->isUsertalkEditAllowed() );
|
|
|
|
|
$this->assertSame( $autoblock->isSitewide(), $block->isSitewide() );
|
2024-02-15 04:57:43 +00:00
|
|
|
$this->assertSame(
|
|
|
|
|
$autoblock->getReasonComment()->text,
|
|
|
|
|
wfMessage( 'autoblocker', $block->getTargetName(), $block->getReasonComment()->text )->text()
|
|
|
|
|
);
|
2020-05-08 06:29:23 +00:00
|
|
|
|
2021-09-05 21:12:06 +00:00
|
|
|
$restrictionStore = $this->getServiceContainer()->getBlockRestrictionStore();
|
2020-05-08 06:29:23 +00:00
|
|
|
$this->assertTrue(
|
|
|
|
|
$restrictionStore->equals(
|
|
|
|
|
$autoblock->getRestrictions(),
|
|
|
|
|
$block->getRestrictions()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 07:33:37 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ::newFromID
|
|
|
|
|
* @covers ::newListFromTarget
|
|
|
|
|
* @covers ::newFromRow
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromID_exists() {
|
|
|
|
|
$block = new DatabaseBlock( [
|
|
|
|
|
'address' => '1.2.3.4',
|
|
|
|
|
'by' => $this->getTestSysop()->getUser(),
|
|
|
|
|
] );
|
|
|
|
|
$store = $this->getStore();
|
|
|
|
|
$inserted = $store->insertBlock( $block );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
(bool)$inserted['id'],
|
|
|
|
|
'Block inserted correctly'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$blockId = $inserted['id'];
|
|
|
|
|
$newFromIdRes = $store->newFromID( $blockId );
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
DatabaseBlock::class,
|
|
|
|
|
$newFromIdRes,
|
|
|
|
|
'Looking up an existing block by id'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$newListRes = $store->newListFromTarget( "#$blockId" );
|
|
|
|
|
$this->assertCount(
|
|
|
|
|
1,
|
|
|
|
|
$newListRes,
|
|
|
|
|
'newListFromTarget with a block id for an existing block'
|
|
|
|
|
);
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
DatabaseBlock::class,
|
|
|
|
|
$newListRes[0],
|
|
|
|
|
'DatabaseBlock returned'
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$blockId,
|
|
|
|
|
$newListRes[0]->getId(),
|
|
|
|
|
'Block returned is the correct one'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ::newFromID
|
|
|
|
|
* @covers ::newListFromTarget
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromID_missing() {
|
|
|
|
|
$store = $this->getStore();
|
|
|
|
|
$missingBlockId = 9998;
|
2024-06-13 16:53:25 +00:00
|
|
|
$dbRow = $this->getDb()->newSelectQueryBuilder()
|
2024-05-02 20:22:10 +00:00
|
|
|
->select( '*' )
|
2024-04-09 02:49:33 +00:00
|
|
|
->from( 'block' )
|
|
|
|
|
->where( [ 'bl_id' => $missingBlockId ] )
|
2024-05-02 20:22:10 +00:00
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchRow();
|
2023-10-31 07:33:37 +00:00
|
|
|
$this->assertFalse(
|
|
|
|
|
$dbRow,
|
|
|
|
|
"Sanity check: make sure there is no block with id $missingBlockId"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$newFromIdRes = $store->newFromID( $missingBlockId );
|
|
|
|
|
$this->assertNull(
|
|
|
|
|
$newFromIdRes,
|
|
|
|
|
'Looking up a missing block by id'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$newListRes = $store->newListFromTarget( "#$missingBlockId" );
|
|
|
|
|
$this->assertCount(
|
|
|
|
|
0,
|
|
|
|
|
$newListRes,
|
|
|
|
|
'newListFromTarget with a block id for a missing block'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ::getQueryInfo
|
|
|
|
|
*/
|
|
|
|
|
public function testGetQueryInfo() {
|
|
|
|
|
// We don't list all of the fields that should be included, because that just
|
|
|
|
|
// duplicates the function itself. Instead, check the structure and the field
|
|
|
|
|
// aliases. The fact that this query info is everything needed to create a block
|
|
|
|
|
// is validated by its uses within the service
|
2024-04-09 03:26:02 +00:00
|
|
|
$queryInfo = $this->getStore()->getQueryInfo();
|
2023-10-31 07:33:37 +00:00
|
|
|
$this->assertArrayHasKey( 'tables', $queryInfo );
|
|
|
|
|
$this->assertArrayHasKey( 'fields', $queryInfo );
|
|
|
|
|
$this->assertArrayHasKey( 'joins', $queryInfo );
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray( $queryInfo['fields'] );
|
2024-04-09 02:49:33 +00:00
|
|
|
$this->assertArrayHasKey( 'bl_by', $queryInfo['fields'] );
|
|
|
|
|
$this->assertSame( 'block_by_actor.actor_user', $queryInfo['fields']['bl_by'] );
|
|
|
|
|
$this->assertArrayHasKey( 'bl_by_text', $queryInfo['fields'] );
|
|
|
|
|
$this->assertSame( 'block_by_actor.actor_name', $queryInfo['fields']['bl_by_text'] );
|
2023-10-31 07:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ::newListFromIPs
|
|
|
|
|
* @covers ::newFromRow
|
|
|
|
|
*/
|
|
|
|
|
public function testNewListFromIPs() {
|
|
|
|
|
$block = new DatabaseBlock( [
|
|
|
|
|
'address' => '1.2.3.4',
|
|
|
|
|
'by' => $this->getTestSysop()->getUser(),
|
|
|
|
|
] );
|
|
|
|
|
$store = $this->getStore();
|
|
|
|
|
$inserted = $store->insertBlock( $block );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
(bool)$inserted['id'],
|
|
|
|
|
'Sanity check: block inserted correctly'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Early return of empty array if no ips in the list
|
|
|
|
|
$list = $store->newListFromIPs( [], true );
|
|
|
|
|
$this->assertCount(
|
|
|
|
|
0,
|
|
|
|
|
$list,
|
|
|
|
|
'No matching blocks'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Empty array for no match
|
|
|
|
|
$list = $store->newListFromIPs(
|
|
|
|
|
[ '10.1.1.1', '192.168.1.1' ],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$this->assertCount(
|
|
|
|
|
0,
|
|
|
|
|
$list,
|
|
|
|
|
'No blocks retrieved if all ips are invalid or trusted proxies'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Actually fetching, block was inserted above
|
|
|
|
|
$list = $store->newListFromIPs( [ '1.2.3.4' ], true );
|
|
|
|
|
$this->assertCount(
|
|
|
|
|
1,
|
|
|
|
|
$list,
|
|
|
|
|
'Block retrieved for the blocked ip'
|
|
|
|
|
);
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
DatabaseBlock::class,
|
|
|
|
|
$list[0],
|
|
|
|
|
'Sanity check: DatabaseBlock returned'
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$inserted['id'],
|
|
|
|
|
$list[0]->getId(),
|
|
|
|
|
'Block returned is the correct one'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetRangeCond() {
|
|
|
|
|
// $start, $end, $expect
|
|
|
|
|
$hex1 = IPUtils::toHex( '1.2.3.4' );
|
|
|
|
|
$hex2 = IPUtils::toHex( '1.2.3.5' );
|
|
|
|
|
yield 'IPv4 start, same end' => [
|
|
|
|
|
$hex1,
|
|
|
|
|
null,
|
2024-04-09 02:49:33 +00:00
|
|
|
"((bt_ip_hex = '$hex1' AND bt_range_start IS NULL)"
|
|
|
|
|
. " OR (bt_range_start LIKE '0102%' ESCAPE '`'"
|
|
|
|
|
. " AND bt_range_start <= '$hex1'"
|
|
|
|
|
. " AND bt_range_end >= '$hex1'))"
|
2023-10-31 07:33:37 +00:00
|
|
|
];
|
|
|
|
|
yield 'IPv4 start, different end' => [
|
|
|
|
|
$hex1,
|
|
|
|
|
$hex2,
|
2024-04-09 02:49:33 +00:00
|
|
|
"(bt_range_start LIKE '0102%' ESCAPE '`'"
|
|
|
|
|
. " AND bt_range_start <= '$hex1'"
|
|
|
|
|
. " AND bt_range_end >= '$hex2')"
|
2023-10-31 07:33:37 +00:00
|
|
|
];
|
|
|
|
|
$hex3 = IPUtils::toHex( '2000:DEAD:BEEF:A:0:0:0:0' );
|
|
|
|
|
$hex4 = IPUtils::toHex( '2000:DEAD:BEEF:A:0:0:000A:000F' );
|
|
|
|
|
yield 'IPv6 start, same end' => [
|
|
|
|
|
$hex3,
|
|
|
|
|
null,
|
2024-04-09 02:49:33 +00:00
|
|
|
"((bt_ip_hex = '$hex3' AND bt_range_start IS NULL)"
|
|
|
|
|
. " OR (bt_range_start LIKE 'v6-2000%' ESCAPE '`'"
|
|
|
|
|
. " AND bt_range_start <= '$hex3'"
|
|
|
|
|
. " AND bt_range_end >= '$hex3'))"
|
2023-10-31 07:33:37 +00:00
|
|
|
];
|
|
|
|
|
yield 'IPv6 start, different end' => [
|
|
|
|
|
$hex3,
|
|
|
|
|
$hex4,
|
2024-04-09 02:49:33 +00:00
|
|
|
"(bt_range_start LIKE 'v6-2000%' ESCAPE '`'"
|
|
|
|
|
. " AND bt_range_start <= '$hex3'"
|
|
|
|
|
. " AND bt_range_end >= '$hex4')"
|
2023-10-31 07:33:37 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetRangeCond
|
|
|
|
|
* @covers ::getRangeCond
|
|
|
|
|
* @covers ::getIpFragment
|
|
|
|
|
*/
|
|
|
|
|
public function testGetRangeCond( $start, $end, $expect ) {
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$expect,
|
2024-04-09 03:26:02 +00:00
|
|
|
$this->getStore()->getRangeCond( $start, $end ) );
|
2023-10-31 07:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-24 01:26:33 +00:00
|
|
|
public static function provideGetRangeCondIntegrated() {
|
|
|
|
|
return [
|
|
|
|
|
'single IP block' => [ '3.3.3.3', '3.3.3.3', true ],
|
|
|
|
|
'/32 range blocks single IP' => [ '3.3.3.3/32', '3.3.3.3', true ],
|
|
|
|
|
'single IP block mismatch' => [ '3.3.3.3', '3.3.3.4', false ],
|
|
|
|
|
'/32 range mismatch' => [ '3.3.3.3/32', '3.3.3.4', false ],
|
|
|
|
|
'/24 match' => [ '3.3.3.0/24', '3.3.3.0', true ],
|
|
|
|
|
'/24 mismatch' => [ '3.3.3.0/24', '3.3.4.0', false ],
|
|
|
|
|
'range search exact match' => [ '3.3.3.0/24', '3.3.3.0/24', true ],
|
|
|
|
|
'encompassing range match' => [ '3.3.3.0/24', '3.3.3.1/27', true ],
|
|
|
|
|
'excessive range mismatch' => [ '3.3.0.0/24', '3.3.0.0/22', false ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test getRangeCond() by inserting blocks and checking for matches
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider provideGetRangeCondIntegrated
|
|
|
|
|
* @param string $blockTarget
|
|
|
|
|
* @param string $searchTarget
|
|
|
|
|
* @param bool $isBlocked
|
|
|
|
|
*/
|
|
|
|
|
public function testGetRangeCondIntegrated( $blockTarget, $searchTarget, $isBlocked ) {
|
|
|
|
|
$store = $this->getStore();
|
|
|
|
|
$store->insertBlock( $this->getBlock( [ 'target' => $blockTarget ] ) );
|
|
|
|
|
[ $start, $end ] = IPUtils::parseRange( $searchTarget );
|
2024-06-13 16:53:25 +00:00
|
|
|
$rows = $this->getDb()->newSelectQueryBuilder()
|
2024-04-09 03:26:02 +00:00
|
|
|
->queryInfo( $store->getQueryInfo() )
|
|
|
|
|
->where( $store->getRangeCond( $start, $end ) )
|
2024-04-24 01:26:33 +00:00
|
|
|
->fetchResultSet();
|
|
|
|
|
$this->assertSame( $isBlocked ? 1 : 0, $rows->numRows() );
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-08 06:29:23 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideInsertBlockSuccess
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertBlockSuccess( $options ) {
|
|
|
|
|
$block = $this->getBlock( $options['block'] ?? [] );
|
|
|
|
|
$block->setRestrictions( [
|
|
|
|
|
new NamespaceRestriction( 0, NS_MAIN ),
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getStore( $options['store'] ?? [] );
|
|
|
|
|
$result = $store->insertBlock( $block );
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray( $result );
|
|
|
|
|
$this->assertArrayHasKey( 'id', $result );
|
|
|
|
|
$this->assertArrayHasKey( 'autoIds', $result );
|
2021-01-30 12:51:38 +00:00
|
|
|
$this->assertCount( 0, $result['autoIds'] );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
2023-10-31 07:57:33 +00:00
|
|
|
$retrievedBlock = $store->newFromID( $result['id'] );
|
2020-05-08 06:29:23 +00:00
|
|
|
$this->assertTrue( $block->equals( $retrievedBlock ) );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideInsertBlockSuccess() {
|
2020-05-08 06:29:23 +00:00
|
|
|
return [
|
|
|
|
|
'No conflicting block, not autoblocking' => [
|
|
|
|
|
'block' => [
|
|
|
|
|
'autoblock' => false,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'No conflicting block, autoblocking but IP not in recent changes' => [
|
|
|
|
|
[
|
|
|
|
|
'block' => [
|
|
|
|
|
'autoblock' => true,
|
|
|
|
|
],
|
|
|
|
|
'store' => [
|
2024-07-09 15:36:08 +00:00
|
|
|
'constructorArgs' => [ MainConfigNames::PutIPinRC => false ],
|
2020-05-08 06:29:23 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'No conflicting block, autoblocking but no recent edits' => [
|
|
|
|
|
'block' => [
|
|
|
|
|
'autoblock' => true,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'Conflicting block, expired' => [
|
|
|
|
|
'block' => [
|
|
|
|
|
// Blocked with expired block in addDBData
|
|
|
|
|
'target' => '1.1.1.1',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInsertBlockConflict() {
|
|
|
|
|
$block = $this->getBlock( [ 'target' => $this->sysop ] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getStore();
|
|
|
|
|
$result = $store->insertBlock( $block );
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $result );
|
|
|
|
|
$this->assertNull( $block->getId() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideInsertBlockLogout
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertBlockLogout( $options, $expectTokenEqual ) {
|
|
|
|
|
$block = $this->getBlock();
|
2021-06-03 10:25:17 +00:00
|
|
|
$userFactory = $this->getServiceContainer()->getUserFactory();
|
|
|
|
|
$targetToken = $userFactory->newFromUserIdentity( $block->getTargetUserIdentity() )->getToken();
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$store = $this->getStore( $options );
|
2023-03-24 03:21:20 +00:00
|
|
|
$store->insertBlock( $block );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$expectTokenEqual,
|
2021-06-03 10:25:17 +00:00
|
|
|
$targetToken === $userFactory->newFromUserIdentity( $block->getTargetUserIdentity() )->getToken()
|
2020-05-08 06:29:23 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideInsertBlockLogout() {
|
2020-05-08 06:29:23 +00:00
|
|
|
return [
|
|
|
|
|
'Blocked user can log in' => [
|
|
|
|
|
[
|
2024-07-09 15:36:08 +00:00
|
|
|
'config' => [ MainConfigNames::BlockDisablesLogin => false ],
|
2020-05-08 06:29:23 +00:00
|
|
|
],
|
|
|
|
|
true,
|
|
|
|
|
],
|
|
|
|
|
'Blocked user cannot log in' => [
|
|
|
|
|
[
|
2024-07-09 15:36:08 +00:00
|
|
|
'config' => [ MainConfigNames::BlockDisablesLogin => true ],
|
2020-05-08 06:29:23 +00:00
|
|
|
],
|
|
|
|
|
false,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInsertBlockAutoblock() {
|
|
|
|
|
// This is quicker than adding a recent change for an unblocked user.
|
|
|
|
|
// See addDBDataOnce documentation for more details.
|
|
|
|
|
$target = $this->sysop;
|
2024-04-09 02:49:33 +00:00
|
|
|
$store = $this->getStore();
|
|
|
|
|
$store->deleteBlocksMatchingConds( [ 'bt_user' => $target->getId() ] );
|
2020-05-08 06:29:23 +00:00
|
|
|
$block = $this->getBlock( [
|
|
|
|
|
'autoblock' => true,
|
|
|
|
|
'target' => $target,
|
|
|
|
|
] );
|
2024-04-09 03:26:02 +00:00
|
|
|
|
2020-05-08 06:29:23 +00:00
|
|
|
$result = $store->insertBlock( $block );
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray( $result );
|
|
|
|
|
$this->assertArrayHasKey( 'autoIds', $result );
|
|
|
|
|
$this->assertCount( 1, $result['autoIds'] );
|
|
|
|
|
|
2023-10-31 07:57:33 +00:00
|
|
|
$retrievedBlock = $store->newFromID( $result['autoIds'][0] );
|
2020-05-08 06:29:23 +00:00
|
|
|
$this->assertSame( $block->getId(), $retrievedBlock->getParentBlockId() );
|
|
|
|
|
$this->assertAutoblockEqualsBlock( $block, $retrievedBlock );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInsertBlockError() {
|
|
|
|
|
$block = $this->createMock( DatabaseBlock::class );
|
|
|
|
|
|
2023-06-09 15:01:45 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
2020-05-08 06:29:23 +00:00
|
|
|
$this->expectExceptionMessage( 'insert' );
|
|
|
|
|
|
|
|
|
|
$store = $this->getStore();
|
|
|
|
|
$store->insertBlock( $block );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUpdateBlock() {
|
2023-10-31 07:57:33 +00:00
|
|
|
$store = $this->getStore();
|
|
|
|
|
$existingBlock = $store->newFromTarget( $this->sysop );
|
2024-02-15 04:57:43 +00:00
|
|
|
|
|
|
|
|
// Insert an autoblock for T351173 regression testing
|
|
|
|
|
$autoblockId = $store->doAutoblock( $existingBlock, '127.0.0.1' );
|
|
|
|
|
|
|
|
|
|
// Modify a block option
|
2020-05-08 06:29:23 +00:00
|
|
|
$existingBlock->isUsertalkEditAllowed( true );
|
2024-02-15 04:57:43 +00:00
|
|
|
$newExpiry = wfTimestamp( TS_MW, time() + 1000 );
|
|
|
|
|
$existingBlock->setExpiry( $newExpiry );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$result = $store->updateBlock( $existingBlock );
|
|
|
|
|
|
2023-10-31 07:57:33 +00:00
|
|
|
$updatedBlock = $store->newFromID( $result['id'] );
|
2024-02-15 04:57:43 +00:00
|
|
|
$autoblock = $store->newFromID( $autoblockId );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$this->assertTrue( $updatedBlock->equals( $existingBlock ) );
|
|
|
|
|
$this->assertAutoblockEqualsBlock( $existingBlock, $autoblock );
|
2024-02-15 04:57:43 +00:00
|
|
|
$this->assertLessThanOrEqual( $newExpiry, $autoblock->getExpiry() );
|
2020-05-08 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUpdateBlockAddOrRemoveAutoblock() {
|
2023-10-31 07:57:33 +00:00
|
|
|
$store = $this->getStore();
|
2020-05-08 06:29:23 +00:00
|
|
|
// Existing block is autoblocking to begin with
|
2023-10-31 07:57:33 +00:00
|
|
|
$existingBlock = $store->newFromTarget( $this->sysop );
|
2020-05-08 06:29:23 +00:00
|
|
|
$existingBlock->isAutoblocking( false );
|
|
|
|
|
|
|
|
|
|
$result = $store->updateBlock( $existingBlock );
|
|
|
|
|
|
2023-10-31 07:57:33 +00:00
|
|
|
$updatedBlock = $store->newFromID( $result['id'] );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$this->assertTrue( $updatedBlock->equals( $existingBlock ) );
|
|
|
|
|
$this->assertCount( 0, $result['autoIds'] );
|
|
|
|
|
|
|
|
|
|
// Test adding an autoblock in the same test run, since we need the
|
|
|
|
|
// target to be the sysop (see addDBDataOnce documentation), and the
|
|
|
|
|
// sysop is blocked with an autoblock between test runs.
|
|
|
|
|
$existingBlock->isAutoblocking( true );
|
|
|
|
|
$result = $store->updateBlock( $existingBlock );
|
|
|
|
|
|
2023-10-31 07:57:33 +00:00
|
|
|
$updatedBlock = $store->newFromID( $result['id'] );
|
|
|
|
|
$autoblock = $store->newFromID( $result['autoIds'][0] );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$this->assertTrue( $updatedBlock->equals( $existingBlock ) );
|
|
|
|
|
$this->assertAutoblockEqualsBlock( $existingBlock, $autoblock );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideUpdateBlockRestrictions
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateBlockRestrictions( $expectedCount ) {
|
2023-10-31 07:57:33 +00:00
|
|
|
$store = $this->getStore();
|
|
|
|
|
$existingBlock = $store->newFromTarget( $this->sysop );
|
2020-05-08 06:29:23 +00:00
|
|
|
$restrictions = [];
|
|
|
|
|
for ( $ns = 0; $ns < $expectedCount; $ns++ ) {
|
|
|
|
|
$restrictions[] = new NamespaceRestriction( $existingBlock->getId(), $ns );
|
|
|
|
|
}
|
|
|
|
|
$existingBlock->setRestrictions( $restrictions );
|
|
|
|
|
|
|
|
|
|
$result = $store->updateBlock( $existingBlock );
|
|
|
|
|
|
2023-10-31 07:57:33 +00:00
|
|
|
$retrievedBlock = $store->newFromID( $result['id'] );
|
2020-05-08 06:29:23 +00:00
|
|
|
$this->assertCount(
|
|
|
|
|
$expectedCount,
|
|
|
|
|
$retrievedBlock->getRestrictions()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideUpdateBlockRestrictions() {
|
2020-05-08 06:29:23 +00:00
|
|
|
return [
|
|
|
|
|
'Restrictions deleted if removed' => [ 0 ],
|
|
|
|
|
'Restrictions changed if updated' => [ 2 ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDeleteBlockSuccess() {
|
|
|
|
|
$store = $this->getStore();
|
2023-10-31 07:57:33 +00:00
|
|
|
$target = $this->sysop;
|
|
|
|
|
$block = $store->newFromTarget( $target );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$this->assertTrue( $store->deleteBlock( $block ) );
|
2023-10-31 07:57:33 +00:00
|
|
|
$this->assertNull( $store->newFromTarget( $target ) );
|
2020-05-08 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDeleteBlockFailureReadOnly() {
|
|
|
|
|
$store = $this->getStore( [
|
|
|
|
|
'constructorArgs' => [
|
2021-05-26 03:35:05 +00:00
|
|
|
'readOnlyMode' => $this->getDummyReadOnlyMode( true )
|
2020-05-08 06:29:23 +00:00
|
|
|
],
|
|
|
|
|
] );
|
2023-10-31 07:57:33 +00:00
|
|
|
$target = $this->sysop;
|
|
|
|
|
$block = $store->newFromTarget( $target );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$this->assertFalse( $store->deleteBlock( $block ) );
|
2023-10-31 07:57:33 +00:00
|
|
|
$this->assertTrue( (bool)$store->newFromTarget( $target ) );
|
2020-05-08 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDeleteBlockFailureNoBlockId() {
|
|
|
|
|
$block = $this->createMock( DatabaseBlock::class );
|
|
|
|
|
$block->method( 'getId' )
|
|
|
|
|
->willReturn( null );
|
2022-09-07 15:23:14 +00:00
|
|
|
$block->method( 'getWikiId' )
|
|
|
|
|
->willReturn( DatabaseBlock::LOCAL );
|
2020-05-08 06:29:23 +00:00
|
|
|
|
2023-06-09 15:01:45 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
2020-05-08 06:29:23 +00:00
|
|
|
$this->expectExceptionMessage( 'delete' );
|
|
|
|
|
|
|
|
|
|
$store = $this->getStore();
|
|
|
|
|
$store->deleteBlock( $block );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether expired blocks and restrictions were removed from the database.
|
|
|
|
|
*
|
|
|
|
|
* @param int $blockId
|
|
|
|
|
* @param bool $expected Whether to expect to find any rows
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
private function assertPurgeWorked( int $blockId, bool $expected ): void {
|
2024-06-13 16:53:25 +00:00
|
|
|
$blockRows = (bool)$this->getDb()->newSelectQueryBuilder()
|
2024-04-09 02:49:33 +00:00
|
|
|
->select( 'bl_id' )
|
|
|
|
|
->from( 'block' )
|
|
|
|
|
->where( [ 'bl_id' => $blockId ] )
|
2023-09-21 16:37:37 +00:00
|
|
|
->fetchResultSet()->numRows();
|
2024-06-13 16:53:25 +00:00
|
|
|
$blockRestrictionsRows = (bool)$this->getDb()->newSelectQueryBuilder()
|
2023-09-21 16:37:37 +00:00
|
|
|
->select( 'ir_ipb_id' )
|
|
|
|
|
->from( 'ipblocks_restrictions' )
|
|
|
|
|
->where( [ 'ir_ipb_id' => $blockId ] )
|
|
|
|
|
->fetchResultSet()->numRows();
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$this->assertSame( $expected, $blockRows );
|
|
|
|
|
$this->assertSame( $expected, $blockRestrictionsRows );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testPurgeExpiredBlocksSuccess() {
|
|
|
|
|
$store = $this->getStore();
|
|
|
|
|
$store->purgeExpiredBlocks();
|
|
|
|
|
|
|
|
|
|
$this->assertPurgeWorked( $this->expiredBlockId, false );
|
|
|
|
|
$this->assertPurgeWorked( $this->unexpiredBlockId, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testPurgeExpiredBlocksFailureReadOnly() {
|
|
|
|
|
$store = $this->getStore( [
|
|
|
|
|
'constructorArgs' => [
|
2021-05-26 03:35:05 +00:00
|
|
|
'readOnlyMode' => $this->getDummyReadOnlyMode( true ),
|
2020-05-08 06:29:23 +00:00
|
|
|
],
|
|
|
|
|
] );
|
|
|
|
|
$store->purgeExpiredBlocks();
|
|
|
|
|
|
|
|
|
|
$this->assertPurgeWorked( $this->expiredBlockId, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* In order to autoblock a user, they must have a recent change.
|
|
|
|
|
*
|
|
|
|
|
* Make a recent change for the test sysop. This user persists between test runs,
|
|
|
|
|
* so will always have this recent change.
|
|
|
|
|
*
|
|
|
|
|
* Regular test users don't persist between test runs, because the TestUserRegistry
|
|
|
|
|
* is cleared between runs. If we tested autoblocking on a regular test user, we
|
|
|
|
|
* would need to make a recent change for each test, which is slow.
|
|
|
|
|
*
|
|
|
|
|
* Instead we always test autoblocks on the test sysop.
|
|
|
|
|
*/
|
|
|
|
|
public function addDBDataOnce() {
|
|
|
|
|
$this->editPage(
|
2023-08-09 01:01:19 +00:00
|
|
|
'DatabaseBlockStoreTest test page',
|
2020-05-08 06:29:23 +00:00
|
|
|
'an edit',
|
|
|
|
|
'a summary',
|
|
|
|
|
NS_MAIN,
|
|
|
|
|
$this->getTestSysop()->getUser()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Three blocks are added:
|
|
|
|
|
* - an expired block with restrictions, against an IP
|
|
|
|
|
* - a current block with restrictions, against a user with recent changes
|
|
|
|
|
* - a current autoblock from the current block above
|
|
|
|
|
*/
|
|
|
|
|
public function addDBData() {
|
|
|
|
|
$this->sysop = $this->getTestSysop()->getUser();
|
|
|
|
|
|
2023-08-09 01:01:19 +00:00
|
|
|
// Get a comment ID. One was added in addDBDataOnce.
|
2024-06-13 16:53:25 +00:00
|
|
|
$commentId = $this->getDb()->newSelectQueryBuilder()
|
2024-05-02 20:22:10 +00:00
|
|
|
->select( 'comment_id' )
|
|
|
|
|
->from( 'comment' )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchField();
|
2020-05-08 06:29:23 +00:00
|
|
|
|
|
|
|
|
$commonBlockData = [
|
2024-04-09 02:49:33 +00:00
|
|
|
'bl_by_actor' => $this->sysop->getActorId(),
|
|
|
|
|
'bl_reason_id' => $commentId,
|
2024-06-13 16:53:25 +00:00
|
|
|
'bl_timestamp' => $this->getDb()->timestamp( '20000101000000' ),
|
2024-04-09 02:49:33 +00:00
|
|
|
'bl_anon_only' => 0,
|
|
|
|
|
'bl_create_account' => 0,
|
|
|
|
|
'bl_deleted' => 0,
|
|
|
|
|
'bl_block_email' => 0,
|
|
|
|
|
'bl_allow_usertalk' => 0,
|
|
|
|
|
'bl_sitewide' => 0,
|
2020-05-08 06:29:23 +00:00
|
|
|
];
|
|
|
|
|
|
2024-04-09 02:49:33 +00:00
|
|
|
$targetRows = [
|
|
|
|
|
'1.1.1.1' => [
|
|
|
|
|
'bt_address' => '1.1.1.1',
|
|
|
|
|
'bt_ip_hex' => IPUtils::toHex( '1.1.1.1' ),
|
|
|
|
|
'bt_auto' => 0,
|
|
|
|
|
],
|
|
|
|
|
'sysop' => [
|
|
|
|
|
'bt_user' => $this->sysop->getId(),
|
|
|
|
|
'bt_user_text' => $this->sysop->getName(),
|
|
|
|
|
'bt_auto' => 0,
|
|
|
|
|
],
|
|
|
|
|
'2.2.2.2' => [
|
|
|
|
|
'bt_address' => '2.2.2.2',
|
|
|
|
|
'bt_ip_hex' => IPUtils::toHex( '2.2.2.2' ),
|
|
|
|
|
'bt_auto' => 1,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
$targetIds = [];
|
|
|
|
|
foreach ( $targetRows as $i => $row ) {
|
2024-06-13 16:53:25 +00:00
|
|
|
$this->getDb()->newInsertQueryBuilder()
|
2024-04-09 02:49:33 +00:00
|
|
|
->insertInto( 'block_target' )
|
|
|
|
|
->row( $row + [ 'bt_count' => 1 ] )
|
|
|
|
|
->execute();
|
2024-06-13 16:53:25 +00:00
|
|
|
$targetIds[$i] = $this->getDb()->insertId();
|
2024-04-09 02:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-08 06:29:23 +00:00
|
|
|
$blockData = [
|
|
|
|
|
[
|
2024-04-09 02:49:33 +00:00
|
|
|
'bl_id' => $this->expiredBlockId,
|
|
|
|
|
'bl_target' => $targetIds['1.1.1.1'],
|
2024-06-13 16:53:25 +00:00
|
|
|
'bl_expiry' => $this->getDb()->timestamp( '20010101000000' ),
|
2024-04-09 02:49:33 +00:00
|
|
|
'bl_enable_autoblock' => 0,
|
|
|
|
|
'bl_parent_block_id' => 0,
|
2024-04-14 19:33:50 +00:00
|
|
|
] + $commonBlockData,
|
2020-05-08 06:29:23 +00:00
|
|
|
[
|
2024-04-09 02:49:33 +00:00
|
|
|
'bl_id' => $this->unexpiredBlockId,
|
|
|
|
|
'bl_target' => $targetIds['sysop'],
|
2024-06-13 16:53:25 +00:00
|
|
|
'bl_expiry' => $this->getDb()->getInfinity(),
|
2024-04-09 02:49:33 +00:00
|
|
|
'bl_enable_autoblock' => 1,
|
|
|
|
|
'bl_parent_block_id' => 0,
|
2024-04-14 19:33:50 +00:00
|
|
|
] + $commonBlockData,
|
2020-05-08 06:29:23 +00:00
|
|
|
[
|
2024-04-09 02:49:33 +00:00
|
|
|
'bl_id' => $this->autoblockId,
|
|
|
|
|
'bl_target' => $targetIds['2.2.2.2'],
|
2024-06-13 16:53:25 +00:00
|
|
|
'bl_expiry' => $this->getDb()->getInfinity(),
|
2024-04-09 02:49:33 +00:00
|
|
|
'bl_enable_autoblock' => 0,
|
|
|
|
|
'bl_parent_block_id' => $this->unexpiredBlockId,
|
2024-04-14 19:33:50 +00:00
|
|
|
] + $commonBlockData,
|
2020-05-08 06:29:23 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$restrictionData = [
|
|
|
|
|
[
|
|
|
|
|
'ir_ipb_id' => $this->expiredBlockId,
|
|
|
|
|
'ir_type' => 1,
|
|
|
|
|
'ir_value' => 1,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'ir_ipb_id' => $this->unexpiredBlockId,
|
|
|
|
|
'ir_type' => 2,
|
|
|
|
|
'ir_value' => 2,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'ir_ipb_id' => $this->autoblockId,
|
|
|
|
|
'ir_type' => 2,
|
|
|
|
|
'ir_value' => 2,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
2024-06-13 16:53:25 +00:00
|
|
|
$this->getDb()->newInsertQueryBuilder()
|
2024-04-09 02:49:33 +00:00
|
|
|
->insertInto( 'block' )
|
2024-04-14 19:33:50 +00:00
|
|
|
->rows( $blockData )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->execute();
|
2020-05-08 06:29:23 +00:00
|
|
|
|
2024-06-13 16:53:25 +00:00
|
|
|
$this->getDb()->newInsertQueryBuilder()
|
2024-04-14 19:33:50 +00:00
|
|
|
->insertInto( 'ipblocks_restrictions' )
|
|
|
|
|
->rows( $restrictionData )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->execute();
|
2020-05-08 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|