Skip to content

Commit db74154

Browse files
DeepDiver1975claude
andcommitted
fix(occ): pass empty string instead of null to user search in home list commands
user:home:list-dirs and user:home:list-users --all passed null as the search pattern to IUserManager::search(). On PHP 8 the null reached Connection::escapeLikeParameter(string $param) and raised a TypeError, aborting the command. Use the empty string '' instead, which is the established "match all" sentinel recognised by UserSearch::isSearchable() and used by every other caller. Fixes #41630 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
1 parent ac51c77 commit db74154

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

changelog/unreleased/41630

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Bugfix: Fix user:home:list-dirs and user:home:list-users crashing on PHP 8
2+
3+
The occ commands user:home:list-dirs and user:home:list-users --all passed
4+
null as the search pattern to IUserManager::search() to mean "all users".
5+
On PHP 8 the null reached Connection::escapeLikeParameter(string $param) and
6+
raised a TypeError, aborting the command. Both commands now pass the empty
7+
string, which is the established "match all" sentinel used by every other
8+
caller.
9+
10+
https://github.com/owncloud/core/issues/41630

core/Command/User/HomeListDirs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5252
$output->writeln('<info>We detected that the instance is running on a S3 primary object storage, home directories might not be accurate</info>');
5353
}
5454

55-
$users = $this->userManager->search(null);
55+
$users = $this->userManager->search('');
5656
$homePaths = [];
5757
foreach ($users as $user) {
5858
$home = $user->getHome();

core/Command/User/HomeListUsers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7979
$output->writeln('<error>--all and path option cannot be given together</error>');
8080
return 1;
8181
}
82-
$users = $this->userManager->search(null, null, null, true);
82+
$users = $this->userManager->search('', null, null, true);
8383
$outputData = [];
8484
foreach ($users as $user) {
8585
$home = $user->getHome();

tests/Core/Command/User/HomeListDirsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ public function testCommandInput($objectStorageUsed) {
7070
$user2Mock = $this->createMock(IUser::class);
7171
$user2Mock->method('getHome')->willReturn("$homePath/user2");
7272

73-
$this->userManager->method('search')->willReturn([$user1Mock, $user2Mock]);
73+
$this->userManager->expects($this->once())
74+
->method('search')
75+
->with($this->identicalTo(''))
76+
->willReturn([$user1Mock, $user2Mock]);
7477
$this->commandTester->execute([]);
7578
$output = $this->commandTester->getDisplay();
7679
$this->assertStringContainsString($homePath, $output);

tests/Core/Command/User/HomeListUsersTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ public function testCommandInputAll() {
114114
->getMock();
115115
$userObject->method('getHome')->willReturn($path . '/' . $uid);
116116
$userObject->method('getUID')->willReturn($uid);
117-
$this->userManager->method('search')->willReturn([$uid => $userObject]);
117+
$this->userManager->expects($this->once())
118+
->method('search')
119+
->with($this->identicalTo(''), null, null, true)
120+
->willReturn([$uid => $userObject]);
118121

119122
$this->commandTester->execute(['--all' => true]);
120123
$output = $this->commandTester->getDisplay();

0 commit comments

Comments
 (0)