diff options
-rw-r--r-- | apps/theming/appinfo/info.xml | 16 | ||||
-rw-r--r-- | core/Command/Db/ConvertType.php | 20 | ||||
-rw-r--r-- | lib/private/App/AppStore/Fetcher/Fetcher.php | 3 | ||||
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 53 | ||||
-rw-r--r-- | lib/private/DB/Adapter.php | 24 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 131 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 2 |
7 files changed, 120 insertions, 129 deletions
diff --git a/apps/theming/appinfo/info.xml b/apps/theming/appinfo/info.xml index 7b42d063161..2eac0fd5058 100644 --- a/apps/theming/appinfo/info.xml +++ b/apps/theming/appinfo/info.xml @@ -9,7 +9,7 @@ <name>Theming</name> <summary>Adjust the Nextcloud theme</summary> <description>Adjust the Nextcloud theme</description> - <version>2.6.0</version> + <version>2.6.1</version> <licence>agpl</licence> <author>Nextcloud</author> <namespace>Theming</namespace> @@ -24,13 +24,6 @@ <nextcloud min-version="31" max-version="31"/> </dependencies> - <settings> - <admin>OCA\Theming\Settings\Admin</admin> - <admin-section>OCA\Theming\Settings\AdminSection</admin-section> - <personal>OCA\Theming\Settings\Personal</personal> - <personal-section>OCA\Theming\Settings\PersonalSection</personal-section> - </settings> - <repair-steps> <post-migration> <step>OCA\Theming\Migration\InitBackgroundImagesMigration</step> @@ -40,4 +33,11 @@ <commands> <command>OCA\Theming\Command\UpdateConfig</command> </commands> + + <settings> + <admin>OCA\Theming\Settings\Admin</admin> + <admin-section>OCA\Theming\Settings\AdminSection</admin-section> + <personal>OCA\Theming\Settings\Personal</personal> + <personal-section>OCA\Theming\Settings\PersonalSection</personal-section> + </settings> </info> diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php index 592285a8309..031d5a83d12 100644 --- a/core/Command/Db/ConvertType.php +++ b/core/Command/Db/ConvertType.php @@ -142,10 +142,13 @@ class ConvertType extends Command implements CompletionAwareInterface { if ($input->isInteractive()) { /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); - $question = new Question('What is the database password?'); + $question = new Question('What is the database password (press <enter> for none)? '); $question->setHidden(true); $question->setHiddenFallback(false); $password = $helper->ask($input, $output, $question); + if ($password === null) { + $password = ''; // possibly unnecessary + } $input->setOption('password', $password); return; } @@ -233,9 +236,24 @@ class ConvertType extends Command implements CompletionAwareInterface { 'password' => $input->getOption('password'), 'dbname' => $input->getArgument('database'), ]); + + // parse port if ($input->getOption('port')) { $connectionParams['port'] = $input->getOption('port'); } + + // parse hostname for unix socket + if (preg_match('/^(.+)(:(\d+|[^:]+))?$/', $input->getOption('hostname'), $matches)) { + $connectionParams['host'] = $matches[1]; + if (isset($matches[3])) { + if (is_numeric($matches[3])) { + $connectionParams['port'] = $matches[3]; + } else { + $connectionParams['unix_socket'] = $matches[3]; + } + } + } + return $this->connectionFactory->getConnection($type, $connectionParams); } diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index ad76befc5fa..28252f264c3 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -86,7 +86,8 @@ abstract class Fetcher { $response = $client->get($this->getEndpoint(), $options); } catch (ConnectException $e) { $this->config->setAppValue('settings', 'appstore-fetcher-lastFailure', (string)time()); - throw $e; + $this->logger->error('Failed to connect to the app store', ['exception' => $e]); + return []; } $responseJson = []; diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index 77fa418cab8..5059199a182 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -24,27 +24,20 @@ use function md5; use function strlen; class JobList implements IJobList { - protected IDBConnection $connection; - protected IConfig $config; - protected ITimeFactory $timeFactory; - protected LoggerInterface $logger; - - public function __construct(IDBConnection $connection, IConfig $config, ITimeFactory $timeFactory, LoggerInterface $logger) { - $this->connection = $connection; - $this->config = $config; - $this->timeFactory = $timeFactory; - $this->logger = $logger; + public function __construct( + protected IDBConnection $connection, + protected IConfig $config, + protected ITimeFactory $timeFactory, + protected LoggerInterface $logger + ) { } public function add($job, $argument = null, ?int $firstCheck = null): void { if ($firstCheck === null) { $firstCheck = $this->timeFactory->getTime(); } - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + + $class = ($job instanceof IJob) ? get_class($job) : $job; $argumentJson = json_encode($argument); if (strlen($argumentJson) > 4000) { @@ -81,11 +74,7 @@ class JobList implements IJobList { * @param mixed $argument */ public function remove($job, $argument = null): void { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + $class = ($job instanceof IJob) ? get_class($job) : $job; $query = $this->connection->getQueryBuilder(); $query->delete('jobs') @@ -104,11 +93,11 @@ class JobList implements IJobList { $query->setMaxResults($max); do { - $deleted = $query->execute(); + $deleted = $query->executeStatement(); } while ($deleted === $max); } else { // Dont use chunked delete - let the DB handle the large row count natively - $query->execute(); + $query->executeStatement(); } } @@ -126,11 +115,7 @@ class JobList implements IJobList { * @param mixed $argument */ public function has($job, $argument): bool { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + $class = ($job instanceof IJob) ? get_class($job) : $job; $argument = json_encode($argument); $query = $this->connection->getQueryBuilder(); @@ -149,11 +134,9 @@ class JobList implements IJobList { public function getJobs($job, ?int $limit, int $offset): array { $iterable = $this->getJobsIterator($job, $limit, $offset); - if (is_array($iterable)) { - return $iterable; - } else { - return iterator_to_array($iterable); - } + return (is_array($iterable)) + ? $iterable + : iterator_to_array($iterable); } /** @@ -168,11 +151,7 @@ class JobList implements IJobList { ->setFirstResult($offset); if ($job !== null) { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + $class = ($job instanceof IJob) ? get_class($job) : $job; $query->where($query->expr()->eq('class', $query->createNamedParameter($class))); } diff --git a/lib/private/DB/Adapter.php b/lib/private/DB/Adapter.php index ccbda897bb3..71824bda9e8 100644 --- a/lib/private/DB/Adapter.php +++ b/lib/private/DB/Adapter.php @@ -46,11 +46,10 @@ class Adapter { /** * Create an exclusive read+write lock on a table * - * @param string $tableName * @throws Exception * @since 9.1.0 */ - public function lockTable($tableName) { + public function lockTable(string $tableName) { $this->conn->beginTransaction(); $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); } @@ -80,12 +79,14 @@ class Adapter { * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 */ public function insertIfNotExist($table, $input, ?array $compare = null) { - if (empty($compare)) { - $compare = array_keys($input); - } - $query = 'INSERT INTO `' .$table . '` (`' - . implode('`,`', array_keys($input)) . '`) SELECT ' - . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? + $compare = $compare ?: array_keys($input); + + // Prepare column names and generate placeholders + $columns = '`' . implode('`,`', array_keys($input)) . '`'; + $placeholders = implode(', ', array_fill(0, count($input), '?')); + + $query = 'INSERT INTO `' . $table . '` (' . $columns . ') ' + . 'SELECT ' . $placeholders . ' ' . 'FROM `' . $table . '` WHERE '; $inserts = array_values($input); @@ -104,10 +105,9 @@ class Adapter { try { return $this->conn->executeUpdate($query, $inserts); } catch (UniqueConstraintViolationException $e) { - // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it - // it's fine to ignore this then - // - // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 + // This exception indicates a concurrent insert happened between + // the insert and the sub-select in the insert, which is safe to ignore. + // More details: https://github.com/nextcloud/server/pull/12315 return 0; } } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 3e085e08d7d..391b77171a9 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -103,7 +103,7 @@ class Manager implements IManager { if ($password === null) { // No password is set, check if this is allowed. if ($this->shareApiLinkEnforcePassword()) { - throw new \InvalidArgumentException('Passwords are enforced for link and mail shares'); + throw new \InvalidArgumentException($this->l->t('Passwords are enforced for link and mail shares')); } return; @@ -130,63 +130,63 @@ class Manager implements IManager { if ($share->getShareType() === IShare::TYPE_USER) { // We expect a valid user as sharedWith for user shares if (!$this->userManager->userExists($share->getSharedWith())) { - throw new \InvalidArgumentException('SharedWith is not a valid user'); + throw new \InvalidArgumentException($this->l->t('SharedWith is not a valid user')); } } elseif ($share->getShareType() === IShare::TYPE_GROUP) { // We expect a valid group as sharedWith for group shares if (!$this->groupManager->groupExists($share->getSharedWith())) { - throw new \InvalidArgumentException('SharedWith is not a valid group'); + throw new \InvalidArgumentException($this->l->t('SharedWith is not a valid group')); } } elseif ($share->getShareType() === IShare::TYPE_LINK) { // No check for TYPE_EMAIL here as we have a recipient for them if ($share->getSharedWith() !== null) { - throw new \InvalidArgumentException('SharedWith should be empty'); + throw new \InvalidArgumentException($this->l->t('SharedWith should be empty')); } } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { if ($share->getSharedWith() === null) { - throw new \InvalidArgumentException('SharedWith should not be empty'); + throw new \InvalidArgumentException($this->l->t('SharedWith should not be empty')); } } elseif ($share->getShareType() === IShare::TYPE_REMOTE) { if ($share->getSharedWith() === null) { - throw new \InvalidArgumentException('SharedWith should not be empty'); + throw new \InvalidArgumentException($this->l->t('SharedWith should not be empty')); } } elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) { if ($share->getSharedWith() === null) { - throw new \InvalidArgumentException('SharedWith should not be empty'); + throw new \InvalidArgumentException($this->l->t('SharedWith should not be empty')); } } elseif ($share->getShareType() === IShare::TYPE_CIRCLE) { $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); if ($circle === null) { - throw new \InvalidArgumentException('SharedWith is not a valid circle'); + throw new \InvalidArgumentException($this->l->t('SharedWith is not a valid circle')); } } elseif ($share->getShareType() === IShare::TYPE_ROOM) { } elseif ($share->getShareType() === IShare::TYPE_DECK) { } elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) { } else { // We cannot handle other types yet - throw new \InvalidArgumentException('unknown share type'); + throw new \InvalidArgumentException($this->l->t('Unknown share type')); } // Verify the initiator of the share is set if ($share->getSharedBy() === null) { - throw new \InvalidArgumentException('SharedBy should be set'); + throw new \InvalidArgumentException($this->l->t('SharedBy should be set')); } // Cannot share with yourself if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() === $share->getSharedBy()) { - throw new \InvalidArgumentException('Cannot share with yourself'); + throw new \InvalidArgumentException($this->l->t('Cannot share with yourself')); } // The path should be set if ($share->getNode() === null) { - throw new \InvalidArgumentException('Path should be set'); + throw new \InvalidArgumentException($this->l->t('Path should be set')); } // And it should be a file or a folder if (!($share->getNode() instanceof \OCP\Files\File) && !($share->getNode() instanceof \OCP\Files\Folder)) { - throw new \InvalidArgumentException('Path should be either a file or a folder'); + throw new \InvalidArgumentException($this->l->t('Path should be either a file or a folder')); } // And you cannot share your rootfolder @@ -196,18 +196,17 @@ class Manager implements IManager { $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); } if ($userFolder->getId() === $share->getNode()->getId()) { - throw new \InvalidArgumentException('You cannot share your root folder'); + throw new \InvalidArgumentException($this->l->t('You cannot share your root folder')); } // Check if we actually have share permissions if (!$share->getNode()->isShareable()) { - $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getName()]); - throw new GenericShareException($message_t, $message_t, 404); + throw new GenericShareException($this->l->t('You are not allowed to share %s', [$share->getNode()->getName()]), code: 404); } // Permissions should be set if ($share->getPermissions() === null) { - throw new \InvalidArgumentException('A share requires permissions'); + throw new \InvalidArgumentException($this->l->t('A share requires permissions')); } $permissions = 0; @@ -225,8 +224,7 @@ class Manager implements IManager { // Check that we do not share with more permissions than we have if ($share->getPermissions() & ~$permissions) { $path = $userFolder->getRelativePath($share->getNode()->getPath()); - $message_t = $this->l->t('Cannot increase permissions of %s', [$path]); - throw new GenericShareException($message_t, $message_t, 404); + throw new GenericShareException($this->l->t('Cannot increase permissions of %s', [$path]), code: 404); } @@ -236,17 +234,15 @@ class Manager implements IManager { || $share->getShareType() === IShare::TYPE_EMAIL; if (!$noReadPermissionRequired && ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { - throw new \InvalidArgumentException('Shares need at least read permissions'); + throw new \InvalidArgumentException($this->l->t('Shares need at least read permissions')); } if ($share->getNode() instanceof \OCP\Files\File) { if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { - $message_t = $this->l->t('Files cannot be shared with delete permissions'); - throw new GenericShareException($message_t); + throw new GenericShareException($this->l->t('Files cannot be shared with delete permissions')); } if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { - $message_t = $this->l->t('Files cannot be shared with create permissions'); - throw new GenericShareException($message_t); + throw new GenericShareException($this->l->t('Files cannot be shared with create permissions')); } } } @@ -287,8 +283,7 @@ class Manager implements IManager { $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); $date->setTime(0, 0, 0); if ($date >= $expirationDate) { - $message = $this->l->t('Expiration date is in the past'); - throw new GenericShareException($message, $message, 404); + throw new GenericShareException($this->l->t('Expiration date is in the past'), code: 404); } } @@ -313,15 +308,14 @@ class Manager implements IManager { // If we enforce the expiration date check that is does not exceed if ($isEnforced) { if (empty($expirationDate)) { - throw new \InvalidArgumentException('Expiration date is enforced'); + throw new \InvalidArgumentException($this->l->t('Expiration date is enforced')); } $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); $date->setTime(0, 0, 0); $date->add(new \DateInterval('P' . $defaultExpireDays . 'D')); if ($date < $expirationDate) { - $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays); - throw new GenericShareException($message, $message, 404); + throw new GenericShareException($this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays), code: 404); } } } @@ -367,8 +361,7 @@ class Manager implements IManager { $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); $date->setTime(0, 0, 0); if ($date >= $expirationDate) { - $message = $this->l->t('Expiration date is in the past'); - throw new GenericShareException($message, $message, 404); + throw new GenericShareException($this->l->t('Expiration date is in the past'), code: 404); } } @@ -394,15 +387,17 @@ class Manager implements IManager { // If we enforce the expiration date check that is does not exceed if ($isEnforced) { if (empty($expirationDate)) { - throw new \InvalidArgumentException('Expiration date is enforced'); + throw new \InvalidArgumentException($this->l->t('Expiration date is enforced')); } $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); $date->setTime(0, 0, 0); $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); if ($date < $expirationDate) { - $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays()); - throw new GenericShareException($message, $message, 404); + throw new GenericShareException( + $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays()), + code: 404, + ); } } @@ -448,8 +443,7 @@ class Manager implements IManager { $groups = array_diff($groups, $excludedGroups); if (empty($groups)) { - $message_t = $this->l->t('Sharing is only allowed with group members'); - throw new \Exception($message_t); + throw new \Exception($this->l->t('Sharing is only allowed with group members')); } } @@ -472,8 +466,7 @@ class Manager implements IManager { // Identical share already exists if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { - $message = $this->l->t('Sharing %s failed, because this item is already shared with the account %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]); - throw new AlreadySharedException($message, $existingShare); + throw new AlreadySharedException($this->l->t('Sharing %s failed, because this item is already shared with the account %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]), $existingShare); } // The share is already shared with this user via a group share @@ -483,8 +476,7 @@ class Manager implements IManager { $user = $this->userManager->get($share->getSharedWith()); if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { - $message = $this->l->t('Sharing %s failed, because this item is already shared with the account %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]); - throw new AlreadySharedException($message, $existingShare); + throw new AlreadySharedException($this->l->t('Sharing %s failed, because this item is already shared with the account %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]), $existingShare); } } } @@ -500,7 +492,7 @@ class Manager implements IManager { protected function groupCreateChecks(IShare $share) { // Verify group shares are allowed if (!$this->allowGroupSharing()) { - throw new \Exception('Group sharing is now allowed'); + throw new \Exception($this->l->t('Group sharing is now allowed')); } // Verify if the user can share with this group @@ -511,7 +503,7 @@ class Manager implements IManager { // optional excluded groups $excludedGroups = $this->shareWithGroupMembersOnlyExcludeGroupsList(); if (is_null($sharedWith) || in_array($share->getSharedWith(), $excludedGroups) || !$sharedWith->inGroup($sharedBy)) { - throw new \Exception('Sharing is only allowed within your own groups'); + throw new \Exception($this->l->t('Sharing is only allowed within your own groups')); } } @@ -532,7 +524,7 @@ class Manager implements IManager { } if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { - throw new AlreadySharedException('Path is already shared with this group', $existingShare); + throw new AlreadySharedException($this->l->t('Path is already shared with this group'), $existingShare); } } } @@ -546,13 +538,13 @@ class Manager implements IManager { protected function linkCreateChecks(IShare $share) { // Are link shares allowed? if (!$this->shareApiAllowLinks()) { - throw new \Exception('Link sharing is not allowed'); + throw new \Exception($this->l->t('Link sharing is not allowed')); } // Check if public upload is allowed if ($share->getNodeType() === 'folder' && !$this->shareApiLinkAllowPublicUpload() && ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { - throw new \InvalidArgumentException('Public upload is not allowed'); + throw new \InvalidArgumentException($this->l->t('Public upload is not allowed')); } } @@ -587,7 +579,7 @@ class Manager implements IManager { $mounts = $this->mountManager->findIn($path->getPath()); foreach ($mounts as $mount) { if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { - throw new \InvalidArgumentException('Path contains files shared with you'); + throw new \InvalidArgumentException($this->l->t('Path contains files shared with you')); } } } @@ -601,11 +593,11 @@ class Manager implements IManager { */ protected function canShare(IShare $share) { if (!$this->shareApiEnabled()) { - throw new \Exception('Sharing is disabled'); + throw new \Exception($this->l->t('Sharing is disabled')); } if ($this->sharingDisabledForUser($share->getSharedBy())) { - throw new \Exception('Sharing is disabled for you'); + throw new \Exception($this->l->t('Sharing is disabled for you')); } } @@ -689,7 +681,7 @@ class Manager implements IManager { // Cannot share with the owner if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() === $share->getShareOwner()) { - throw new \InvalidArgumentException('Cannot share with the share owner'); + throw new \InvalidArgumentException($this->l->t('Cannot share with the share owner')); } // Generate the target @@ -724,7 +716,8 @@ class Manager implements IManager { $share->setTarget($target); } } catch (AlreadySharedException $e) { - // if a share for the same target already exists, dont create a new one, but do trigger the hooks and notifications again + // If a share for the same target already exists, dont create a new one, + // but do trigger the hooks and notifications again $oldShare = $share; // Reuse the node we already have @@ -769,24 +762,24 @@ class Manager implements IManager { try { $originalShare = $this->getShareById($share->getFullId()); } catch (\UnexpectedValueException $e) { - throw new \InvalidArgumentException('Share does not have a full id'); + throw new \InvalidArgumentException($this->l->t('Share does not have a full id')); } // We cannot change the share type! if ($share->getShareType() !== $originalShare->getShareType()) { - throw new \InvalidArgumentException('Cannot change share type'); + throw new \InvalidArgumentException($this->l->t('Cannot change share type')); } // We can only change the recipient on user shares if ($share->getSharedWith() !== $originalShare->getSharedWith() && $share->getShareType() !== IShare::TYPE_USER) { - throw new \InvalidArgumentException('Can only update recipient on user shares'); + throw new \InvalidArgumentException($this->l->t('Can only update recipient on user shares')); } // Cannot share with the owner if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() === $share->getShareOwner()) { - throw new \InvalidArgumentException('Cannot share with the share owner'); + throw new \InvalidArgumentException($this->l->t('Cannot share with the share owner')); } $this->generalCreateChecks($share, true); @@ -795,7 +788,7 @@ class Manager implements IManager { $this->userCreateChecks($share); if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { - //Verify the expiration date + // Verify the expiration date $this->validateExpirationDateInternal($share); $expirationDateUpdated = true; } @@ -803,7 +796,7 @@ class Manager implements IManager { $this->groupCreateChecks($share); if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { - //Verify the expiration date + // Verify the expiration date $this->validateExpirationDateInternal($share); $expirationDateUpdated = true; } @@ -821,7 +814,7 @@ class Manager implements IManager { * Cannot enable the getSendPasswordByTalk if there is no password set */ if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) { - throw new \InvalidArgumentException('Cannot enable sending the password by Talk with an empty password'); + throw new \InvalidArgumentException($this->l->t('Cannot enable sending the password by Talk with an empty password')); } /** @@ -831,10 +824,10 @@ class Manager implements IManager { */ if (!$updatedPassword && $share->getShareType() === IShare::TYPE_EMAIL) { if (!$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { - throw new \InvalidArgumentException('Cannot enable sending the password by Talk without setting a new password'); + throw new \InvalidArgumentException($this->l->t('Cannot enable sending the password by Talk without setting a new password')); } if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) { - throw new \InvalidArgumentException('Cannot disable sending the password by Talk without setting a new password'); + throw new \InvalidArgumentException($this->l->t('Cannot disable sending the password by Talk without setting a new password')); } } @@ -845,7 +838,7 @@ class Manager implements IManager { } } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { - //Verify the expiration date + // Verify the expiration date $this->validateExpirationDateInternal($share); $expirationDateUpdated = true; } @@ -915,7 +908,7 @@ class Manager implements IManager { $provider = $this->factory->getProvider($providerId); if (!($provider instanceof IShareProviderSupportsAccept)) { - throw new \InvalidArgumentException('Share provider does not support accepting'); + throw new \InvalidArgumentException($this->l->t('Share provider does not support accepting')); } /** @var IShareProvider&IShareProviderSupportsAccept $provider */ $provider->acceptShare($share, $recipientId); @@ -944,7 +937,7 @@ class Manager implements IManager { // Password updated. if ($passwordsAreDifferent) { - //Verify the password + // Verify the password $this->verifyPassword($share->getPassword()); // If a password is set. Hash it! @@ -1028,7 +1021,7 @@ class Manager implements IManager { try { $share->getFullId(); } catch (\UnexpectedValueException $e) { - throw new \InvalidArgumentException('Share does not have a full id'); + throw new \InvalidArgumentException($this->l->t('Share does not have a full id')); } $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($share)); @@ -1075,21 +1068,21 @@ class Manager implements IManager { public function moveShare(IShare $share, $recipientId) { if ($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL) { - throw new \InvalidArgumentException('Cannot change target of link share'); + throw new \InvalidArgumentException($this->l->t('Cannot change target of link share')); } if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() !== $recipientId) { - throw new \InvalidArgumentException('Invalid recipient'); + throw new \InvalidArgumentException($this->l->t('Invalid recipient')); } if ($share->getShareType() === IShare::TYPE_GROUP) { $sharedWith = $this->groupManager->get($share->getSharedWith()); if (is_null($sharedWith)) { - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); + throw new \InvalidArgumentException($this->l->t('Group "%s" does not exist', [$share->getSharedWith()])); } $recipient = $this->userManager->get($recipientId); if (!$sharedWith->inGroup($recipient)) { - throw new \InvalidArgumentException('Invalid recipient'); + throw new \InvalidArgumentException($this->l->t('Invalid recipient')); } } @@ -1125,7 +1118,7 @@ class Manager implements IManager { if ($path !== null && !($path instanceof \OCP\Files\File) && !($path instanceof \OCP\Files\Folder)) { - throw new \InvalidArgumentException('invalid path'); + throw new \InvalidArgumentException($this->l->t('Invalid path')); } try { @@ -1149,7 +1142,7 @@ class Manager implements IManager { try { $this->checkShare($share); } catch (ShareNotFound $e) { - //Ignore since this basically means the share is deleted + // Ignore since this basically means the share is deleted continue; } diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 370047a7e7c..f7b8f1458b3 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -652,7 +652,7 @@ class ManagerTest extends \Test\TestCase { [$this->createShare(null, IShare::TYPE_LINK, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith should be empty', true], [$this->createShare(null, IShare::TYPE_LINK, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith should be empty', true], [$this->createShare(null, IShare::TYPE_LINK, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith should be empty', true], - [$this->createShare(null, -1, $file, null, $user0, $user0, 31, null, null), 'unknown share type', true], + [$this->createShare(null, -1, $file, null, $user0, $user0, 31, null, null), 'Unknown share type', true], [$this->createShare(null, IShare::TYPE_USER, $file, $user2, null, $user0, 31, null, null), 'SharedBy should be set', true], [$this->createShare(null, IShare::TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'SharedBy should be set', true], |