mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-06 11:09:29 +00:00
Fix migration error and dto error
This commit is contained in:
parent
2bc39e7791
commit
ccb837e4b4
4 changed files with 115 additions and 12 deletions
|
|
@ -4,29 +4,49 @@ declare(strict_types=1);
|
|||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use App\Migration\AbstractMultiPlatformMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250802153643 extends AbstractMigration
|
||||
final class Version20250802153643 extends AbstractMultiPlatformMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add bulk info provider import jobs table';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
public function mySQLUp(Schema $schema): void
|
||||
{
|
||||
$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');
|
||||
$this->addSql('CREATE INDEX IDX_7F58C1EDB03A8386 ON bulk_info_provider_import_jobs (created_by_id)');
|
||||
}
|
||||
|
||||
public function mySQLDown(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE bulk_info_provider_import_jobs');
|
||||
}
|
||||
|
||||
public function sqLiteUp(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$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)');
|
||||
$this->addSql('CREATE INDEX IDX_7F58C1EDB03A8386 ON bulk_info_provider_import_jobs (created_by_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
public function sqLiteDown(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE bulk_info_provider_import_jobs');
|
||||
}
|
||||
|
||||
public function postgreSQLUp(Schema $schema): void
|
||||
{
|
||||
$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)');
|
||||
$this->addSql('CREATE INDEX IDX_7F58C1EDB03A8386 ON bulk_info_provider_import_jobs (created_by_id)');
|
||||
}
|
||||
|
||||
public function postgreSQLDown(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP TABLE bulk_info_provider_import_jobs');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -246,9 +246,9 @@
|
|||
<br><small class="text-muted">{{ dto.provider_id }}</small>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-info">{{ dto._source_field ?? 'unknown' }}</span>
|
||||
{% if dto._source_keyword %}
|
||||
<br><small class="text-muted">{{ dto._source_keyword }}</small>
|
||||
<span class="badge bg-info">{{ result.source_field ?? 'unknown' }}</span>
|
||||
{% if result.source_keyword %}
|
||||
<br><small class="text-muted">{{ result.source_keyword }}</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
|
|
|
|||
|
|
@ -169,9 +169,9 @@
|
|||
<br><small class="text-muted">{{ dto.provider_id }}</small>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-info">{{ dto._source_field ?? 'unknown' }}</span>
|
||||
{% if dto._source_keyword %}
|
||||
<br><small class="text-muted">{{ dto._source_keyword }}</small>
|
||||
<span class="badge bg-info">{{ result.source_field ?? 'unknown' }}</span>
|
||||
{% if result.source_keyword %}
|
||||
<br><small class="text-muted">{{ result.source_keyword }}</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\BulkInfoProviderImportJob;
|
||||
use App\Entity\BulkImportJobStatus;
|
||||
use App\Entity\UserSystem\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
|
@ -111,6 +114,86 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testStep2TemplateRendering(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$this->loginAsUser($client, 'admin');
|
||||
|
||||
$entityManager = $client->getContainer()->get('doctrine')->getManager();
|
||||
|
||||
// Use an existing part from test fixtures (ID 1 should exist)
|
||||
$partRepository = $entityManager->getRepository(Part::class);
|
||||
$part = $partRepository->find(1);
|
||||
|
||||
if (!$part) {
|
||||
$this->markTestSkipped('Test part with ID 1 not found in fixtures');
|
||||
}
|
||||
|
||||
// Get the admin user for the createdBy field
|
||||
$userRepository = $entityManager->getRepository(User::class);
|
||||
$user = $userRepository->findOneBy(['name' => 'admin']);
|
||||
|
||||
if (!$user) {
|
||||
$this->markTestSkipped('Admin user not found in fixtures');
|
||||
}
|
||||
|
||||
// Create a test job with search results that include source_field and source_keyword
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($user);
|
||||
$job->setPartIds([$part->getId()]);
|
||||
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
|
||||
$job->setSearchResults([
|
||||
[
|
||||
'part_id' => $part->getId(),
|
||||
'search_results' => [
|
||||
[
|
||||
'dto' => [
|
||||
'provider_key' => 'test_provider',
|
||||
'provider_id' => 'TEST123',
|
||||
'name' => 'Test Component',
|
||||
'description' => 'Test component description',
|
||||
'manufacturer' => 'Test Manufacturer',
|
||||
'mpn' => 'TEST-MPN-123',
|
||||
'provider_url' => 'https://example.com/test',
|
||||
'preview_image_url' => null,
|
||||
'_source_field' => 'test_field',
|
||||
'_source_keyword' => 'test_keyword'
|
||||
],
|
||||
'localPart' => null
|
||||
]
|
||||
],
|
||||
'errors' => []
|
||||
]
|
||||
]);
|
||||
|
||||
$entityManager->persist($job);
|
||||
$entityManager->flush();
|
||||
|
||||
// Test that step2 renders correctly with the search results
|
||||
$client->request('GET', '/tools/bulk-info-provider-import/step2/' . $job->getId());
|
||||
|
||||
// Follow any redirects (like locale redirects)
|
||||
if ($client->getResponse()->isRedirect()) {
|
||||
$client->followRedirect();
|
||||
}
|
||||
|
||||
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
|
||||
|
||||
// Verify the template rendered the source_field and source_keyword correctly
|
||||
$content = $client->getResponse()->getContent();
|
||||
$this->assertStringContainsString('test_field', $content);
|
||||
$this->assertStringContainsString('test_keyword', $content);
|
||||
|
||||
// Clean up - find by ID to avoid detached entity issues
|
||||
$jobId = $job->getId();
|
||||
$entityManager->clear(); // Clear all entities
|
||||
$jobToRemove = $entityManager->find(BulkInfoProviderImportJob::class, $jobId);
|
||||
if ($jobToRemove) {
|
||||
$entityManager->remove($jobToRemove);
|
||||
$entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
private function loginAsUser($client, string $username): void
|
||||
{
|
||||
$entityManager = $client->getContainer()->get('doctrine')->getManager();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue