25use InvalidArgumentException;
41 private $joinCache = [];
54 private bool $allowUnknown;
56 private bool $forImport =
false;
89 $this->fieldInfos = $fieldInfos;
90 $this->allowUnknown = $options[
'allowUnknown'] ??
true;
94 if ( $writeStage === 0 ) {
95 throw new InvalidArgumentException(
'$stage must include a write mode' );
97 if ( $readStage === 0 ) {
98 throw new InvalidArgumentException(
'$stage must include a read mode' );
101 throw new InvalidArgumentException(
'Cannot read multiple schemas' );
104 throw new InvalidArgumentException(
'Cannot read the old schema without also writing it' );
107 throw new InvalidArgumentException(
'Cannot read the new schema without also writing it' );
109 $this->readStage = $readStage;
110 $this->writeStage = $writeStage;
120 throw new LogicException( __METHOD__ .
" must be overridden" );
132 if ( isset( $this->fieldInfos[$key] ) ) {
133 return $this->fieldInfos[$key];
134 } elseif ( $this->allowUnknown ) {
137 throw new InvalidArgumentException( $this->
getInstanceName() .
": unknown key $key" );
150 if ( (
new ReflectionClass( $this ) )->isAnonymous() ) {
154 return static::class;
167 if ( isset( $fieldInfo[
'removedVersion'] ) ) {
168 $removedVersion = $fieldInfo[
'removedVersion'];
169 $component = $fieldInfo[
'component'] ??
'MediaWiki';
170 throw new InvalidArgumentException(
171 "Use of {$this->getInstanceName()} for '$key' was removed in $component $removedVersion"
174 if ( isset( $fieldInfo[
'deprecatedVersion'] ) ) {
175 $deprecatedVersion = $fieldInfo[
'deprecatedVersion'];
176 $component = $fieldInfo[
'component'] ??
'MediaWiki';
177 wfDeprecated(
"{$this->getInstanceName()} for '$key'", $deprecatedVersion, $component, 3 );
204 private function getFieldNames( $key ) {
206 $textField = $fieldInfo[
'textField'] ?? $key .
'_text';
207 $actorField = $fieldInfo[
'actorField'] ?? substr( $key, 0, -5 ) .
'_actor';
208 return [ $textField, $actorField ];
226 if ( !isset( $this->joinCache[$key] ) ) {
231 [ $text, $actor ] = $this->getFieldNames( $key );
234 $fields[$key] = $key;
235 $fields[$text] = $text;
236 $fields[$actor] =
'NULL';
238 $alias =
"actor_$key";
239 $tables[$alias] =
'actor';
240 $joins[$alias] = [
'JOIN',
"{$alias}.actor_id = {$actor}" ];
242 $fields[$key] =
"{$alias}.actor_user";
243 $fields[$text] =
"{$alias}.actor_name";
244 $fields[$actor] = $actor;
247 $this->joinCache[$key] = [
254 return $this->joinCache[$key];
269 [ $text, $actor ] = $this->getFieldNames( $key );
272 $ret[$key] = $user->
getId();
273 $ret[$text] = $user->
getName();
277 ->acquireActorId( $user, $dbw );
315 } elseif ( $users ===
null || $users ===
false ) {
318 } elseif ( !is_array( $users ) ) {
319 $what = get_debug_type( $users );
320 throw new InvalidArgumentException(
321 __METHOD__ .
": Value for \$users must be a UserIdentity or array, got $what"
329 foreach ( $users as $user ) {
330 if ( $useId && $user->isRegistered() ) {
331 $ids[] = $user->getId();
334 $names[] = IPUtils::sanitizeIP( $user->getName() );
337 ->findActorId( $user, $db );
340 $actors[] = $actorId;
344 [ $text, $actor ] = $this->getFieldNames( $key );
349 $conds[
'newactor'] = $db->
makeList( [ $actor => $actors ], IDatabase::LIST_AND );
353 $conds[
'userid'] = $db->
makeList( [ $key => $ids ], IDatabase::LIST_AND );
356 $conds[
'username'] = $db->
makeList( [ $text => $names ], IDatabase::LIST_AND );
362 'conds' => $conds ? $db->
makeList( array_values( $conds ), IDatabase::LIST_OR ) :
'1=0',
373 $this->forImport = $forImport;
381 if ( $this->forImport ) {
382 return $this->actorStoreFactory->getActorNormalizationForImport( $domainId );
384 return $this->actorStoreFactory->getActorNormalization( $domainId );
390class_alias( ActorMigrationBase::class,
'ActorMigrationBase' );
const SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_WRITE_OLD
const SCHEMA_COMPAT_READ_OLD
const SCHEMA_COMPAT_WRITE_NEW
const SCHEMA_COMPAT_WRITE_MASK
const SCHEMA_COMPAT_READ_MASK
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))