Skip to content

IUserConfig - #47658

Merged
skjnldsv merged 5 commits into
masterfrom
enh/noid/user-preferences
Nov 19, 2024
Merged

IUserConfig#47658
skjnldsv merged 5 commits into
masterfrom
enh/noid/user-preferences

Conversation

@ArtificialOwl

@ArtificialOwlArtificialOwl commented Aug 31, 2024

Copy link
Copy Markdown
Member
  • replace IConfig's preferences-related method
  • tests

Comment threadcore/Migrations/Version31000Date20240814184402.php Fixed
Comment threadcore/Migrations/Version31000Date20240814184402.php Fixed
Comment threadcore/Migrations/Version31000Date20240814184402.php Fixed
Comment threadlib/private/UserPreferences.php Fixed
Comment threadlib/private/UserPreferences.php Fixed
Comment threadlib/public/UserPreferences/ValueType.php Fixed
Comment threadlib/public/UserPreferences/ValueType.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch 2 times, most recently from 6d81b97 to a9e2a38CompareAugust 31, 2024 22:30
Comment threadlib/private/UserPreferences.php Fixed
Comment threadlib/private/UserPreferences.php Fixed
Comment threadlib/public/UserPreferences/IUserPreferences.php Fixed
Comment threadlib/public/UserPreferences/IUserPreferences.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from e9ec009 to cda7029CompareSeptember 1, 2024 19:15
Comment threadlib/private/AllConfig.php Fixed
Comment threadlib/private/AllConfig.php Fixed
Comment threadlib/private/UserPreferences.php Fixed
Comment threadlib/private/UserPreferences.php Fixed
Comment threadlib/private/UserPreferences.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from 1fbb6a9 to 317202aCompareSeptember 1, 2024 22:42
Comment threadlib/private/AllConfig.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from c78f304 to 979eceeCompareSeptember 2, 2024 01:09
Comment threadlib/private/AllConfig.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from 979ecee to 41ba78fCompareSeptember 2, 2024 01:19
Comment threadlib/private/AllConfig.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch 2 times, most recently from 8edb1c1 to e510535CompareSeptember 2, 2024 02:31
Comment threadlib/private/UserPreferences.php Fixed
Comment threadlib/private/UserPreferences.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from f71bb7d to e24d29aCompareSeptember 2, 2024 03:33
Comment threadlib/private/AllConfig.php Fixed
Comment threadlib/private/AllConfig.php Fixed
Comment threadlib/private/AllConfig.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch 2 times, most recently from 32c209d to b80315bCompareSeptember 2, 2024 14:57
Comment threadlib/private/AllConfig.php Fixed
Comment threadlib/private/AllConfig.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from b80315b to 0c489afCompareSeptember 2, 2024 16:03
Comment threadlib/private/UserPreferences.php Fixed
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from 0c489af to 6ae7f9fCompareSeptember 2, 2024 19:50
Comment threadlib/public/UserPreferences/ValueTypeDefinition.php Outdated
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from ceb814d to a219133CompareSeptember 30, 2024 16:25
@ArtificialOwl
ArtificialOwl marked this pull request as ready for review September 30, 2024 16:26
@ArtificialOwlArtificialOwl added the 3. to review Waiting for reviews label Sep 30, 2024
@ArtificialOwlArtificialOwl added this to the Nextcloud 31 milestone Sep 30, 2024
Comment threadlib/private/UserPreferences.php Outdated
$value = $cache[$app][$key];
try {
$this->decryptSensitiveValue($userId, $app, $key, $value);
$value = $this->convertTypedValue($value, $typedAs ?? $this->getValueType($userId, (string)$app, $key, $lazy));

Check failure

Code scanning / Psalm

RedundantCast

Redundant cast to string
Comment threadlib/private/UserPreferences.php Outdated
* @param string $value preference value
* @param bool $caseInsensitive non-case-sensitive search, only works if $value is a string
*
* @return list<string>

Check failure

Code scanning / Psalm

MoreSpecificReturnType

The declared return type 'list<string>' for OC\UserPreferences::searchUsersByValueString is more specific than the inferred return type 'array<array-key, mixed>'
* @since 31.0.0
*/
public function searchUsersByValueString(string $app, string $key, string $value, bool $caseInsensitive = false): array {
return $this->searchUsersByTypedValue($app, $key, $value, $caseInsensitive);

Check failure

Code scanning / Psalm

LessSpecificReturnStatement

The type 'array<array-key, mixed>' is more general than the declared return type 'list<string>' for OC\UserPreferences::searchUsersByValueString
Comment threadlib/private/UserPreferences.php Outdated
* @param string $key preference key
* @param array $values list of preference values
*
* @return list<string>

Check failure

Code scanning / Psalm

MoreSpecificReturnType

The declared return type 'list<string>' for OC\UserPreferences::searchUsersByValues is more specific than the inferred return type 'array<array-key, mixed>'
* @since 31.0.0
*/
public function searchUsersByValues(string $app, string $key, array $values): array {
return $this->searchUsersByTypedValue($app, $key, $values);

Check failure

Code scanning / Psalm

LessSpecificReturnStatement

The type 'array<array-key, mixed>' is more general than the declared return type 'list<string>' for OC\UserPreferences::searchUsersByValues

@susnuxsusnux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🥳

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
@ArtificialOwl
ArtificialOwlforce-pushed the enh/noid/user-preferences branch from 97ab26e to 5b4f190CompareNovember 18, 2024 21:11
@skjnldsvskjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 2. developing Work in progress labels Nov 19, 2024
@skjnldsvskjnldsv changed the title IUserPreferencesIUserConfigNov 19, 2024
@skjnldsv
skjnldsv merged commit 899b651 into masterNov 19, 2024
@skjnldsv
skjnldsv deleted the enh/noid/user-preferences branch November 19, 2024 08:31
@kesselb

Copy link
Copy Markdown
Contributor

Please send a follow-up and increase the version to trigger the migration.

@st3iny

Copy link
Copy Markdown
Member

Please send a follow-up and increase the version to trigger the migration.

An exception occurred while executing a query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'type' in 'field list' /home/richard/src/nextcloud/master/lib/private/DB/Exceptions/DbalException.php at 54

*
* @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
* @throws \UnexpectedValueException when trying to store an unexpected value
* @deprecated 31.0.0 - use {@see IUserConfig} directly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://docs.nextcloud.com/server/latest/developer_manual/digging_deeper/api.html#php-unstable-api

Code from the OCP namespace must never mention anything coming from the NCU namespace. It can not require it as an argument, constant or return something from NCU.

So you can not deprecate this and neither the public interface.

* @param mixed $default the default value to be returned if the value isn't set
*
* @return string
* @deprecated 31.0.0 - use {@see IUserConfig} directly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same for all methods

@nickvergessen

Copy link
Copy Markdown
Member

💥 This PR breaks talks tests.
We set a user config and fetch it in another place of the code, but receive the default value instead:
https://github.com/nextcloud/spreed/actions/runs/11911817197/job/33195693787?pr=13750#step:15:2199

string $userId,
string $app,
string $key,
string $default = '',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Breaking change, before mixed was documented and no type was casted.
At least null is used by apps and was used even in server's own method (setUserValue)

string $key,
string $default = '',
?bool $lazy = false,
): string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When the default value is "widen" again, the return type also needs to be

@skjnldsvskjnldsv added the pending documentation This pull request needs an associated documentation update label Nov 19, 2024
@skjnldsv

skjnldsv commented Nov 19, 2024

Copy link
Copy Markdown
Member

$userPreferences = \OCP\Server::get(IUserConfig::class);
if ($preCondition !== null) {
try {
if ($userPreferences->getValueMixed($userId, $appName, $key) !== (string)$preCondition) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is a behaviour change, previously the precondition did not fail, when the value is not set in the database.

* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace NCU\Config\Exceptions;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please create a documentation for this new Namespace and the way it should work (when is it going to become stable, when can devs use it... etc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

// removing this index from Version13000Date20170718121200
// $table->addIndex(['appid', 'configkey'], 'preferences_app_key');
if ($table->hasIndex('preferences_app_key')) {
$table->dropIndex('preferences_app_key');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

for my dev instance running mariadb this DROP did not happen, so I now have redundant indexes:

image

The migration code seems correct, but something seems to prevent the DROP. @ArtificialOwl could you check the upgrade path?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See #49638

The index is dropped... But next repair step run adds it again

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to releaseReady to be released and/or waiting for tests to finishdeveloper experienceenhancementpending documentationThis pull request needs an associated documentation update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@ArtificialOwl@kesselb@st3iny@nickvergessen@skjnldsv@ChristophWurst@susnux@artonge@github-advanced-security@come-nc