Skip to content

Commit

Permalink
Merge pull request #37507 from nextcloud/fix/config-values-types
Browse files Browse the repository at this point in the history
Fix types for reading and writing config values
  • Loading branch information
provokateurin authored Apr 5, 2023
2 parents 54140dd + d9f8522 commit 88ab6d4
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ protected function getSuggestedOverwriteCliURL(): string {
}

protected function getLastCronInfo(): array {
$lastCronRun = $this->config->getAppValue('core', 'lastcron', 0);
$lastCronRun = (int)$this->config->getAppValue('core', 'lastcron', '0');
return [
'diffInSeconds' => time() - $lastCronRun,
'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun),
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/lib/Settings/Admin/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getForm() {
'shareExcludedGroupsList' => $excludeGroupsList,
'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL),
'shareApiDefaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL),
'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(),
'shareDefaultInternalExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'),
'shareInternalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
Expand Down
4 changes: 2 additions & 2 deletions apps/settings/tests/Settings/Admin/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testGetFormWithoutExcludedGroups(): void {
['core', 'shareapi_exclude_groups', 'no', 'no'],
['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
['core', 'shareapi_default_permissions', Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
Expand Down Expand Up @@ -175,7 +175,7 @@ public function testGetFormWithExcludedGroups(): void {
['core', 'shareapi_exclude_groups', 'no', 'yes'],
['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
['core', 'shareapi_default_permissions', Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
Expand Down
4 changes: 2 additions & 2 deletions apps/updatenotification/lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function isUpdaterEnabled() {
*/
public function setChannel(string $channel): DataResponse {
Util::setChannel($channel);
$this->config->setAppValue('core', 'lastupdatedat', 0);
$this->config->setAppValue('core', 'lastupdatedat', '0');
return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]);
}

Expand All @@ -99,7 +99,7 @@ public function createCredentials(): DataResponse {

// Create a new job and store the creation date
$this->jobList->add(ResetTokenBackgroundJob::class);
$this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
$this->config->setAppValue('core', 'updater.secret.created', (string)$this->timeFactory->getTime());

// Create a new token
$newToken = $this->secureRandom->generate(64);
Expand Down
6 changes: 3 additions & 3 deletions apps/updatenotification/lib/Notification/BackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ protected function checkCoreUpdate() {

$status = $updater->check();
if ($status === false) {
$errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0);
$this->config->setAppValue('updatenotification', 'update_check_errors', $errors);
$errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', '0');
$this->config->setAppValue('updatenotification', 'update_check_errors', (string)$errors);

if (\in_array($errors, $this->connectionNotifications, true)) {
$this->sendErrorNotifications($errors);
}
} elseif (\is_array($status)) {
$this->config->setAppValue('updatenotification', 'update_check_errors', 0);
$this->config->setAppValue('updatenotification', 'update_check_errors', '0');
$this->clearErrorNotifications();

if (isset($status['version'])) {
Expand Down
2 changes: 1 addition & 1 deletion apps/updatenotification/lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function prepare(INotification $notification, string $languageCode): INot

$l = $this->l10NFactory->get('updatenotification', $languageCode);
if ($notification->getSubject() === 'connection_error') {
$errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0);
$errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', '0');
if ($errors === 0) {
$this->notificationManager->markProcessed($notification);
throw new \InvalidArgumentException('Update checked worked again');
Expand Down
2 changes: 1 addition & 1 deletion apps/updatenotification/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(
}

public function getForm(): TemplateResponse {
$lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
$lastUpdateCheckTimestamp = (int)$this->config->getAppValue('core', 'lastupdatedat');
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);

$channels = [
Expand Down
10 changes: 5 additions & 5 deletions apps/user_ldap/lib/Jobs/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public function __construct(Manager $userManager, ITimeFactory $time) {
parent::__construct($time);
$this->userManager = $userManager;
$this->setInterval(
\OC::$server->getConfig()->getAppValue(
(int)\OC::$server->getConfig()->getAppValue(
'user_ldap',
'background_sync_interval',
self::MIN_INTERVAL
(string)self::MIN_INTERVAL
)
);
}
Expand All @@ -97,7 +97,7 @@ public function updateInterval() {
$interval = floor(24 * 60 * 60 / $runsPerDay);
$interval = min(max($interval, self::MIN_INTERVAL), self::MAX_INTERVAL);

$this->config->setAppValue('user_ldap', 'background_sync_interval', $interval);
$this->config->setAppValue('user_ldap', 'background_sync_interval', (string)$interval);
}

/**
Expand Down Expand Up @@ -198,7 +198,7 @@ public function getCycle() {

$cycleData = [
'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', null),
'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', 0),
'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', '0'),
];

if (
Expand Down Expand Up @@ -255,7 +255,7 @@ public function determineNextCycle(array $cycleData = null) {
* @return bool
*/
public function qualifiesToRun($cycleData) {
$lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0);
$lastChange = (int)$this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', '0');
if ((time() - $lastChange) > 60 * 30) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/lib/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function getHomePath($valueFromLDAP = null) {
}

if (!is_null($attr)
&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', 'true')
) {
// a naming rule attribute is defined, but it doesn't exist for that LDAP user
throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
Expand Down Expand Up @@ -355,7 +355,7 @@ public function getAvatarImage() {
*/
public function markLogin() {
$this->config->setUserValue(
$this->uid, 'user_ldap', self::USER_PREFKEY_FIRSTLOGIN, 1);
$this->uid, 'user_ldap', self::USER_PREFKEY_FIRSTLOGIN, '1');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Authentication/TwoFactorAuth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function verifyChallenge(string $providerId, IUser $user, string $challen
$sessionId = $this->session->getId();
$token = $this->tokenProvider->getToken($sessionId);
$tokenId = $token->getId();
$this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId);
$this->config->deleteUserValue($user->getUID(), 'login_token_2fa', (string)$tokenId);

$dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
$this->legacyDispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent);
Expand Down Expand Up @@ -395,7 +395,7 @@ public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) {

$id = $this->session->getId();
$token = $this->tokenProvider->getToken($id);
$this->config->setUserValue($user->getUID(), 'login_token_2fa', (string) $token->getId(), $this->timeFactory->getTime());
$this->config->setUserValue($user->getUID(), 'login_token_2fa', (string) $token->getId(), (string)$this->timeFactory->getTime());
}

public function clearTwoFactorPending(string $userId) {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ public function install($options) {

if (empty($error)) {
$config = \OC::$server->getConfig();
$config->setAppValue('core', 'installedat', microtime(true));
$config->setAppValue('core', 'lastupdatedat', microtime(true));
$config->setAppValue('core', 'installedat', (string)microtime(true));
$config->setAppValue('core', 'lastupdatedat', (string)microtime(true));

$vendorData = $this->getVendorData();
$config->setAppValue('core', 'vendor', $vendorData['vendor']);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ protected function validateExpirationDateLink(IShare $share) {
$expirationDate = new \DateTime();
$expirationDate->setTime(0, 0, 0);

$days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', $this->shareApiLinkDefaultExpireDays());
$days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$this->shareApiLinkDefaultExpireDays());
if ($days > $this->shareApiLinkDefaultExpireDays()) {
$days = $this->shareApiLinkDefaultExpireDays();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Updater/VersionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public function check() {

$updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.nextcloud.com/updater_server/');

$this->config->setAppValue('core', 'lastupdatedat', time());
$this->config->setAppValue('core', 'lastupdatedat', (string)time());

if ($this->config->getAppValue('core', 'installedat', '') === '') {
$this->config->setAppValue('core', 'installedat', microtime(true));
$this->config->setAppValue('core', 'installedat', (string)microtime(true));
}

$version = Util::getVersion();
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ public function testValidateExpirationDateEnforceButNotSetNewShare() {
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'link_defaultExpDays', 3, '3'],
['core', 'link_defaultExpDays', '3', '3'],
]);

$expected = new \DateTime();
Expand All @@ -1306,7 +1306,7 @@ public function testValidateExpirationDateEnforceRelaxedDefaultButNotSetNewShare
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'link_defaultExpDays', 3, '1'],
['core', 'link_defaultExpDays', '3', '1'],
]);

$expected = new \DateTime();
Expand Down Expand Up @@ -1416,7 +1416,7 @@ public function testValidateExpirationDateNoDateDefault() {
->willReturnMap([
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
['core', 'link_defaultExpDays', 3, '3'],
['core', 'link_defaultExpDays', '3', '3'],
]);

$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
Expand Down Expand Up @@ -1445,7 +1445,7 @@ public function testValidateExpirationDateDefault() {
->willReturnMap([
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
['core', 'link_defaultExpDays', 3, '1'],
['core', 'link_defaultExpDays', '3', '1'],
]);

$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
Expand Down
20 changes: 10 additions & 10 deletions tests/lib/Updater/VersionCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testCheckWithoutUpdateUrl() {
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls(
0,
'0',
'installedat',
'installedat',
'lastupdatedat'
Expand All @@ -125,7 +125,7 @@ public function testCheckWithoutUpdateUrl() {
->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['core', 'lastupdatedat', $this->isType('integer')],
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', json_encode($expectedResult)]
);

Expand Down Expand Up @@ -163,7 +163,7 @@ public function testCheckWithInvalidXml() {
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls(
0,
'0',
'installedat',
'installedat',
'lastupdatedat'
Expand All @@ -177,7 +177,7 @@ public function testCheckWithInvalidXml() {
->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['core', 'lastupdatedat', $this->isType('integer')],
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', '[]']
);

Expand Down Expand Up @@ -217,7 +217,7 @@ public function testCheckWithEmptyValidXmlResponse() {
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls(
0,
'0',
'installedat',
'installedat',
'lastupdatedat'
Expand All @@ -231,7 +231,7 @@ public function testCheckWithEmptyValidXmlResponse() {
->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['core', 'lastupdatedat', $this->isType('integer')],
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', $this->isType('string')]
);

Expand Down Expand Up @@ -270,7 +270,7 @@ public function testCheckWithEmptyInvalidXmlResponse() {
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls(
0,
'0',
'installedat',
'installedat',
'lastupdatedat'
Expand All @@ -284,7 +284,7 @@ public function testCheckWithEmptyInvalidXmlResponse() {
->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['core', 'lastupdatedat', $this->isType('integer')],
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', json_encode($expectedResult)]
);

Expand Down Expand Up @@ -324,7 +324,7 @@ public function testCheckWithMissingAttributeXmlResponse() {
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls(
0,
'0',
'installedat',
'installedat',
'lastupdatedat'
Expand All @@ -338,7 +338,7 @@ public function testCheckWithMissingAttributeXmlResponse() {
->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['core', 'lastupdatedat', $this->isType('integer')],
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', $this->isType('string')]
);

Expand Down

0 comments on commit 88ab6d4

Please sign in to comment.