elaitech/import

Elaitech Import Package - A comprehensive import workflow system for Laravel

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/elaitech/import

0.0.1 2026-02-16 01:30 UTC

This package is auto-updated.

Last update: 2026-02-16 02:11:41 UTC


README

A comprehensive, modular data import workflow engine for Laravel 12. Provides a full pipeline system for downloading, reading, filtering, mapping, transforming, and processing data from external sources β€” with execution tracking, scheduling, and a built-in dashboard.

Namespace: Elaitech\Import
Requires: PHP 8.4+ Β· Laravel 12 Β· elaitech/data-mapper

πŸ“– Table of Contents

πŸš€ Installation

As a local Composer package (recommended)

In your root composer.json, add the package as a path repository:

{
    "repositories": [
        {
            "type": "path",
            "url": "./packages/import",
            "options": { "symlink": true }
        }
    ],
    "require": {
        "elaitech/import": "@dev"
    }
}

Then install:

composer update elaitech/import

Publishing Assets

# Publish configuration
php artisan vendor:publish --tag=import-config

# Publish migrations (optional β€” they auto-load)
php artisan vendor:publish --tag=import-migrations

# Run migrations
php artisan migrate

πŸ— Architecture

src/
β”œβ”€β”€ ImportServiceProvider.php         # Package bootstrap β€” registers all sub-providers
β”œβ”€β”€ Helpers.php                       # Global helper functions
β”‚
β”œβ”€β”€ Models/                           # Eloquent models (5)
β”‚   β”œβ”€β”€ ImportPipeline.php            # Main pipeline definition
β”‚   β”œβ”€β”€ ImportPipelineConfig.php      # Per-step JSON configuration
β”‚   β”œβ”€β”€ ImportPipelineExecution.php   # Execution run records
β”‚   β”œβ”€β”€ ImportPipelineLog.php         # Per-stage log entries
β”‚   └── ImportPipelineTemplate.php    # Reusable pipeline templates
β”‚
β”œβ”€β”€ Contracts/                        # Top-level interfaces
β”‚   β”œβ”€β”€ Repositories/                 # Repository contracts
β”‚   └── Services/                     # Service contracts
β”‚
β”œβ”€β”€ Enums/                            # Backed enums (6)
β”‚   β”œβ”€β”€ ImportPipelineStatus.php      # pending, running, completed, failed, cancelled
β”‚   β”œβ”€β”€ ImportPipelineFrequency.php   # once, daily, weekly, monthly
β”‚   β”œβ”€β”€ ImportPipelineStep.php        # 8 stepper steps
β”‚   β”œβ”€β”€ PipelineStage.php            # Pipeline execution stages
β”‚   β”œβ”€β”€ PipelineStatus.php           # active, inactive, needs_configuration
β”‚   └── ImageDownloadMode.php        # Image download strategies
β”‚
└── Services/
    β”œβ”€β”€ Core/                         # Shared infrastructure
    β”‚   β”œβ”€β”€ Abstracts/                # Base abstract classes
    β”‚   β”œβ”€β”€ Contracts/                # Shared interfaces (ServiceInterface, FactoryInterface)
    β”‚   β”œβ”€β”€ DTOs/                     # Shared data objects (FilterConfigurationData, etc.)
    β”‚   β”œβ”€β”€ Exceptions/               # Custom exceptions (Filter, Reader, Downloader, etc.)
    β”‚   β”œβ”€β”€ Operators/                # Operator definitions
    β”‚   β”œβ”€β”€ Registry/                 # Service registries
    β”‚   β”œβ”€β”€ Cache/                    # Caching strategies
    β”‚   β”œβ”€β”€ Configuration/            # Configuration handling
    β”‚   └── Traits/                   # HasOptions, ServiceTrait, etc.
    β”‚
    β”œβ”€β”€ Downloader/                   # Data source downloaders
    β”‚   β”œβ”€β”€ Abstracts/                # AbstractDownloader base
    β”‚   β”œβ”€β”€ Contracts/                # DownloaderInterface
    β”‚   β”œβ”€β”€ Factories/                # DownloaderFactory
    β”‚   └── Implementations/
    β”‚       β”œβ”€β”€ HttpDownloader.php    # HTTP/HTTPS downloads
    β”‚       β”œβ”€β”€ FtpDownloader.php     # FTP downloads
    β”‚       └── SftpDownloader.php    # SFTP downloads
    β”‚
    β”œβ”€β”€ Reader/                       # Data format readers
    β”‚   β”œβ”€β”€ Abstracts/                # AbstractReader base
    β”‚   β”œβ”€β”€ Contracts/                # ReaderInterface
    β”‚   β”œβ”€β”€ Factories/                # ReaderFactory
    β”‚   └── Implementations/
    β”‚       β”œβ”€β”€ CsvReader.php         # CSV parsing
    β”‚       β”œβ”€β”€ JsonReader.php        # JSON parsing
    β”‚       β”œβ”€β”€ XmlReader.php         # XML parsing
    β”‚       └── YamlReader.php        # YAML parsing
    β”‚
    β”œβ”€β”€ Filter/                       # Data filtering engine
    β”‚   β”œβ”€β”€ Abstracts/                # AbstractFilterOperator (Template Method)
    β”‚   β”œβ”€β”€ Contracts/                # FilterInterface, OperatorRegistryInterface, etc.
    β”‚   β”œβ”€β”€ Extractors/               # DotNotationValueExtractor
    β”‚   β”œβ”€β”€ Registry/                 # OperatorRegistry
    β”‚   β”œβ”€β”€ Validators/               # FilterValidator
    β”‚   └── Implementations/          # 17 filter operators
    β”‚
    β”œβ”€β”€ Pipeline/                     # Pipeline orchestration
    β”‚   β”œβ”€β”€ Contracts/                # PipelineExecutionServiceInterface, etc.
    β”‚   β”œβ”€β”€ DTOs/                     # PipelineContext, StageResult, etc.
    β”‚   β”œβ”€β”€ Factories/                # ImportPipelineConfigFactory
    β”‚   β”œβ”€β”€ Orchestrators/            # Pipeline orchestrator
    β”‚   β”œβ”€β”€ Pipes/                    # 7 sequential pipes (see below)
    β”‚   β”œβ”€β”€ Services/                 # ExecutionService, SchedulingService, TestDataService
    β”‚   β”œβ”€β”€ ValueObjects/             # Pipeline value objects
    β”‚   └── Implementations/          # Concrete implementations
    β”‚
    β”œβ”€β”€ Prepare/                      # Data preparation
    β”‚   β”œβ”€β”€ Contracts/                # PrepareInterface
    β”‚   └── Services/                 # Preparation services
    β”‚
    β”œβ”€β”€ ImageDownloader/              # Image download handling
    β”‚
    β”œβ”€β”€ ImportDashboard/              # Dashboard service & repository
    β”‚   β”œβ”€β”€ ImportDashboardService.php
    β”‚   └── ImportPipelineRepository.php
    β”‚
    β”œβ”€β”€ Jobs/                         # Queue jobs (2)
    β”‚
    └── Providers/                    # Sub-service providers (5)
        β”œβ”€β”€ DownloaderServiceProvider.php
        β”œβ”€β”€ ReaderServiceProvider.php
        β”œβ”€β”€ FilterServiceProvider.php
        β”œβ”€β”€ PrepareServiceProvider.php
        └── PipelineServiceProvider.php

πŸ”„ Pipeline System

Each import pipeline consists of 7 sequential pipes that process data in order:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  1. Download │───▢│ 2. Read  │───▢│ 3. Filter  │───▢│  4. Map  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚   7. Save   │◀───│6. Prepare│◀───│5. Images Prep  β”‚β—€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Pipes

# Pipe File Description
1 DownloadPipe Pipeline/Pipes/DownloadPipe.php Fetches raw data from HTTP, FTP, or SFTP sources
2 ReadPipe Pipeline/Pipes/ReadPipe.php Parses raw data using configured reader (CSV/JSON/XML/YAML)
3 FilterPipe Pipeline/Pipes/FilterPipe.php Applies filter rules with AND/OR logic to include/exclude rows
4 MapPipe Pipeline/Pipes/MapPipe.php Maps source fields β†’ target fields via elaitech/data-mapper
5 ImagesPreparePipe Pipeline/Pipes/ImagesPreparePipe.php Processes image URLs β€” separators, index skipping, download modes
6 PreparePipe Pipeline/Pipes/PreparePipe.php Final prep β€” category resolution, VIN/stock ID generation
7 SavePipe Pipeline/Pipes/SavePipe.php Placeholder save β€” simulates create/update stats without persistence

Pipeline Configuration Steps (Stepper)

Pipelines are configured through an 8-step stepper wizard:

Order Step Enum Value Description
1 Basic Info basic-info Name, description, frequency, start time
2 Downloader Config downloader-config Protocol, URL, auth credentials
3 Reader Config reader-config Format, delimiter, encoding, root path
4 Filter Config filter-config Filter rules with operators and logic
5 Mapper Config mapper-config Field mappings with transformers
6 Images Prepare images-prepare-config Image handling settings
7 Prepare Config prepare-config Data preparation rules
8 Preview preview Review full configuration and test output

πŸ“Š Models

ImportPipeline

The core model representing an import pipeline definition.

Field Type Description
name string Pipeline display name
description string Optional description
target_id string Target identifier
is_active boolean Whether the pipeline is enabled
frequency ImportPipelineFrequency once, daily, weekly, monthly
start_time datetime Scheduled start time
last_executed_at datetime Last execution timestamp
next_execution_at datetime Next scheduled execution
created_by / updated_by int Audit tracking (auto-set)

Relationships: config(), executions(), logs(), creator(), updater()
Scopes: active(), scheduled()
Accessors: status (computed: active / inactive / needs_configuration)

ImportPipelineConfig

Stores per-step JSON configuration. Each pipeline has multiple config entries (one per stepper step).

ImportPipelineExecution

Tracks execution runs with status, timing, and result data.

Field Type Description
status ImportPipelineStatus pending, running, completed, failed, cancelled
started_at / completed_at datetime Timing brackets
total_rows / processed_rows int Row counts
success_rate decimal Percentage success
processing_time decimal Execution time in seconds
memory_usage int Memory consumed
error_message string Failure details
result_data array Detailed result payload

Helper Methods: markAsRunning(), markAsCompleted(), markAsFailed(), markAsCancelled(), addLog()

ImportPipelineLog

Per-stage log entries with level, message, and context.

ImportPipelineTemplate

Reusable pipeline configuration templates for quick setup.

βš™οΈ Services

Downloader

Implementation Protocol Key Features
HttpDownloader HTTP/HTTPS Headers, auth, SSL config, timeouts
FtpDownloader FTP Passive mode, directory listing
SftpDownloader SFTP Key-based auth, known hosts

Reader

Implementation Format Key Features
CsvReader CSV Delimiter, enclosure, escape, encoding, header row
JsonReader JSON Root path, nested object traversal
XmlReader XML Node path, attribute mapping
YamlReader YAML Root key extraction

Filter (17 Operators)

Built using the Template Method pattern via AbstractFilterOperator:

Category Operators
Equality equals, not_equals
String contains, not_contains, starts_with, ends_with
Numeric greater_than, less_than, between, not_between
Set in, not_in
Pattern regex, not_regex
Null is_null, is_not_null

Features:

  • Dot-notation field access for nested data
  • AND/OR logical grouping of rules
  • Case-sensitive/insensitive matching
  • Extensible via AbstractFilterOperator base class

Pipeline Services

Service Description
PipelineExecutionService Orchestrates full pipeline execution
PipelineSchedulingService Handles scheduled pipeline runs
PipelineTestDataService Provides test data for step testing
ImportPipelineConfigFactory Creates/updates step configurations

Dashboard Services

Service Description
ImportDashboardService Business logic for the dashboard UI
ImportPipelineRepository Data access layer for pipelines

πŸ“‹ Enums

ImportPipelineStatus

pending Β· running Β· completed Β· failed Β· cancelled

Methods: getLabel(), getDescription(), getColor(), isActive(), isFinished(), isSuccessful(), isFailed(), isCancelled()

ImportPipelineFrequency

once Β· daily Β· weekly Β· monthly

Methods: getLabel(), getDescription(), getOptions()

ImportPipelineStep

basic-info Β· downloader-config Β· reader-config Β· filter-config Β· mapper-config Β· images-prepare-config Β· prepare-config Β· preview

Methods: title(), description(), route(), order()

PipelineStage

Represents the runtime execution stage of a pipeline.

PipelineStatus

active Β· inactive Β· needs_configuration

ImageDownloadMode

Strategies for handling image downloads during pipeline execution.

βš™οΈ Configuration

The package publishes config/import-pipelines.php:

php artisan vendor:publish --tag=import-config

πŸ”§ Extending

Adding a Custom Downloader

  1. Create a class extending the abstract downloader
  2. Implement the required methods
  3. Register in DownloaderServiceProvider

Adding a Custom Reader

  1. Extend the abstract reader
  2. Implement parsing logic
  3. Register in ReaderServiceProvider

Adding a Custom Filter Operator

use Elaitech\Import\Services\Filter\Abstracts\AbstractFilterOperator;

final class CustomOperator extends AbstractFilterOperator
{
    public function getName(): string { return 'custom'; }
    public function getLabel(): string { return 'Custom Operator'; }
    public function getDescription(): string { return 'My custom filter logic'; }
    public function supportsValueType(mixed $value): bool { return true; }

    protected function doApply(mixed $dataValue, mixed $filterValue, array $options): bool
    {
        // Your logic here
        return $dataValue === $filterValue;
    }
}

Register it in FilterServiceProvider:

$registry->register(new CustomOperator());

Implementing Real Persistence (SavePipe)

Replace the placeholder SavePipe with your domain-specific save logic:

// In your custom SavePipe:
// 1. Receive prepared data from PreparePipe
// 2. Create/update your product models
// 3. Return statistics (created, updated, errors)

πŸ§ͺ Testing

# From the package directory
./vendor/bin/phpunit

# From the root project
php artisan test

πŸ“¦ Dependencies

Package Version Purpose
illuminate/support ^12.0 Laravel framework support
illuminate/database ^12.0 Eloquent ORM
illuminate/http ^12.0 HTTP handling
illuminate/queue ^12.0 Queue jobs
illuminate/console ^12.0 Artisan commands
spatie/laravel-activitylog ^4.11 Audit logging
spatie/laravel-data ^4.19 Typed DTOs
spatie/laravel-view-models ^1.6 View models
league/flysystem-ftp ^3.31 FTP filesystem
league/flysystem-sftp-v3 ^3.31 SFTP filesystem
symfony/yaml ^7.4 YAML parsing

πŸ“„ License

MIT β€” see LICENSE for details.