Skip to content

Commit 4f64f0e

Browse files
committed
Fix migration error and dto error
1 parent eb4ca17 commit 4f64f0e

File tree

4 files changed

+115
-12
lines changed

4 files changed

+115
-12
lines changed

migrations/Version20250802153643.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,49 @@
44

55
namespace DoctrineMigrations;
66

7+
use App\Migration\AbstractMultiPlatformMigration;
78
use Doctrine\DBAL\Schema\Schema;
8-
use Doctrine\Migrations\AbstractMigration;
99

1010
/**
1111
* Auto-generated Migration: Please modify to your needs!
1212
*/
13-
final class Version20250802153643 extends AbstractMigration
13+
final class Version20250802153643 extends AbstractMultiPlatformMigration
1414
{
1515
public function getDescription(): string
1616
{
1717
return 'Add bulk info provider import jobs table';
1818
}
1919

20-
public function up(Schema $schema): void
20+
public function mySQLUp(Schema $schema): void
21+
{
22+
$this->addSql('CREATE TABLE bulk_info_provider_import_jobs (id INT AUTO_INCREMENT NOT NULL, name LONGTEXT NOT NULL, part_ids LONGTEXT NOT NULL, field_mappings LONGTEXT NOT NULL, search_results LONGTEXT NOT NULL, status VARCHAR(20) NOT NULL, created_at DATETIME NOT NULL, completed_at DATETIME DEFAULT NULL, prefetch_details TINYINT(1) NOT NULL, progress LONGTEXT NOT NULL, created_by_id INT NOT NULL, CONSTRAINT FK_7F58C1EDB03A8386 FOREIGN KEY (created_by_id) REFERENCES `users` (id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
23+
$this->addSql('CREATE INDEX IDX_7F58C1EDB03A8386 ON bulk_info_provider_import_jobs (created_by_id)');
24+
}
25+
26+
public function mySQLDown(Schema $schema): void
27+
{
28+
$this->addSql('DROP TABLE bulk_info_provider_import_jobs');
29+
}
30+
31+
public function sqLiteUp(Schema $schema): void
2132
{
22-
// this up() migration is auto-generated, please modify it to your needs
2333
$this->addSql('CREATE TABLE bulk_info_provider_import_jobs (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name CLOB NOT NULL, part_ids CLOB NOT NULL, field_mappings CLOB NOT NULL, search_results CLOB NOT NULL, status VARCHAR(20) NOT NULL, created_at DATETIME NOT NULL, completed_at DATETIME DEFAULT NULL, prefetch_details BOOLEAN NOT NULL, progress CLOB NOT NULL, created_by_id INTEGER NOT NULL, CONSTRAINT FK_7F58C1EDB03A8386 FOREIGN KEY (created_by_id) REFERENCES "users" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
2434
$this->addSql('CREATE INDEX IDX_7F58C1EDB03A8386 ON bulk_info_provider_import_jobs (created_by_id)');
2535
}
2636

27-
public function down(Schema $schema): void
37+
public function sqLiteDown(Schema $schema): void
38+
{
39+
$this->addSql('DROP TABLE bulk_info_provider_import_jobs');
40+
}
41+
42+
public function postgreSQLUp(Schema $schema): void
43+
{
44+
$this->addSql('CREATE TABLE bulk_info_provider_import_jobs (id SERIAL PRIMARY KEY NOT NULL, name TEXT NOT NULL, part_ids TEXT NOT NULL, field_mappings TEXT NOT NULL, search_results TEXT NOT NULL, status VARCHAR(20) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, completed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, prefetch_details BOOLEAN NOT NULL, progress TEXT NOT NULL, created_by_id INT NOT NULL, CONSTRAINT FK_7F58C1EDB03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
45+
$this->addSql('CREATE INDEX IDX_7F58C1EDB03A8386 ON bulk_info_provider_import_jobs (created_by_id)');
46+
}
47+
48+
public function postgreSQLDown(Schema $schema): void
2849
{
29-
// this down() migration is auto-generated, please modify it to your needs
3050
$this->addSql('DROP TABLE bulk_info_provider_import_jobs');
3151
}
3252
}

templates/info_providers/bulk_import/step1.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@
246246
<br><small class="text-muted">{{ dto.provider_id }}</small>
247247
</td>
248248
<td>
249-
<span class="badge bg-info">{{ dto._source_field ?? 'unknown' }}</span>
250-
{% if dto._source_keyword %}
251-
<br><small class="text-muted">{{ dto._source_keyword }}</small>
249+
<span class="badge bg-info">{{ result.source_field ?? 'unknown' }}</span>
250+
{% if result.source_keyword %}
251+
<br><small class="text-muted">{{ result.source_keyword }}</small>
252252
{% endif %}
253253
</td>
254254
<td>

templates/info_providers/bulk_import/step2.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@
169169
<br><small class="text-muted">{{ dto.provider_id }}</small>
170170
</td>
171171
<td>
172-
<span class="badge bg-info">{{ dto._source_field ?? 'unknown' }}</span>
173-
{% if dto._source_keyword %}
174-
<br><small class="text-muted">{{ dto._source_keyword }}</small>
172+
<span class="badge bg-info">{{ result.source_field ?? 'unknown' }}</span>
173+
{% if result.source_keyword %}
174+
<br><small class="text-muted">{{ result.source_keyword }}</small>
175175
{% endif %}
176176
</td>
177177
<td>

tests/Controller/BulkInfoProviderImportControllerTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
namespace App\Tests\Controller;
2424

25+
use App\Entity\Parts\Part;
26+
use App\Entity\BulkInfoProviderImportJob;
27+
use App\Entity\BulkImportJobStatus;
2528
use App\Entity\UserSystem\User;
2629
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
2730
use Symfony\Component\HttpFoundation\Response;
@@ -111,6 +114,86 @@ public function testAccessControlForManage(): void
111114
);
112115
}
113116

117+
public function testStep2TemplateRendering(): void
118+
{
119+
$client = static::createClient();
120+
$this->loginAsUser($client, 'admin');
121+
122+
$entityManager = $client->getContainer()->get('doctrine')->getManager();
123+
124+
// Use an existing part from test fixtures (ID 1 should exist)
125+
$partRepository = $entityManager->getRepository(Part::class);
126+
$part = $partRepository->find(1);
127+
128+
if (!$part) {
129+
$this->markTestSkipped('Test part with ID 1 not found in fixtures');
130+
}
131+
132+
// Get the admin user for the createdBy field
133+
$userRepository = $entityManager->getRepository(User::class);
134+
$user = $userRepository->findOneBy(['name' => 'admin']);
135+
136+
if (!$user) {
137+
$this->markTestSkipped('Admin user not found in fixtures');
138+
}
139+
140+
// Create a test job with search results that include source_field and source_keyword
141+
$job = new BulkInfoProviderImportJob();
142+
$job->setCreatedBy($user);
143+
$job->setPartIds([$part->getId()]);
144+
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
145+
$job->setSearchResults([
146+
[
147+
'part_id' => $part->getId(),
148+
'search_results' => [
149+
[
150+
'dto' => [
151+
'provider_key' => 'test_provider',
152+
'provider_id' => 'TEST123',
153+
'name' => 'Test Component',
154+
'description' => 'Test component description',
155+
'manufacturer' => 'Test Manufacturer',
156+
'mpn' => 'TEST-MPN-123',
157+
'provider_url' => 'https://example.com/test',
158+
'preview_image_url' => null,
159+
'_source_field' => 'test_field',
160+
'_source_keyword' => 'test_keyword'
161+
],
162+
'localPart' => null
163+
]
164+
],
165+
'errors' => []
166+
]
167+
]);
168+
169+
$entityManager->persist($job);
170+
$entityManager->flush();
171+
172+
// Test that step2 renders correctly with the search results
173+
$client->request('GET', '/tools/bulk-info-provider-import/step2/' . $job->getId());
174+
175+
// Follow any redirects (like locale redirects)
176+
if ($client->getResponse()->isRedirect()) {
177+
$client->followRedirect();
178+
}
179+
180+
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
181+
182+
// Verify the template rendered the source_field and source_keyword correctly
183+
$content = $client->getResponse()->getContent();
184+
$this->assertStringContainsString('test_field', $content);
185+
$this->assertStringContainsString('test_keyword', $content);
186+
187+
// Clean up - find by ID to avoid detached entity issues
188+
$jobId = $job->getId();
189+
$entityManager->clear(); // Clear all entities
190+
$jobToRemove = $entityManager->find(BulkInfoProviderImportJob::class, $jobId);
191+
if ($jobToRemove) {
192+
$entityManager->remove($jobToRemove);
193+
$entityManager->flush();
194+
}
195+
}
196+
114197
private function loginAsUser($client, string $username): void
115198
{
116199
$entityManager = $client->getContainer()->get('doctrine')->getManager();

0 commit comments

Comments
 (0)