-
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.
- Loading branch information
1 parent
8a10ecc
commit a3c7a78
Showing
13 changed files
with
390 additions
and
102 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20250123145424 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Création de la table agent_fournisseurs_identites'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE TABLE agent_fournisseurs_identites (uid VARCHAR(255) NOT NULL, nom VARCHAR(255) NOT NULL, est_reseau_interne BOOLEAN NOT NULL, est_actif BOOLEAN NOT NULL, url_decouverte VARCHAR(255) NOT NULL, domaines JSON NOT NULL, categorie_agent VARCHAR(255) DEFAULT NULL, PRIMARY KEY(uid))'); | ||
$this->addSql('ALTER TABLE agents ADD fournisseur_identite_uid VARCHAR(255) DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE agents DROP fournisseur_identite'); | ||
$this->addSql('ALTER TABLE agents ALTER donnes_authentification TYPE TEXT'); | ||
$this->addSql('COMMENT ON COLUMN agents.donnes_authentification IS NULL'); | ||
$this->addSql('ALTER TABLE agents ADD CONSTRAINT FK_9596AB6E2CCC2389 FOREIGN KEY (fournisseur_identite_uid) REFERENCES agent_fournisseurs_identites (uid) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('CREATE INDEX IDX_9596AB6E2CCC2389 ON agents (fournisseur_identite_uid)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE agents DROP CONSTRAINT FK_9596AB6E2CCC2389'); | ||
$this->addSql('DROP TABLE agent_fournisseurs_identites'); | ||
$this->addSql('DROP INDEX IDX_9596AB6E2CCC2389'); | ||
$this->addSql('ALTER TABLE agents ADD fournisseur_identite VARCHAR(255) NOT NULL'); | ||
$this->addSql('ALTER TABLE agents DROP fournisseur_identite_uid'); | ||
$this->addSql('ALTER TABLE agents ALTER donnes_authentification TYPE TEXT'); | ||
$this->addSql('COMMENT ON COLUMN agents.donnes_authentification IS \'(DC2Type:simple_array)\''); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Command/ImporterCatalogueFournisseurIdentiteAgentCommand.php
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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonIndemnisationJustice\Command; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use MonIndemnisationJustice\Entity\FournisseurIdentiteAgent; | ||
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\EventDispatcher\EventDispatcherInterface; | ||
|
||
#[AsCommand(name: 'mon_indemnisation:agent:importer_catalogue_fournisseur_identite', description: 'Hello PhpStorm')] | ||
class ImporterCatalogueFournisseurIdentiteAgentCommand extends Command | ||
{ | ||
public function __construct( | ||
protected readonly EntityManagerInterface $em, | ||
protected readonly EventDispatcherInterface $eventDispatcher, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->addArgument('path', InputArgument::REQUIRED) | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$path = $input->getArgument('path'); | ||
if (!filter_var($path, FILTER_VALIDATE_URL) && !is_file($path)) { | ||
$output->writeln("<error>URL ou chemin de fichier inconnu $path</error>"); | ||
|
||
return Command::FAILURE; | ||
} | ||
|
||
$index = 0; | ||
if (($handle = fopen($path, 'r')) !== false) { | ||
while (($data = fgetcsv($handle, 1000, ',')) !== false) { | ||
if ($index++ > 0) { | ||
dump($data); | ||
list($reseau, $uid, $titre, $actif, $urlDecouverte, $listeFQDNs) = $data; | ||
|
||
/** @var FournisseurIdentiteAgent $fournisseurIdentite */ | ||
$fournisseurIdentite = $this->em->getRepository(FournisseurIdentiteAgent::class)->findOneBy(['uid' => $uid]) ?? (new FournisseurIdentiteAgent())->setUid($uid); | ||
|
||
$fournisseurIdentite | ||
->setNom($titre) | ||
->setActif(in_array(strtolower($actif), ['oui', 'true', 1])) | ||
->setUrlDecouverte($urlDecouverte) | ||
->setReseauInterne(FournisseurIdentiteAgent::RESEAU_INTERNE === $reseau) | ||
->setDomaines(explode(',', $listeFQDNs)) | ||
; | ||
$this->em->persist($fournisseurIdentite); | ||
} | ||
} | ||
} | ||
|
||
fclose($handle); | ||
$this->em->flush(); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file was deleted.
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
Oops, something went wrong.