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

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