Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SonataImportBundle] New SonataImportBundle package #247

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading