Skip to content
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
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,49 @@ jobs:
run: composer require --dev --no-interaction -W maatwebsite/excel spatie/simple-excel rap2hpoutre/fast-excel "box/spout:^3.3"
- name: Files written by each library import, and our exports read back in each
run: vendor/bin/pest tests/Interop tests/FileInteropTest.php

databases:
name: Pest on ${{ matrix.database }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { database: PostgreSQL, connection: pgsql, port: 5432 }
- { database: MySQL, connection: mysql, port: 3306 }
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: import_wizard
POSTGRES_PASSWORD: secret
POSTGRES_DB: import_wizard_test
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
mysql:
image: mysql:8.4
env:
MYSQL_USER: import_wizard
MYSQL_PASSWORD: secret
MYSQL_DATABASE: import_wizard_test
MYSQL_ROOT_PASSWORD: secret
ports: ['3306:3306']
options: --health-cmd "mysqladmin ping -h 127.0.0.1 -psecret" --health-interval 5s --health-timeout 5s --health-retries 20
steps:
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: mbstring, intl, pdo_sqlite, pdo_pgsql, pdo_mysql, zip, gd, dom, fileinfo, simplexml, xmlreader, xmlwriter
coverage: none
tools: composer:v2
- uses: ramsey/composer-install@v4
- name: Pest (tenancy, job hooks and Octane safety included)
env:
DB_CONNECTION: ${{ matrix.connection }}
DB_HOST: 127.0.0.1
DB_PORT: ${{ matrix.port }}
DB_DATABASE: import_wizard_test
DB_USERNAME: import_wizard
DB_PASSWORD: secret
run: vendor/bin/pest
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.14.0
- **Fixed on MySQL**: the review preview kept its columns in file order (MySQL's JSON type reordered them); review slices are now stored as text.
- **Multi-tenant panels**: runs record their Filament tenant. The Import audit page, approvals and rejections are limited to the current tenant, so one tenant never sees or decides another's imports. `HeadlessImport::tenant()` records one for headless runs. Uploads go to a folder per tenant (`{directory}/{panel}/tenant-{key}`), and `import-wizard:prune-uploads` prunes those too. New migration (`tenant_type`, `tenant_id`). `docs/multi-tenancy.md`.
- **Code around every queued job**: `ImportJobContext::around(fn (JobRun $run, Closure $next) => …)` wraps each review and import slice, so apps can set up their own context (a tenant connection, a current-site service) before rows are read or written.
- **`LocaleColumns::writeUsing()`**: write translations stored outside the record's attributes (e.g. one row per language).
- **Exports for importers whose columns aren't attributes**: an importer implementing `CustomizesExport` chooses the exported records (`modifyExportQuery()`) and computes each value (`resolveExportValue()`), e.g. one row per entry with a column per language.
- **`CommitsRowsIndividually`**: importers whose rows are each atomic and safe to repeat can commit row by row instead of one transaction per slice. On PostgreSQL that doubled the speed of rows that open several savepoints each.
- **`ext-pdo_sqlite` is optional**: `seen_store` defaults to `auto` (SQLite when the extension is loaded, else the database).
- **CI on PostgreSQL and MySQL** besides SQLite, plus an Octane safety test (no per-request static state; jobs run back to back without leaking context).
- **Filament 5.12 compatibility**: Filament now restores the panel inside queued import jobs; the test suite was updated for it and for its panel-origin check on nested Livewire components.
- **Fixed**: queued review slices crashed on a real queue worker (the user was looked up through `app(Authenticatable::class)`, which Laravel binds to the current user, null on a worker); so did `import-wizard:run --user` unless the app had rebound the contract. Review slices now also run in the panel and tenant they were started in.
- **Fixed**: CustomizesExport is applied to relation queries given to `FileExport::query()`.

### Upgrading from 0.13
- Run `php artisan migrate`. Runs recorded before the upgrade have no tenant, so on a panel with tenancy the Import audit page no longer lists them (and they can't be approved there). To keep them, fill `tenant_type` / `tenant_id` yourself, e.g. `update import_wizard_audits set tenant_type = 'team', tenant_id = …`.
- On panels with tenancy, uploads (and the chunked-upload endpoints, now `/{panel}/{tenant}/import-wizard/upload/*`) move to the tenant's folder: finish or restart uploads that were in progress during the deploy.
- `LocaleColumns::filler()` is now an instance method (`protected function filler(string $locale)`); subclasses overriding it must follow.
- `ext-pdo_sqlite` is no longer required; with `seen_store` left at its default (`auto`) a server without it uses the database store.

## 0.13.0
- **Quick start from a model**: `ImportWizardAction::make()->forModel(Product::class)` (or `ModelImporters::for(Product::class)` for the headless API and console) generates an importer from the model's table — fillable columns, types, nullability and `varchar` lengths become casts and rules; a blank cell in a NOT NULL column uses the column default. The class is generated from its own name, so queue workers define it too; it is only ever generated for real Eloquent models. `docs/quick-start-model.md`.
- Translations (en, zh_CN, zh_TW, zh_HK) for the generated importer's completion message.
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<img src="https://img.shields.io/badge/Filament-5.x-FDAE4B" alt="Filament 5">
<img src="https://img.shields.io/badge/PHPStan-level%2010-brightgreen?logo=php&logoColor=white" alt="PHPStan level 10">
<a href="https://github.com/solutionforest/filament-import-wizard/actions/workflows/ci.yml"><img src="https://github.com/solutionforest/filament-import-wizard/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<img src="https://img.shields.io/badge/release-0.13.0-4f46e5" alt="Release 0.13.0">
<img src="https://img.shields.io/badge/release-0.14.0-4f46e5" alt="Release 0.14.0">
<img src="https://img.shields.io/badge/license-MIT-green" alt="License: MIT">
</p>

Expand Down Expand Up @@ -41,10 +41,11 @@ Upload a file → map the columns → review every row → import (queued) → e
| **Headless API** | `HeadlessImport` runs the same upload → map → review → import pipeline from an API endpoint, a job or a command — [headless API](docs/headless-api.md) |
| **Audit trail** *(optional)* | Who imported what (file SHA-256, mapping, review result, outcome) with an immutable event history and an **Import audit** page — [audit](docs/audit-and-approval.md) |
| **Approval flow** *(optional)* | Maker–checker: hold an import for a second person, by rule (e.g. over 1,000 rows) — [audit & approval](docs/audit-and-approval.md) |
| **Multi-tenant panels** | Audits, approvals and history scoped to the Filament tenant; a hook around every queued job for your own context (tenant database, current site) — [multi-tenancy](docs/multi-tenancy.md) |
| **Multi-panel, multi-server** | Per-panel disk, directory and limits; shared-disk / database-backed state so any server can take any request; Horizon and Octane notes — [scaling](docs/scaling.md) |
| **Translated** | English, 简体中文, 繁體中文 (TW / HK); plural-aware, locale-aware numbers and dates, RTL-safe — [localization](docs/localization.md) |
| **Secure by default** | Locked wizard state, escaped output, confined uploads, allow-listed importer options, CSV formula guard on export; dedicated security tests and `composer audit` in CI |
| **Quality gates** | PHPStan level 10, 130 Pest tests, security group, differential fuzz, mutation test, 50k–200k-row stress tests, CI matrix (PHP 8.2–8.4 × Laravel 12/13) — [testing](docs/testing.md) |
| **Quality gates** | PHPStan level 10, 140 Pest tests on SQLite, PostgreSQL and MySQL, security group, differential fuzz, mutation test, 50k–200k-row stress tests, CI matrix (PHP 8.2–8.4 × Laravel 12/13) — [testing](docs/testing.md) |

## Video tutorial

Expand All @@ -58,18 +59,18 @@ Chapters and how it was recorded: [docs/video-tutorial.md](docs/video-tutorial.m

| Package | PHP | Laravel | Filament | Livewire | Status |
| --- | --- | --- | --- | --- | --- |
| **0.10 – 0.13** | 8.2 – 8.4 ¹ | **12** ✅ · **13** ✅ · 11.28+ ² | **5.x** (tested on 5.11) | 4.x (via Filament 5) | **Current** |
| 0.2 – 0.9 | 8.2 – 8.4 ¹ | 12 · 13 | 5.x | 4.x | Superseded — upgrade to 0.13 |
| **0.10 – 0.14** | 8.2 – 8.4 ¹ | **12** ✅ · **13** ✅ · 11.28+ ² | **5.x** (tested on 5.12) | 4.x (via Filament 5) | **Current** |
| 0.2 – 0.9 | 8.2 – 8.4 ¹ | 12 · 13 | 5.x | 4.x | Superseded — upgrade to 0.14 |
| — | — | — | 3.x · 4.x | — | Not supported (built on Filament 5's importer and schema APIs) |

✅ = the full test suite (Pest, 130 tests + fuzz, mutation and stress suites) passes on it · ¹ run on PHP 8.4; 8.2 and 8.3 are allowed by the constraints but were not run ·
✅ = the full test suite (Pest, 140 tests + fuzz, mutation and stress suites) passes on it · ¹ run on PHP 8.4; 8.2 and 8.3 are allowed by the constraints but were not run ·
² allowed by Filament 5, not run — every Laravel 11.x release is currently flagged by Composer security advisories, so upgrade to 12+.

| Environment | Status |
| --- | --- |
| Queue | `sync` (tested), `database` / `redis` / `sqs` via Filament batches · **Horizon**: supported — see [Scaling](docs/scaling.md) |
| **Octane** | Code-reviewed for state leaks; not run under a live Octane server — see [Scaling](docs/scaling.md) |
| Database | SQLite (tested). MySQL / PostgreSQL use only standard Laravel query-builder calls but were not run here |
| **Octane** | A test fails on any per-request static state, and runs jobs back to back to check nothing leaks; not run under a live Octane server here — see [Scaling](docs/scaling.md) |
| Database | SQLite, PostgreSQL and MySQL: the full suite runs on all three in CI |
| File storage | `local` (tested). Any Flysystem disk (S3, NFS…) is supported by design; S3 was not run here |
| Browsers | Chromium (tested) |

Expand All @@ -79,7 +80,7 @@ Release notes: [CHANGELOG.md](CHANGELOG.md).

```bash
composer config repositories.filament-import-wizard vcs https://github.com/solutionforest/filament-import-wizard.git
composer require solution-forest/filament-import-wizard:^0.13
composer require solution-forest/filament-import-wizard:^0.14
php artisan migrate
```

Expand Down Expand Up @@ -147,6 +148,7 @@ $review->isValid() && $import->user($user)->start(); // queued, like
| [Other spreadsheet libraries](docs/interop.md) | maatwebsite/excel, spatie/simple-excel, fast-excel, simplesheet, xlswriter |
| [Large files](docs/large-files.md) | Chunked upload, console import |
| [Audit & approval](docs/audit-and-approval.md) | Optional trail and maker–checker |
| [Multi-tenancy](docs/multi-tenancy.md) | Tenant-scoped audits and approvals; code around every queued job |
| [Scaling](docs/scaling.md) | Several servers, Horizon, Octane |
| [Configuration](docs/configuration.md) | Every option in one place |
| [Localization](docs/localization.md) | Languages, overriding texts, adding a locale |
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
],
"require": {
"php": "^8.2",
"filament/filament": "^5.0",
"ext-pdo_sqlite": "*"
"filament/filament": "^5.0"
},
"require-dev": {
"orchestra/testbench": "^9.0|^10.0|^11.0",
Expand Down Expand Up @@ -92,6 +91,7 @@
]
},
"suggest": {
"ext-pdo_sqlite": "Faster duplicate checks (UniqueInFile) on a single server; without it the application database is used.",
"phpoffice/phpspreadsheet": "Required to import legacy .xls files (loaded fully into memory, so keep those files modest).",
"maatwebsite/excel": "Files written by Laravel Excel import fine (it needs no integration); use a StringValueBinder for codes and phone numbers.",
"spatie/simple-excel": "Files written by Simple Excel import fine.",
Expand Down
3 changes: 2 additions & 1 deletion config/import-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
| during Review. Review is spread over many requests, so with more than one
| web server this MUST be a shared store:
|
| 'auto' – 'sqlite' when the pdo_sqlite extension is loaded, else 'database'
| 'sqlite' – a throw-away file in storage/app/import-wizard (single server)
| 'database' – the application database (works behind a load balancer)
*/
'seen_store' => env('IMPORT_WIZARD_SEEN_STORE', 'sqlite'),
'seen_store' => env('IMPORT_WIZARD_SEEN_STORE', 'auto'),

/*
| Seconds a queued import slice may run (Horizon / queue:work --timeout must
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
* The Filament tenant a run belongs to, so panels with tenancy only list,
* approve and reject the current tenant's imports. Null on panels without tenancy.
*/
return new class extends Migration
{
public function up(): void
{
Schema::table('import_wizard_audits', function (Blueprint $table): void {
$table->string('tenant_type')->nullable()->after('panel_id');
$table->string('tenant_id', 64)->nullable()->after('tenant_type');
$table->index(['panel_id', 'tenant_type', 'tenant_id'], 'import_wizard_audits_tenant_index');
});
}

public function down(): void
{
Schema::table('import_wizard_audits', function (Blueprint $table): void {
$table->dropIndex('import_wizard_audits_tenant_index');
$table->dropColumn(['tenant_type', 'tenant_id']);
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

/**
* MySQL's JSON type reorders object keys (shortest first), which scrambled the
* order of the preview's columns and of the error counts per column. Review
* slices are short-lived working rows, so keep their JSON exactly as written.
*/
return new class extends Migration
{
public function up(): void
{
Schema::table('import_wizard_review_slices', function (Blueprint $table): void {
$table->longText('errors_by_column')->change();
$table->longText('sample')->change();
$table->longText('preview')->nullable()->change();
});
}

public function down(): void
{
// PostgreSQL won't turn text into json without being told how.
if (Schema::getConnection()->getDriverName() === 'pgsql') {
foreach (['errors_by_column', 'sample', 'preview'] as $column) {
DB::statement("alter table import_wizard_review_slices alter column {$column} type json using {$column}::json");
}

return;
}

Schema::table('import_wizard_review_slices', function (Blueprint $table): void {
$table->json('errors_by_column')->change();
$table->json('sample')->change();
$table->json('preview')->nullable()->change();
});
}
};
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

| Key | Env | Default | |
| --- | --- | --- | --- |
| `seen_store` | `IMPORT_WIZARD_SEEN_STORE` | `sqlite` | `sqlite` (one server) or `database` (shared) |
| `seen_store` | `IMPORT_WIZARD_SEEN_STORE` | `auto` | `auto` (`sqlite` if `pdo_sqlite` is loaded, else `database`), `sqlite` (one server) or `database` (shared) |
| `job_timeout` | `IMPORT_WIZARD_JOB_TIMEOUT` | `600` | Seconds a queued slice may run |
| `preview_rows` | `IMPORT_WIZARD_PREVIEW_ROWS` | `10` | Rows in the Map / Review preview tables |

Expand Down
19 changes: 19 additions & 0 deletions docs/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ the exported file re-reviewed as 100 % valid (see `composer stress`).

For anything that isn't just an attribute of the same name use `->resolve()`.

When **most** columns aren't attributes (say one row per entry with a column per language, while the list shows one record per language), implement `CustomizesExport` on the importer instead. The export action and `FileExport` then use it:

```php
class EntryImporter extends Importer implements CustomizesExport
{
public static function modifyExportQuery(Builder $query): Builder
{
return $query->where('locale', 'en'); // one row per entry
}

public static function resolveExportValue(Model $record, string $column): mixed
{
return $record->page->valueForImportColumn($column); // e.g. title_zh_HK
}
}
```

`modifyExportQuery()` receives the list's query with its constraints — the tenant scope of a panel with tenancy, a relation manager's owner, the user's filters. Narrow or extend **that** query; never return a new one (`Entry::query()`), which would export every tenant's records. Resolved values are formatted and, in CSV, guarded against formulas like any other value.

## Rules stay valid: `verify()`

Data that is already in your database may not satisfy the importer's rules (an old record with a bad e-mail). `verify()` runs the exported file through the importer's own
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ composer config repositories.filament-import-wizard vcs https://github.com/solut
composer require solution-forest/filament-import-wizard:^0.8
```

Requirements: PHP 8.2+, Filament 5 (and the Laravel version it requires), `ext-pdo_sqlite`.
Requirements: PHP 8.2+, Filament 5 (and the Laravel version it requires). `ext-pdo_sqlite` is optional: with it, duplicate checks use a throw-away SQLite file; without it, the application database.

## 2. Database tables

Expand Down
Loading