Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses IShare::TYPE_... in Server.php rather than the obsolete Constants #32647

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/Collaboration/Collaborators/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset) {
}

public function registerPlugin(array $pluginInfo) {
$shareType = constant(Share::class . '::' . $pluginInfo['shareType']);
$shareType = $pluginInfo['shareType'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So your proposal is:

Suggested change
$shareType = $pluginInfo['shareType'];
if (str_starts_with($pluginInfo['shareType'], 'SHARE_TYPE') {
$shareType = constant(Share::class . '::' . $pluginInfo['shareType']);
} else {
$shareType = $pluginInfo['shareType'];
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

Suggested change
$shareType = $pluginInfo['shareType'];
if (str_starts_with($pluginInfo['shareType'], 'SHARE_TYPE') {
$shareType = constant(IShare::class . '::' . substr($pluginInfo['shareType'], 6));
} else {
$shareType = $pluginInfo['shareType'];
}

This way we still get rid of the old constats?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also note that $shareType is a int after constant() but not with your code.
So should use the following on the else branch

		$shareType = (int) $pluginInfo['shareType'];

if ($shareType === null) {
throw new \InvalidArgumentException('Provided ShareType is invalid');
}
Expand Down
11 changes: 6 additions & 5 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
use OCP\Security\ISecureRandom;
use OCP\Security\ITrustedDomainHelper;
use OCP\Security\VerificationToken\IVerificationToken;
use OCP\Share\IShare;
use OCP\Share\IShareHelper;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
Expand Down Expand Up @@ -1313,11 +1314,11 @@ public function __construct($webRoot, \OC\Config $config) {
$instance = new Collaboration\Collaborators\Search($c);

// register default plugins
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
$instance->registerPlugin(['shareType' => IShare::TYPE_USER, 'class' => UserPlugin::class]);
$instance->registerPlugin(['shareType' => IShare::TYPE_GROUP, 'class' => GroupPlugin::class]);
$instance->registerPlugin(['shareType' => IShare::TYPE_EMAIL, 'class' => MailPlugin::class]);
$instance->registerPlugin(['shareType' => IShare::TYPE_REMOTE, 'class' => RemotePlugin::class]);
$instance->registerPlugin(['shareType' => IShare::TYPE_REMOTE_GROUP, 'class' => RemoteGroupPlugin::class]);

return $instance;
});
Expand Down