-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use multiple authors instead of mainAuthor
- Loading branch information
1 parent
0897f57
commit d2d0d01
Showing
26 changed files
with
1,066 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Repository\BookRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
#[AsCommand( | ||
name: 'app:move-main-author', | ||
description: 'Add a short description for your command', | ||
)] | ||
class MoveMainAuthorCommand extends Command | ||
{ | ||
public function __construct(private EntityManagerInterface $entityManager, private BookRepository $bookRepository) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$books = $this->bookRepository->findAll(); | ||
foreach ($books as $book) { | ||
$book->addAuthor($book->getMainAuthor()); | ||
} | ||
|
||
$this->entityManager->flush(); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Entity\Book; | ||
use App\Repository\BookRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
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; | ||
|
||
#[AsCommand( | ||
name: 'app:rename-author', | ||
description: 'Add a short description for your command', | ||
)] | ||
class RenameAuthorCommand extends Command | ||
{ | ||
public function __construct(private EntityManagerInterface $entityManager, private BookRepository $bookRepository) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->addArgument('author', InputArgument::REQUIRED, 'Author to rename') | ||
->addArgument('newname', InputArgument::REQUIRED, 'new name') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
$toRename = $input->getArgument('author'); | ||
$newName = $input->getArgument('newname'); | ||
|
||
if (!is_string($toRename) || !is_string($newName)) { | ||
throw new \Exception('Arguments must be strings'); | ||
} | ||
|
||
/** @var Book[] $books */ | ||
$books = $this->bookRepository->getByAuthorQuery($toRename)->getResult(); | ||
|
||
foreach ($books as $book) { | ||
$io->writeln('Renaming '.$toRename.' to '.$newName.' in '.$book->getTitle()); | ||
|
||
$book->removeAuthor($toRename); | ||
if ($newName !== '') { | ||
$book->addAuthor($newName); | ||
} | ||
} | ||
|
||
$this->entityManager->flush(); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Entity\Book; | ||
use App\Repository\BookRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
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 Symfony\Component\String\Slugger\SluggerInterface; | ||
|
||
#[AsCommand( | ||
name: 'app:rename-serie', | ||
description: 'Add a short description for your command', | ||
)] | ||
class RenameSerieCommand extends Command | ||
{ | ||
public function __construct(private EntityManagerInterface $entityManager, private BookRepository $bookRepository, private SluggerInterface $slugger) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->addArgument('serie', InputArgument::REQUIRED, 'Serie to rename') | ||
->addArgument('newname', InputArgument::REQUIRED, 'new name') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
$toRename = $input->getArgument('serie'); | ||
$newName = $input->getArgument('newname'); | ||
|
||
if (!is_string($toRename) || !is_string($newName)) { | ||
throw new \Exception('Arguments must be strings'); | ||
} | ||
/** @var Book[] $books */ | ||
$books = $this->bookRepository->getBySerieQuery($this->slugger->slug($toRename))->getResult(); | ||
|
||
foreach ($books as $book) { | ||
$io->writeln('Renaming '.$toRename.' to '.$newName.' in '.$book->getTitle()); | ||
$book->setSerie($newName); | ||
} | ||
|
||
$this->entityManager->flush(); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.