-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SonataImportBundle] New SonataImportBundle package
- Loading branch information
Showing
39 changed files
with
2,133 additions
and
1 deletion.
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
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'); | ||
} | ||
} |
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,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'); | ||
} | ||
} |
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,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'); | ||
} | ||
} |
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
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' |
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,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; | ||
} | ||
} |
Oops, something went wrong.