Skip to content

Space admin table should have a REFERENCES user_id ON DELETE CASCADE type constraint #14

@wgevaert

Description

@wgevaert

I am doing the following:

$oldSpace = Space::newFromConstant( $id );
$newSpace = clone $oldSpace;
$newSpace->setName( 'New name Foo' );
$newSpace->setDescription( "Foo Bar Baz" );
$WssNamespaceRepository->updateSpace( $oldSpace, $newSpace, true );

And I (sometimes) get this error:

InvalidArgumentException: UserGroupManager::removeUserFromGroup() needs a positive user ID. Perhaps removeUserFromGroup() was called before the user was added to the database. in /var/www/html/includes/user/UserGroupManager.php:964
Stack trace:
#0 /var/www/html/extensions/WSSpaces/src/NamespaceRepository.php(469): MediaWiki\User\UserGroupManager->removeUserFromGroup()
#1 /var/www/html/extensions/WSSpaces/src/NamespaceRepository.php(371): WSS\NamespaceRepository->removeUserFromUserGroup()
#2 /var/www/html/extensions/WSSpaces/src/NamespaceRepository.php(282): WSS\NamespaceRepository->updateSpaceAdministrators()

Did some debugging, and the problem is the following:
Some user ids in the wss_namespace_admins table do not correspond to users in the user table; These users have probably been deleted in some way.

Preferably, the wss_namespace_admins table has a FOREIGN KEY constraint on user ID with a ON DELETE CASCADE, such that these things do not happen.

As a start, the users should not be updated if they do not exist.

MW version: 1.39.5
PHP version: 8.0.30

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions