private $nameField;
/** @var null|callable */
private $normalizationCallback = null;
+ /** @var null|callable */
+ private $insertCallback = null;
/**
* @param LoadBalancer $dbLoadBalancer A load balancer for acquiring database connections
* @param callable $normalizationCallback Normalization to be applied to names before being
* saved or queried. This should be a callback that accepts and returns a single string.
* @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
+ * @param callable $insertCallback Callback to change insert fields accordingly.
+ * This parameter was introduced in 1.32
*/
public function __construct(
LoadBalancer $dbLoadBalancer,
$idField,
$nameField,
callable $normalizationCallback = null,
- $wikiId = false
+ $wikiId = false,
+ callable $insertCallback = null
) {
$this->loadBalancer = $dbLoadBalancer;
$this->cache = $cache;
$this->normalizationCallback = $normalizationCallback;
$this->wikiId = $wikiId;
$this->cacheTTL = IExpiringStore::TTL_MONTH;
+ $this->insertCallback = $insertCallback;
}
/**
$dbw = $this->getDBConnection( DB_MASTER );
+ $insertFields = [ $this->nameField => $name ];
+ if ( $this->insertCallback !== null ) {
+ $insertFields = call_user_func( $this->insertCallback, $insertFields );
+ }
+
$dbw->insert(
$this->table,
- [ $this->nameField => $name ],
+ $insertFields,
__METHOD__,
[ 'IGNORE' ]
);
BagOStuff $cacheBag,
$insertCalls,
$selectCalls,
- $normalizationCallback = null
+ $normalizationCallback = null,
+ $insertCallback = null
) {
return new NameTableStore(
$this->getMockLoadBalancer( $this->getCallCheckingDb( $insertCalls, $selectCalls ) ),
$this->getHashWANObjectCache( $cacheBag ),
new NullLogger(),
'slot_roles', 'role_id', 'role_name',
- $normalizationCallback
+ $normalizationCallback,
+ false,
+ $insertCallback
);
}
$this->assertSame( $barId, $store3->acquireId( 'bar' ) );
}
+ public function testGetAndAcquireIdInsertCallback() {
+ $store = $this->getNameTableSqlStore(
+ new EmptyBagOStuff(),
+ 1,
+ 1,
+ null,
+ function ( $insertFields ) {
+ $insertFields['role_id'] = 7251;
+ return $insertFields;
+ }
+ );
+ $this->assertSame( 7251, $store->acquireId( 'A' ) );
+ }
+
}