Moved all console comands to the partdb: namespace

This commit is contained in:
Jan Böhmer 2022-08-04 21:49:16 +02:00
parent 92e477775a
commit 21ca1ffead
11 changed files with 145 additions and 23 deletions

View file

@ -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

View file

@ -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.

View file

@ -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'

View file

@ -142,7 +142,7 @@ services:
####################################################################################################################
# Price system
####################################################################################################################
App\Command\UpdateExchangeRatesCommand:
App\Command\Currencies\UpdateExchangeRatesCommand:
arguments:
$base_current: '%partdb.default_currency%'

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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')
;
}

View file

@ -0,0 +1,64 @@
<?php
namespace App\Command\User;
use App\Entity\UserSystem\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class UserListCommand extends Command
{
protected static $defaultName = 'partdb:users:list|users:list';
protected $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->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;
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace App\Command;
use App\Services\GitVersionInfo;
use Shivas\VersioningBundle\Service\VersionManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class VersionCommand extends Command
{
protected static $defaultName = 'partdb:version|app:version';
protected $versionManager;
protected $gitVersionInfo;
public function __construct(VersionManagerInterface $versionManager, GitVersionInfo $gitVersionInfo)
{
$this->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;
}
}