Skip to content

Commit

Permalink
[SonataImportBundle] New SonataImportBundle package
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Apr 17, 2024
1 parent 4b178ad commit 5561211
Show file tree
Hide file tree
Showing 39 changed files with 2,133 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/after_splitting_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- process
- profiling
- security
- sonata-import-bundle
- sonata-integration-bundle
- sonata-extra-bundle
- tester
Expand Down
60 changes: 60 additions & 0 deletions app/migrations/Version20240411203316.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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 Version20240411203316 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE import__column (
id INT AUTO_INCREMENT NOT NULL,
import_id INT UNSIGNED NOT NULL,
header_name VARCHAR(255) NOT NULL,
sample LONGTEXT NOT NULL,
is_identifier TINYINT(1) DEFAULT 0 NOT NULL,
is_ignored TINYINT(1) DEFAULT 0 NOT NULL,
mapped_to VARCHAR(255) DEFAULT NULL,
is_date TINYINT(1) DEFAULT 0 NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
INDEX IDX_9770C911B6A263D9 (import_id),
UNIQUE INDEX import_header_name (import_id, header_name),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE import__import (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
entity_class VARCHAR(255) NOT NULL,
file_content LONGTEXT DEFAULT NULL,
state VARCHAR(40) DEFAULT \'new\' NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE
import__column
ADD
CONSTRAINT FK_9770C911B6A263D9 FOREIGN KEY (import_id) REFERENCES import__import (id) ON DELETE CASCADE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE import__column DROP FOREIGN KEY FK_9770C911B6A263D9');
$this->addSql('DROP TABLE import__column');
$this->addSql('DROP TABLE import__import');
}
}
31 changes: 31 additions & 0 deletions app/migrations/Version20240417143929.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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 Version20240417143929 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE UNIQUE INDEX UNIQ_C052A2E4EA750E8 ON draw_acme__tag (label)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_C052A2E4EA750E8 ON draw_acme__tag');
}
}
31 changes: 31 additions & 0 deletions app/migrations/Version20240417181931.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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 Version20240417181931 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE import__import ADD insert_when_not_found TINYINT(1) DEFAULT 0 NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE import__import DROP insert_when_not_found');
}
}
2 changes: 1 addition & 1 deletion app/src/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Tag implements \Stringable
#[ORM\Column(name: 'active', type: 'boolean', options: ['default' => 1])]
private bool $active = true;

#[ORM\Column(name: 'label', type: 'string', length: 255, nullable: false)]
#[ORM\Column(name: 'label', type: 'string', length: 255, unique: true, nullable: false)]
#[
Assert\NotNull,
Assert\Length(min: 3, max: 255)
Expand Down
1 change: 1 addition & 0 deletions app/src/Sonata/Admin/UserAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected function configureListFields(ListMapper $list): void
->add('email')
->add('childObject1')
->add('childObject2')
->add('userTags', 'list')
->add('tags', 'list')
->add('isLocked', 'boolean', ['inverse' => true]);
}
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"draw/profiling": "self.version",
"draw/security": "self.version",
"draw/sonata-extra-bundle": "self.version",
"draw/sonata-import-bundle": "self.version",
"draw/sonata-integration-bundle": "self.version",
"draw/tester": "self.version",
"draw/tester-bundle": "self.version",
Expand All @@ -165,6 +166,7 @@
"psr-4": {
"Draw\\Bundle\\FrameworkExtraBundle\\": "packages/framework-extra-bundle/",
"Draw\\Bundle\\SonataExtraBundle\\": "packages/sonata-extra-bundle/",
"Draw\\Bundle\\SonataImportBundle\\": "packages/sonata-import-bundle/",
"Draw\\Bundle\\SonataIntegrationBundle\\": "packages/sonata-integration-bundle/",
"Draw\\Bundle\\TesterBundle\\": "packages/tester-bundle/",
"Draw\\Bundle\\UserBundle\\": "packages/user-bundle/",
Expand Down
1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
Draw\Bundle\FrameworkExtraBundle\DrawFrameworkExtraBundle::class => ['all' => true],
Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Draw\Bundle\SonataImportBundle\DrawSonataImportBundle::class => ['all' => true],
];
6 changes: 6 additions & 0 deletions config/packages/draw_sonata_import.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
draw_sonata_import:
classes:
'App\Entity\Tag':
alias: 'Tag'
'App\Entity\UserTag':
alias: 'UserTag'
66 changes: 66 additions & 0 deletions packages/sonata-import-bundle/Admin/ColumnAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Draw\Bundle\SonataImportBundle\Admin;

use Draw\Bundle\SonataImportBundle\Column\MappedToOptionBuilder\MappedToOptionBuilderInterface;
use Draw\Bundle\SonataImportBundle\Entity\Column;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

/**
* @method Column getSubject()
*/
#[AutoconfigureTag(
'sonata.admin',
attributes: [
'group' => 'Import',
'show_in_dashboard' => false,
'model_class' => Column::class,
'manager_type' => 'orm',
'label' => 'Column',
]
)]
class ColumnAdmin extends AbstractAdmin
{
public function __construct(
#[TaggedIterator(MappedToOptionBuilderInterface::class)]
private iterable $mappedToOptionBuilders
) {
parent::__construct();
}

protected function configureFormFields(FormMapper $form): void
{
$form
->add('headerName')
->add('sample')
->add(
'mappedTo',
ChoiceType::class,
[
'required' => false,
'choices' => $this->loadMappedToOptions($this->getSubject()),
]
)
->add('isIdentifier')
->add('isDate')
->add('isIgnored');
}

private function loadMappedToOptions(Column $column): array
{
$options = [];

foreach ($this->mappedToOptionBuilders as $mappedToOptionBuilder) {
$options = $mappedToOptionBuilder->getOptions(
$column,
$options
);
}

return $options;
}
}
Loading

0 comments on commit 5561211

Please sign in to comment.