-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1959 from MTES-MCT/feature/1665-back-enregistrer-…
…les-desordres [Back] Remplir les 3 tables de désordres à partir du fichier xls
- Loading branch information
Showing
18 changed files
with
979 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20231120144804 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add relation between signalement and desordre'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE TABLE desordre_categorie_signalement | ||
(desordre_categorie_id INT NOT NULL, | ||
signalement_id INT NOT NULL, | ||
INDEX IDX_E365880CECF01477 (desordre_categorie_id), | ||
INDEX IDX_E365880C65C5E57E (signalement_id), | ||
PRIMARY KEY(desordre_categorie_id, signalement_id)) | ||
DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); | ||
|
||
$this->addSql('CREATE TABLE desordre_critere_signalement | ||
(desordre_critere_id INT NOT NULL, | ||
signalement_id INT NOT NULL, | ||
INDEX IDX_689D9BA81C3935AB (desordre_critere_id), | ||
INDEX IDX_689D9BA865C5E57E (signalement_id), | ||
PRIMARY KEY(desordre_critere_id, signalement_id)) | ||
DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); | ||
|
||
$this->addSql('CREATE TABLE desordre_precision_signalement | ||
(desordre_precision_id INT NOT NULL, | ||
signalement_id INT NOT NULL, | ||
INDEX IDX_D390215F9FB07E9C (desordre_precision_id), | ||
INDEX IDX_D390215F65C5E57E (signalement_id), | ||
PRIMARY KEY(desordre_precision_id, signalement_id)) | ||
DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); | ||
|
||
$this->addSql('ALTER TABLE desordre_categorie_signalement | ||
ADD CONSTRAINT FK_E365880CECF01477 FOREIGN KEY (desordre_categorie_id) | ||
REFERENCES desordre_categorie (id) ON DELETE CASCADE'); | ||
|
||
$this->addSql('ALTER TABLE desordre_categorie_signalement | ||
ADD CONSTRAINT FK_E365880C65C5E57E FOREIGN KEY (signalement_id) REFERENCES signalement (id) ON DELETE CASCADE'); | ||
|
||
$this->addSql('ALTER TABLE desordre_critere_signalement | ||
ADD CONSTRAINT FK_689D9BA81C3935AB FOREIGN KEY (desordre_critere_id) | ||
REFERENCES desordre_critere (id) ON DELETE CASCADE'); | ||
|
||
$this->addSql('ALTER TABLE desordre_critere_signalement | ||
ADD CONSTRAINT FK_689D9BA865C5E57E FOREIGN KEY (signalement_id) REFERENCES signalement (id) ON DELETE CASCADE'); | ||
|
||
$this->addSql('ALTER TABLE desordre_precision_signalement | ||
ADD CONSTRAINT FK_D390215F9FB07E9C FOREIGN KEY (desordre_precision_id) | ||
REFERENCES desordre_precision (id) ON DELETE CASCADE'); | ||
|
||
$this->addSql('ALTER TABLE desordre_precision_signalement | ||
ADD CONSTRAINT FK_D390215F65C5E57E FOREIGN KEY (signalement_id) REFERENCES signalement (id) ON DELETE CASCADE'); | ||
|
||
$this->addSql('ALTER TABLE desordre_categorie | ||
CHANGE created_at created_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\''); | ||
|
||
$this->addSql('ALTER TABLE desordre_critere | ||
CHANGE created_at created_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\''); | ||
|
||
$this->addSql('ALTER TABLE desordre_precision | ||
CHANGE created_at created_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\''); | ||
|
||
$this->addSql('ALTER TABLE desordre_precision CHANGE coef coef DOUBLE PRECISION NOT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE desordre_categorie_signalement DROP FOREIGN KEY FK_E365880CECF01477'); | ||
$this->addSql('ALTER TABLE desordre_categorie_signalement DROP FOREIGN KEY FK_E365880C65C5E57E'); | ||
$this->addSql('ALTER TABLE desordre_critere_signalement DROP FOREIGN KEY FK_689D9BA81C3935AB'); | ||
$this->addSql('ALTER TABLE desordre_critere_signalement DROP FOREIGN KEY FK_689D9BA865C5E57E'); | ||
$this->addSql('ALTER TABLE desordre_precision_signalement DROP FOREIGN KEY FK_D390215F9FB07E9C'); | ||
$this->addSql('ALTER TABLE desordre_precision_signalement DROP FOREIGN KEY FK_D390215F65C5E57E'); | ||
$this->addSql('DROP TABLE desordre_categorie_signalement'); | ||
$this->addSql('DROP TABLE desordre_critere_signalement'); | ||
$this->addSql('DROP TABLE desordre_precision_signalement'); | ||
|
||
$this->addSql('ALTER TABLE desordre_categorie | ||
CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
CHANGE updated_at updated_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\''); | ||
|
||
$this->addSql('ALTER TABLE desordre_critere | ||
CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
CHANGE updated_at updated_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\''); | ||
|
||
$this->addSql('ALTER TABLE desordre_precision | ||
CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
CHANGE updated_at updated_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\''); | ||
|
||
$this->addSql('ALTER TABLE desordre_precision CHANGE coef coef INT NOT NULL'); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Service\Import\CsvParser; | ||
use App\Service\Import\Desordres\DesordresTablesLoader; | ||
use App\Service\UploadHandlerService; | ||
use League\Flysystem\FilesystemOperator; | ||
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; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
|
||
#[AsCommand( | ||
name: 'app:import-desordres-tables', | ||
description: 'Import DesordreCategorie, DesordreCritere, DesordrePrecision', | ||
)] | ||
class ImportDesordresTablesCommand extends Command | ||
{ | ||
public function __construct( | ||
private CsvParser $csvParser, | ||
private ParameterBagInterface $parameterBag, | ||
private FilesystemOperator $fileStorage, | ||
private UploadHandlerService $uploadHandlerService, | ||
private DesordresTablesLoader $desordresTablesLoader, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$fromFile = 'csv/desordres_tables.csv'; | ||
$toFile = $this->parameterBag->get('uploads_tmp_dir').'desordres_tables.csv'; | ||
if (!$this->fileStorage->fileExists($fromFile)) { | ||
$io->error('CSV File does not exists'); | ||
|
||
return Command::FAILURE; | ||
} | ||
|
||
$this->uploadHandlerService->createTmpFileFromBucket($fromFile, $toFile); | ||
|
||
$this->desordresTablesLoader->load( | ||
$this->csvParser->parseAsDict($toFile), | ||
$output | ||
); | ||
|
||
$metadata = $this->desordresTablesLoader->getMetadata(); | ||
|
||
$io->success(sprintf('%s desordre_categorie have been created', $metadata['count_desordre_categorie_created'])); | ||
$io->success(sprintf('%s desordre_critere have been created', $metadata['count_desordre_critere_created'])); | ||
$io->success(sprintf('%s desordre_precision have been created', $metadata['count_desordre_precision_created'])); | ||
$io->success(sprintf('%s desordre_precision have been updated', $metadata['count_desordre_precision_updated'])); | ||
|
||
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
Oops, something went wrong.