This commit is contained in:
Jeremy Benoist 2024-08-14 16:39:36 +02:00
parent bf329d34d8
commit c6a69e595c
No known key found for this signature in database
GPG key ID: 7168D5DD29F38552
23 changed files with 57 additions and 57 deletions

View file

@ -65,7 +65,7 @@ class CleanDownloadedImagesCommand extends Command
$existingPaths[] = $file->getFilename(); $existingPaths[] = $file->getFilename();
} }
$io->text(sprintf(' -> <info>%d</info> images found', \count($existingPaths))); $io->text(\sprintf(' -> <info>%d</info> images found', \count($existingPaths)));
$io->text('Retrieve valid folders attached to a user'); $io->text('Retrieve valid folders attached to a user');
@ -84,7 +84,7 @@ class CleanDownloadedImagesCommand extends Command
$validPaths[] = explode('/', $path)[2]; $validPaths[] = explode('/', $path)[2];
} }
$io->text(sprintf(' -> <info>%d</info> folders found', \count($validPaths))); $io->text(\sprintf(' -> <info>%d</info> folders found', \count($validPaths)));
$deletedCount = 0; $deletedCount = 0;
@ -103,11 +103,11 @@ class CleanDownloadedImagesCommand extends Command
$deletedCount += \count($files); $deletedCount += \count($files);
$io->text(sprintf('Deleted images in <info>%s</info>: <info>%d</info>', $existingPath, \count($files))); $io->text(\sprintf('Deleted images in <info>%s</info>: <info>%d</info>', $existingPath, \count($files)));
} }
} }
$io->success(sprintf('Finished cleaning. %d deleted images', $deletedCount)); $io->success(\sprintf('Finished cleaning. %d deleted images', $deletedCount));
return 0; return 0;
} }

View file

@ -56,7 +56,7 @@ class CleanDuplicatesCommand extends Command
$user = $this->getUser($username); $user = $this->getUser($username);
$this->cleanDuplicates($user); $this->cleanDuplicates($user);
} catch (NoResultException $e) { } catch (NoResultException $e) {
$this->io->error(sprintf('User "%s" not found.', $username)); $this->io->error(\sprintf('User "%s" not found.', $username));
return 1; return 1;
} }
@ -65,13 +65,13 @@ class CleanDuplicatesCommand extends Command
} else { } else {
$users = $this->userRepository->findAll(); $users = $this->userRepository->findAll();
$this->io->text(sprintf('Cleaning through <info>%d</info> user accounts', \count($users))); $this->io->text(\sprintf('Cleaning through <info>%d</info> user accounts', \count($users)));
foreach ($users as $user) { foreach ($users as $user) {
$this->io->text(sprintf('Processing user <info>%s</info>', $user->getUsername())); $this->io->text(\sprintf('Processing user <info>%s</info>', $user->getUsername()));
$this->cleanDuplicates($user); $this->cleanDuplicates($user);
} }
$this->io->success(sprintf('Finished cleaning. %d duplicates found in total', $this->duplicates)); $this->io->success(\sprintf('Finished cleaning. %d duplicates found in total', $this->duplicates));
} }
return 0; return 0;
@ -99,7 +99,7 @@ class CleanDuplicatesCommand extends Command
$this->duplicates += $duplicatesCount; $this->duplicates += $duplicatesCount;
$this->io->text(sprintf('Cleaned <info>%d</info> duplicates for user <info>%s</info>', $duplicatesCount, $user->getUserName())); $this->io->text(\sprintf('Cleaned <info>%d</info> duplicates for user <info>%s</info>', $duplicatesCount, $user->getUserName()));
} }
private function similarUrl($url) private function similarUrl($url)

View file

@ -56,7 +56,7 @@ class ExportCommand extends Command
try { try {
$user = $this->userRepository->findOneByUserName($input->getArgument('username')); $user = $this->userRepository->findOneByUserName($input->getArgument('username'));
} catch (NoResultException $e) { } catch (NoResultException $e) {
$io->error(sprintf('User "%s" not found.', $input->getArgument('username'))); $io->error(\sprintf('User "%s" not found.', $input->getArgument('username')));
return 1; return 1;
} }
@ -66,12 +66,12 @@ class ExportCommand extends Command
->getQuery() ->getQuery()
->getResult(); ->getResult();
$io->text(sprintf('Exporting <info>%d</info> entrie(s) for user <info>%s</info>...', \count($entries), $user->getUserName())); $io->text(\sprintf('Exporting <info>%d</info> entrie(s) for user <info>%s</info>...', \count($entries), $user->getUserName()));
$filePath = $input->getArgument('filepath'); $filePath = $input->getArgument('filepath');
if (!$filePath) { if (!$filePath) {
$filePath = $this->projectDir . '/' . sprintf('%s-export.json', $user->getUsername()); $filePath = $this->projectDir . '/' . \sprintf('%s-export.json', $user->getUsername());
} }
try { try {
@ -82,7 +82,7 @@ class ExportCommand extends Command
->exportJsonData(); ->exportJsonData();
file_put_contents($filePath, $data); file_put_contents($filePath, $data);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
$io->error(sprintf('Error: "%s"', $e->getMessage())); $io->error(\sprintf('Error: "%s"', $e->getMessage()));
return 1; return 1;
} }

View file

@ -50,17 +50,17 @@ class GenerateUrlHashesCommand extends Command
$user = $this->getUser($username); $user = $this->getUser($username);
$this->generateHashedUrls($user); $this->generateHashedUrls($user);
} catch (NoResultException $e) { } catch (NoResultException $e) {
$output->writeln(sprintf('<error>User "%s" not found.</error>', $username)); $output->writeln(\sprintf('<error>User "%s" not found.</error>', $username));
return 1; return 1;
} }
} else { } else {
$users = $this->userRepository->findAll(); $users = $this->userRepository->findAll();
$output->writeln(sprintf('Generating hashed urls for "%d" users', \count($users))); $output->writeln(\sprintf('Generating hashed urls for "%d" users', \count($users)));
foreach ($users as $user) { foreach ($users as $user) {
$output->writeln(sprintf('Processing user: %s', $user->getUsername())); $output->writeln(\sprintf('Processing user: %s', $user->getUsername()));
$this->generateHashedUrls($user); $this->generateHashedUrls($user);
} }
$output->writeln('Finished generated hashed urls'); $output->writeln('Finished generated hashed urls');
@ -86,7 +86,7 @@ class GenerateUrlHashesCommand extends Command
$this->entityManager->flush(); $this->entityManager->flush();
$this->output->writeln(sprintf('Generated hashed urls for user: %s', $user->getUserName())); $this->output->writeln(\sprintf('Generated hashed urls for user: %s', $user->getUserName()));
} }
/** /**

View file

@ -98,7 +98,7 @@ class ImportCommand extends Command
$output->writeln('Start : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---'); $output->writeln('Start : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---');
if (!file_exists($input->getArgument('filepath'))) { if (!file_exists($input->getArgument('filepath'))) {
throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath'))); throw new Exception(\sprintf('File "%s" not found', $input->getArgument('filepath')));
} }
// Turning off doctrine default logs queries for saving memory // Turning off doctrine default logs queries for saving memory
@ -115,7 +115,7 @@ class ImportCommand extends Command
} }
if (!\is_object($entityUser)) { if (!\is_object($entityUser)) {
throw new Exception(sprintf('User "%s" not found', $input->getArgument('username'))); throw new Exception(\sprintf('User "%s" not found', $input->getArgument('username')));
} }
// Authenticate user for paywalled websites // Authenticate user for paywalled websites

View file

@ -41,7 +41,7 @@ class RedisWorkerCommand extends Command
$serviceName = $input->getArgument('serviceName'); $serviceName = $input->getArgument('serviceName');
if (!$this->container->has('wallabag.queue.redis.' . $serviceName) || !$this->container->has('wallabag.consumer.redis.' . $serviceName)) { if (!$this->container->has('wallabag.queue.redis.' . $serviceName) || !$this->container->has('wallabag.consumer.redis.' . $serviceName)) {
throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName'))); throw new Exception(\sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
} }
$worker = new QueueWorker( $worker = new QueueWorker(

View file

@ -109,7 +109,7 @@ class InstallCommand extends Command
$help = 'Database driver "' . $this->databaseDriver . '" is not installed.'; $help = 'Database driver "' . $this->databaseDriver . '" is not installed.';
} }
$rows[] = [sprintf($label, $this->databaseDriver), $status, $help]; $rows[] = [\sprintf($label, $this->databaseDriver), $status, $help];
// testing if connection to the database can be established // testing if connection to the database can be established
$label = '<comment>Database connection</comment>'; $label = '<comment>Database connection</comment>';
@ -388,12 +388,12 @@ class InstallCommand extends Command
$schemaManager = $connection->createSchemaManager(); $schemaManager = $connection->createSchemaManager();
} catch (\Exception $exception) { } catch (\Exception $exception) {
// mysql & sqlite // mysql & sqlite
if (str_contains($exception->getMessage(), sprintf("Unknown database '%s'", $databaseName))) { if (str_contains($exception->getMessage(), \sprintf("Unknown database '%s'", $databaseName))) {
return false; return false;
} }
// pgsql // pgsql
if (str_contains($exception->getMessage(), sprintf('database "%s" does not exist', $databaseName))) { if (str_contains($exception->getMessage(), \sprintf('database "%s" does not exist', $databaseName))) {
return false; return false;
} }

View file

@ -59,7 +59,7 @@ class ListUserCommand extends Command
$io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows); $io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows);
$io->success( $io->success(
sprintf( \sprintf(
'%s/%s%s user(s) displayed.', '%s/%s%s user(s) displayed.',
\count($users), \count($users),
$nbUsers, $nbUsers,

View file

@ -63,7 +63,7 @@ class ReloadEntryCommand extends Command
->findOneByUserName($username) ->findOneByUserName($username)
->getId(); ->getId();
} catch (NoResultException $e) { } catch (NoResultException $e) {
$io->error(sprintf('User "%s" not found.', $username)); $io->error(\sprintf('User "%s" not found.', $username));
return 1; return 1;
} }
@ -80,7 +80,7 @@ class ReloadEntryCommand extends Command
} }
$io->note( $io->note(
sprintf( \sprintf(
"You're going to reload %s entries. Depending on the number of entry to reload, this could be a very long process.", "You're going to reload %s entries. Depending on the number of entry to reload, this could be a very long process.",
$nbEntries $nbEntries
) )

View file

@ -47,7 +47,7 @@ class ShowUserCommand extends Command
$user = $this->getUser($username); $user = $this->getUser($username);
$this->showUser($user); $this->showUser($user);
} catch (NoResultException $e) { } catch (NoResultException $e) {
$this->io->error(sprintf('User "%s" not found.', $username)); $this->io->error(\sprintf('User "%s" not found.', $username));
return 1; return 1;
} }
@ -58,13 +58,13 @@ class ShowUserCommand extends Command
private function showUser(User $user) private function showUser(User $user)
{ {
$this->io->listing([ $this->io->listing([
sprintf('Username: %s', $user->getUsername()), \sprintf('Username: %s', $user->getUsername()),
sprintf('Email: %s', $user->getEmail()), \sprintf('Email: %s', $user->getEmail()),
sprintf('Display name: %s', $user->getName()), \sprintf('Display name: %s', $user->getName()),
sprintf('Creation date: %s', $user->getCreatedAt()->format('Y-m-d H:i:s')), \sprintf('Creation date: %s', $user->getCreatedAt()->format('Y-m-d H:i:s')),
sprintf('Last login: %s', null !== $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'), \sprintf('Last login: %s', null !== $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'),
sprintf('2FA (email) activated: %s', $user->isEmailTwoFactor() ? 'yes' : 'no'), \sprintf('2FA (email) activated: %s', $user->isEmailTwoFactor() ? 'yes' : 'no'),
sprintf('2FA (OTP) activated: %s', $user->isGoogleAuthenticatorEnabled() ? 'yes' : 'no'), \sprintf('2FA (OTP) activated: %s', $user->isGoogleAuthenticatorEnabled() ? 'yes' : 'no'),
]); ]);
} }

View file

@ -49,12 +49,12 @@ class TagAllCommand extends Command
try { try {
$user = $this->getUser($input->getArgument('username')); $user = $this->getUser($input->getArgument('username'));
} catch (NoResultException $e) { } catch (NoResultException $e) {
$io->error(sprintf('User "%s" not found.', $input->getArgument('username'))); $io->error(\sprintf('User "%s" not found.', $input->getArgument('username')));
return 1; return 1;
} }
$io->text(sprintf('Tagging entries for user <info>%s</info>...', $user->getUserName())); $io->text(\sprintf('Tagging entries for user <info>%s</info>...', $user->getUserName()));
$entries = $this->ruleBasedTagger->tagAllForUser($user); $entries = $this->ruleBasedTagger->tagAllForUser($user);

View file

@ -1088,7 +1088,7 @@ class EntryRestController extends WallabagRestController
{ {
$expect = $request->query->get('expect', 'entry'); $expect = $request->query->get('expect', 'entry');
if (!\in_array($expect, ['id', 'entry'], true)) { if (!\in_array($expect, ['id', 'entry'], true)) {
throw new BadRequestHttpException(sprintf("expect: 'id' or 'entry' expected, %s given", $expect)); throw new BadRequestHttpException(\sprintf("expect: 'id' or 'entry' expected, %s given", $expect));
} }
$this->validateAuthentication(); $this->validateAuthentication();
$this->validateUserAccess($entry->getUser()->getId()); $this->validateUserAccess($entry->getUser()->getId());

View file

@ -657,7 +657,7 @@ class EntryController extends AbstractController
$qb = $this->entryRepository->getBuilderForAllByUser($this->getUser()->getId()); $qb = $this->entryRepository->getBuilderForAllByUser($this->getUser()->getId());
break; break;
default: default:
throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type));
} }
$form = $this->createForm(EntryFilterType::class, [], $formOptions); $form = $this->createForm(EntryFilterType::class, [], $formOptions);

View file

@ -102,7 +102,7 @@ class FeedController extends AbstractController
]; ];
if (!isset($sorts[$sort])) { if (!isset($sorts[$sort])) {
throw new BadRequestHttpException(sprintf('Sort "%s" is not available.', $sort)); throw new BadRequestHttpException(\sprintf('Sort "%s" is not available.', $sort));
} }
$url = $this->generateUrl( $url = $this->generateUrl(
@ -200,7 +200,7 @@ class FeedController extends AbstractController
$qb = $this->entryRepository->getBuilderForAllByUser($user->getId()); $qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
break; break;
default: default:
throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type));
} }
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);

View file

@ -114,7 +114,7 @@ class EntryFilterType extends AbstractType
return false; return false;
} }
$paramName = sprintf('%s', str_replace('.', '_', $field)); $paramName = \sprintf('%s', str_replace('.', '_', $field));
$expression = $filterQuery->getExpr()->eq($field, ':' . $paramName); $expression = $filterQuery->getExpr()->eq($field, ':' . $paramName);
$parameters = [$paramName => $value]; $parameters = [$paramName => $value];

View file

@ -119,7 +119,7 @@ class EntriesExport
return $this->$functionName(); return $this->$functionName();
} }
throw new \InvalidArgumentException(sprintf('The format "%s" is not yet supported.', $format)); throw new \InvalidArgumentException(\sprintf('The format "%s" is not yet supported.', $format));
} }
public function exportJsonData() public function exportJsonData()
@ -196,7 +196,7 @@ class EntriesExport
foreach ($entry->getTags() as $tag) { foreach ($entry->getTags() as $tag) {
$book->setSubject($tag->getLabel()); $book->setSubject($tag->getLabel());
} }
$filename = sha1(sprintf('%s:%s', $entry->getUrl(), $entry->getTitle())); $filename = sha1(\sprintf('%s:%s', $entry->getUrl(), $entry->getTitle()));
$publishedBy = $entry->getPublishedBy(); $publishedBy = $entry->getPublishedBy();
$authors = $this->translator->trans('export.unknown'); $authors = $this->translator->trans('export.unknown');
@ -232,8 +232,8 @@ class EntriesExport
$book->addChapter('Notices', 'Cover2.html', $content_start . $this->getExportInformation('PHPePub') . $bookEnd); $book->addChapter('Notices', 'Cover2.html', $content_start . $this->getExportInformation('PHPePub') . $bookEnd);
// Could also be the ISBN number, prefered for published books, or a UUID. // Could also be the ISBN number, prefered for published books, or a UUID.
$hash = sha1(sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds))); $hash = sha1(\sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds)));
$book->setIdentifier(sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI); $book->setIdentifier(\sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI);
return Response::create( return Response::create(
$book->getBook(), $book->getBook(),

View file

@ -60,7 +60,7 @@ class PocketImport extends AbstractImport
return $response->toArray()['code']; return $response->toArray()['code'];
} catch (ExceptionInterface $e) { } catch (ExceptionInterface $e) {
$this->logger->error(sprintf('PocketImport: Failed to request token: %s', $e->getMessage()), ['exception' => $e]); $this->logger->error(\sprintf('PocketImport: Failed to request token: %s', $e->getMessage()), ['exception' => $e]);
return false; return false;
} }
@ -88,7 +88,7 @@ class PocketImport extends AbstractImport
return true; return true;
} catch (ExceptionInterface $e) { } catch (ExceptionInterface $e) {
$this->logger->error(sprintf('PocketImport: Failed to authorize client: %s', $e->getMessage()), ['exception' => $e]); $this->logger->error(\sprintf('PocketImport: Failed to authorize client: %s', $e->getMessage()), ['exception' => $e]);
return false; return false;
} }
@ -132,7 +132,7 @@ class PocketImport extends AbstractImport
return true; return true;
} catch (ExceptionInterface $e) { } catch (ExceptionInterface $e) {
$this->logger->error(sprintf('PocketImport: Failed to import: %s', $e->getMessage()), ['exception' => $e]); $this->logger->error(\sprintf('PocketImport: Failed to import: %s', $e->getMessage()), ['exception' => $e]);
return false; return false;
} }

View file

@ -17,9 +17,9 @@ class Matches
public function __invoke($subject, $pattern) public function __invoke($subject, $pattern)
{ {
if ("'" === $pattern[0]) { if ("'" === $pattern[0]) {
$pattern = sprintf("'%%%s%%'", substr($pattern, 1, -1)); $pattern = \sprintf("'%%%s%%'", substr($pattern, 1, -1));
} }
return sprintf('UPPER(%s) LIKE UPPER(%s)', $subject, $pattern); return \sprintf('UPPER(%s) LIKE UPPER(%s)', $subject, $pattern);
} }
} }

View file

@ -17,9 +17,9 @@ class NotMatches
public function __invoke($subject, $pattern) public function __invoke($subject, $pattern)
{ {
if ("'" === $pattern[0]) { if ("'" === $pattern[0]) {
$pattern = sprintf("'%%%s%%'", substr($pattern, 1, -1)); $pattern = \sprintf("'%%%s%%'", substr($pattern, 1, -1));
} }
return sprintf('UPPER(%s) NOT LIKE UPPER(%s)', $subject, $pattern); return \sprintf('UPPER(%s) NOT LIKE UPPER(%s)', $subject, $pattern);
} }
} }

View file

@ -88,7 +88,7 @@ class UsernameFeedTokenConverter implements ParamConverterInterface
$user = $userRepository->findOneByUsernameAndFeedtoken($username, $feedToken); $user = $userRepository->findOneByUsernameAndFeedtoken($username, $feedToken);
if (null === $user || !($user instanceof User)) { if (null === $user || !($user instanceof User)) {
throw new NotFoundHttpException(sprintf('%s not found.', $configuration->getClass())); throw new NotFoundHttpException(\sprintf('%s not found.', $configuration->getClass()));
} }
// Map found user to the route's parameter // Map found user to the route's parameter

View file

@ -306,7 +306,7 @@ class EntryRepository extends ServiceEntityRepository
$fields = array_filter($fieldNames, function ($k) { $fields = array_filter($fieldNames, function ($k) {
return 'content' !== $k; return 'content' !== $k;
}); });
$qb->select(sprintf('partial e.{%s}', implode(',', $fields))); $qb->select(\sprintf('partial e.{%s}', implode(',', $fields)));
} }
if (null !== $isArchived) { if (null !== $isArchived) {
@ -780,6 +780,6 @@ class EntryRepository extends ServiceEntityRepository
*/ */
private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc') private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc')
{ {
return $qb->orderBy(sprintf('e.%s', $sortBy), $direction); return $qb->orderBy(\sprintf('e.%s', $sortBy), $direction);
} }
} }

View file

@ -111,7 +111,7 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface
$qb = $this->entryRepository->getCountBuilderForAllByUser($user->getId()); $qb = $this->entryRepository->getCountBuilderForAllByUser($user->getId());
break; break;
default: default:
throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type));
} }
$query = $qb $query = $qb

View file

@ -1709,7 +1709,7 @@ class EntryControllerTest extends WallabagTestCase
// the deletion link of the first tag // the deletion link of the first tag
$link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract(['href'])[1]; $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract(['href'])[1];
$this->assertStringStartsWith(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); $this->assertStringStartsWith(\sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
} }
public function testRandom() public function testRandom()