From 21ca1ffeadbc183e2e961da57ae4bb0802ba633a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 4 Aug 2022 21:49:16 +0200 Subject: [PATCH] Moved all console comands to the partdb: namespace --- .github/workflows/tests.yml | 2 +- README.md | 8 +-- UPGRADE.md | 4 +- config/services.yaml | 2 +- .../CleanAttachmentsCommand.php | 10 +-- .../UpdateExchangeRatesCommand.php | 9 +-- .../{ => Logs}/ShowEventLogCommand.php | 4 +- .../{ => Migrations}/ConvertBBCodeCommand.php | 7 +- src/Command/{ => User}/SetPasswordCommand.php | 5 +- src/Command/User/UserListCommand.php | 64 +++++++++++++++++++ src/Command/VersionCommand.php | 53 +++++++++++++++ 11 files changed, 145 insertions(+), 23 deletions(-) rename src/Command/{ => Attachments}/CleanAttachmentsCommand.php (97%) rename src/Command/{ => Currencies}/UpdateExchangeRatesCommand.php (96%) rename src/Command/{ => Logs}/ShowEventLogCommand.php (98%) rename src/Command/{ => Migrations}/ConvertBBCodeCommand.php (98%) rename src/Command/{ => User}/SetPasswordCommand.php (97%) create mode 100644 src/Command/User/UserListCommand.php create mode 100644 src/Command/VersionCommand.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5a37dd50..212ee37b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -120,7 +120,7 @@ jobs: env_vars: PHP_VERSION,DB_TYPE - name: Test app:clean-attachments - run: php bin/console app:clean-attachments -n + run: php bin/console partdb:attachments:clean-unused -n - name: Test app:convert-bbcode run: php bin/console app:convert-bbcode -n diff --git a/README.md b/README.md index 29a89956..779f36fc 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,11 @@ If the reverse proxy is on a different server (or it cannot access Part-DB via l ## Useful console commands Part-DB provides some command consoles which can be invoked by `php bin/console [command]`. You can get help for every command with the parameter `--help`. Useful commands are: -* `php bin/console app:set-password [username]`: Sets a new password for the user with the given username. Useful if you forget the password to your Part-DB instance. -* `php bin/console app:show-logs`: Show last activty log on console. Use `-x` options, to include extra column. -* `php bin/console app:update-exchange-rates`: Update the exchange rates of your currencies from internet. Setup this to be run in a cronjob to always get up-to-date exchange rates. +* `php bin/console partdb:users:set-password [username]`: Sets a new password for the user with the given username. Useful if you forget the password to your Part-DB instance. +* `php bin/console partdb:logs:show`: Show last activty log on console. Use `-x` options, to include extra column. +* `php bin/console partdb:currencies:update-exchange-rates`: Update the exchange rates of your currencies from internet. Setup this to be run in a cronjob to always get up-to-date exchange rates. If you dont use Euro as base currency, you have to setup an fixer.io API key in `.env.local`. -* `php bin/console app:clean-attachments`: Removes all unused files (files without an associated attachment) in attachments folder. +* `php bin/console partdb:attachments:clean-unused`: Removes all unused files (files without an associated attachment) in attachments folder. Normally Part-DB should be able to delete the attachment file, if you delete the attachment, but if you have some obsolete files left over from legacy Part-DB you can remove them safely with this command. * `php bin/console cache:clear`: Remove and rebuild all caches. If you encounter some weird issues in Part-DB, it maybe helps to run this command. * `php bin/console doctrine:migrations:up-to-date`: Check if your database is up to date. diff --git a/UPGRADE.md b/UPGRADE.md index b9c5c3a4..c498120f 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -13,7 +13,7 @@ It is tried to keep the breaking changes as small as possible, so they should no * Console access highly required. The installation of composer and frontend dependencies require console access, also the managment commands are using CLI, so you should have console access on your server. * Markdown/HTML is now used instead of BBCode for rich text in description and command fields. - It is possible to migrate your existing BBCode to Markdown via `php bin/console php bin/console app:convert-bbcode`. + It is possible to migrate your existing BBCode to Markdown via `php bin/console php bin/console partdb:migrations:convert-bbcode`. * Server exceptions are not logged to Event log anymore. For security reasons (exceptions can contain sensitive informations) exceptions are only logged to server log (by default under './var/log'), so only the server admins can access it. * Profile labels are now saved in Database (before they were saved in a seperate JSON file). The profiles of legacy Part-DB versions can not be imported into new Part-DB 1.0 @@ -25,7 +25,7 @@ It is tried to keep the breaking changes as small as possible, so they should no 2. Make a backup of your database. If somethings goes wrong during migration, you can use this backup to start over. 3. Setup the new Part-DB like described on [README](README.md) in section Installation. In `.env.local` enter the URL to your old Part-DB database. - 4. Run `php bin/console app:convert-bbcode` to convert the BBCode used in comments and part description to the newly used markdown. + 4. Run `php bin/console partdb:migrations:convert-bbcode` to convert the BBCode used in comments and part description to the newly used markdown. 5. Copy the content of `data/media` from the old Part-DB version into `public/media` in the new version. 6. Run 'php bin/console cache:clear' diff --git a/config/services.yaml b/config/services.yaml index 5f965295..9d492f15 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -142,7 +142,7 @@ services: #################################################################################################################### # Price system #################################################################################################################### - App\Command\UpdateExchangeRatesCommand: + App\Command\Currencies\UpdateExchangeRatesCommand: arguments: $base_current: '%partdb.default_currency%' diff --git a/src/Command/CleanAttachmentsCommand.php b/src/Command/Attachments/CleanAttachmentsCommand.php similarity index 97% rename from src/Command/CleanAttachmentsCommand.php rename to src/Command/Attachments/CleanAttachmentsCommand.php index e6e1403e..9c95b590 100644 --- a/src/Command/CleanAttachmentsCommand.php +++ b/src/Command/Attachments/CleanAttachmentsCommand.php @@ -40,13 +40,11 @@ declare(strict_types=1); * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -namespace App\Command; +namespace App\Command\Attachments; use App\Services\Attachments\AttachmentManager; use App\Services\Attachments\AttachmentPathResolver; use App\Services\Attachments\AttachmentReverseSearch; -use function count; -use const DIRECTORY_SEPARATOR; use IntlDateFormatter; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; @@ -57,9 +55,13 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; use Symfony\Component\Mime\MimeTypes; +use function count; + +use const DIRECTORY_SEPARATOR; + class CleanAttachmentsCommand extends Command { - protected static $defaultName = 'app:clean-attachments'; + protected static $defaultName = 'partdb:attachments:clean-unused|app:clean-attachments'; protected $attachment_helper; protected $reverseSearch; diff --git a/src/Command/UpdateExchangeRatesCommand.php b/src/Command/Currencies/UpdateExchangeRatesCommand.php similarity index 96% rename from src/Command/UpdateExchangeRatesCommand.php rename to src/Command/Currencies/UpdateExchangeRatesCommand.php index 69f9a7b5..7c86bd12 100644 --- a/src/Command/UpdateExchangeRatesCommand.php +++ b/src/Command/Currencies/UpdateExchangeRatesCommand.php @@ -40,23 +40,24 @@ declare(strict_types=1); * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -namespace App\Command; +namespace App\Command\Currencies; use App\Entity\PriceInformations\Currency; use App\Services\ExchangeRateUpdater; -use function count; use Doctrine\ORM\EntityManagerInterface; use Exchanger\Exception\Exception; -use function strlen; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use function count; +use function strlen; + class UpdateExchangeRatesCommand extends Command { - protected static $defaultName = 'app:update-exchange-rates'; + protected static $defaultName = 'partdb:currencies:update-exchange-rates|partdb:update-exchange-rates|app:update-exchange-rates'; protected $base_current; protected $em; diff --git a/src/Command/ShowEventLogCommand.php b/src/Command/Logs/ShowEventLogCommand.php similarity index 98% rename from src/Command/ShowEventLogCommand.php rename to src/Command/Logs/ShowEventLogCommand.php index 627855da..00efffaf 100644 --- a/src/Command/ShowEventLogCommand.php +++ b/src/Command/Logs/ShowEventLogCommand.php @@ -40,7 +40,7 @@ declare(strict_types=1); * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -namespace App\Command; +namespace App\Command\Logs; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\LogSystem\AbstractLogEntry; @@ -57,7 +57,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; class ShowEventLogCommand extends Command { - protected static $defaultName = 'app:show-logs'; + protected static $defaultName = 'partdb:logs:show|app:show-logs'; protected $entityManager; protected $translator; protected $elementTypeNameGenerator; diff --git a/src/Command/ConvertBBCodeCommand.php b/src/Command/Migrations/ConvertBBCodeCommand.php similarity index 98% rename from src/Command/ConvertBBCodeCommand.php rename to src/Command/Migrations/ConvertBBCodeCommand.php index 48b8bd5c..16ab7b5f 100644 --- a/src/Command/ConvertBBCodeCommand.php +++ b/src/Command/Migrations/ConvertBBCodeCommand.php @@ -40,7 +40,7 @@ declare(strict_types=1); * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -namespace App\Command; +namespace App\Command\Migrations; use App\Entity\Attachments\AttachmentType; use App\Entity\Base\AbstractNamedDBElement; @@ -54,7 +54,6 @@ use App\Entity\Parts\Supplier; use App\Entity\PriceInformations\Currency; use App\Entity\UserSystem\Group; use App\Helpers\BBCodeToMarkdownConverter; -use function count; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Symfony\Component\Console\Command\Command; @@ -63,6 +62,8 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; +use function count; + /** * This command converts the BBCode used by old Part-DB versions (<1.0), to the current used markdown format. */ @@ -77,7 +78,7 @@ class ConvertBBCodeCommand extends Command */ protected const BBCODE_REGEX = '/\\[.+\\].*\\[\\/.+\\]/'; - protected static $defaultName = 'app:convert-bbcode'; + protected static $defaultName = 'partdb:migrations:convert-bbcode|app:convert-bbcode'; protected $em; protected $propertyAccessor; diff --git a/src/Command/SetPasswordCommand.php b/src/Command/User/SetPasswordCommand.php similarity index 97% rename from src/Command/SetPasswordCommand.php rename to src/Command/User/SetPasswordCommand.php index b4d18b6d..7911e050 100644 --- a/src/Command/SetPasswordCommand.php +++ b/src/Command/User/SetPasswordCommand.php @@ -40,7 +40,7 @@ declare(strict_types=1); * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -namespace App\Command; +namespace App\Command\User; use App\Entity\UserSystem\User; use App\Events\SecurityEvent; @@ -56,7 +56,7 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; class SetPasswordCommand extends Command { - protected static $defaultName = 'app:set-password'; + protected static $defaultName = 'partdb:users:set-password|app:set-password|users:set-password'; protected $entityManager; protected $encoder; @@ -77,6 +77,7 @@ class SetPasswordCommand extends Command ->setDescription('Sets the password of a user') ->setHelp('This password allows you to set the password of a user, without knowing the old password.') ->addArgument('user', InputArgument::REQUIRED, 'The name of the user') + ; } diff --git a/src/Command/User/UserListCommand.php b/src/Command/User/UserListCommand.php new file mode 100644 index 00000000..ed8ceb53 --- /dev/null +++ b/src/Command/User/UserListCommand.php @@ -0,0 +1,64 @@ +entityManager = $entityManager; + + parent::__construct(); + } + + protected function configure(): void + { + $this + ->setDescription('Lists all users') + ->setHelp('This command lists all users in the database.') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new SymfonyStyle($input, $output); + + //Get all users from database + $users = $this->entityManager->getRepository(User::class)->findAll(); + + $io->info(sprintf("Found %d users in database.", count($users))); + + $io->title('Users:'); + + $table = new Table($output); + $table->setHeaders(['ID', 'Username', 'Name', 'Email', 'Group']); + + foreach ($users as $user) { + $table->addRow([ + $user->getId(), + $user->getUsername(), + $user->getFullName(), + $user->getEmail(), + $user->getGroup() !== null ? $user->getGroup()->getName() . ' (ID: ' . $user->getGroup()->getID() . ')' : 'No group', + ]); + } + + $table->render(); + + + return self::SUCCESS; + } + +} \ No newline at end of file diff --git a/src/Command/VersionCommand.php b/src/Command/VersionCommand.php new file mode 100644 index 00000000..1be7ea3a --- /dev/null +++ b/src/Command/VersionCommand.php @@ -0,0 +1,53 @@ +versionManager = $versionManager; + $this->gitVersionInfo = $gitVersionInfo; + parent::__construct(); + } + + protected function configure(): void + { + $this + ->setDescription('Shows the currently installed version of Part-DB.') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $message = 'Part-DB version: '. $this->versionManager->getVersion()->toString(); + + if ($this->gitVersionInfo->getGitBranchName() !== null) { + $message .= ' Git branch: '. $this->gitVersionInfo->getGitBranchName(); + $message .= ', Git commit: '. $this->gitVersionInfo->getGitCommitHash(); + } + + $io->success($message); + + $io->info('PHP version: '. phpversion()); + $io->info('Symfony version: ' . $this->getApplication()->getVersion()); + $io->info('OS: '. php_uname()); + $io->info('PHP extension: '. implode(', ', get_loaded_extensions())); + + return 0; + } +} \ No newline at end of file