PHPackages                             wonderwp/import-foundation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wonderwp/import-foundation

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wonderwp/import-foundation
==========================

WonderWp ImportFoundation Component

1481↓50%PHP

Since Nov 18Pushed 6mo agoCompare

[ Source](https://github.com/wonderwp/import-foundation)[ Packagist](https://packagist.org/packages/wonderwp/import-foundation)[ RSS](/packages/wonderwp-import-foundation/feed)WikiDiscussions feature/definition Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

WonderWp Import Foundation
==========================

[](#wonderwp-import-foundation)

A robust and flexible import framework for WordPress applications built on the WonderWp ecosystem. This package provides a complete architecture for importing data from external sources into WordPress, with support for data transformation, synchronization, and dry-run capabilities.

Overview
--------

[](#overview)

The Import Foundation package implements a clean architecture pattern for data imports, separating concerns into distinct components:

- **Commands**: WP-CLI commands for executing imports
- **Importers**: Main orchestrators that coordinate the import process
- **Repositories**: Data access layer for source and destination
- **Transformers**: Data format conversion and normalization
- **Syncers**: Synchronization logic between source and destination
- **Persisters**: Data persistence layer
- **Requests/Responses**: Request/response handling for imports and syncs

Architecture Components
-----------------------

[](#architecture-components)

### 1. Commands (`src/Commands/`)

[](#1-commands-srccommands)

WP-CLI commands that provide the entry point for import operations.

#### `AbstractImporterCommand`

[](#abstractimportercommand)

Base class for all importer commands that:

- Extends `AbstractWpCliCommand` with dry-run support
- Provides standardized argument handling
- Manages logging and response output
- Requires implementation of `loadImporter()` method

**Key Features:**

- Built-in dry-run functionality
- Automatic timing and logging
- Standardized error handling
- Progress tracking

### 2. Importers (`src/Importers/`)

[](#2-importers-srcimporters)

The main orchestrators that coordinate the entire import process.

#### `AbstractImporter`

[](#abstractimporter)

Core importer class that implements the complete import workflow:

1. **Fetch source data** via `sourceRepository`
2. **Transform source data** via `sourceTransformer`
3. **Fetch destination data** via `destinationRepository`
4. **Transform destination data** via `destinationTransformer`
5. **Synchronize data** via `syncer`

**Constructor Dependencies:**

```
public function __construct(
    RepositoryInterface  $sourceRepository,
    TransformerInterface $sourceTransformer,
    RepositoryInterface  $destinationRepository,
    TransformerInterface $destinationTransformer,
    SyncerInterface      $syncer
)
```

### 3. Repositories (`src/Repositories/`)

[](#3-repositories-srcrepositories)

Data access layer that abstracts data retrieval operations.

#### `RepositoryInterface`

[](#repositoryinterface)

Extends the base WonderWp repository interface, providing:

- `find($id)` - Find single item by ID
- `findAll()` - Retrieve all items
- `findBy(array $criteria)` - Find items by criteria
- `findOneBy(array $criteria)` - Find single item by criteria

### 4. Transformers (`src/Transformers/`)

[](#4-transformers-srctransformers)

Data transformation layer that converts data between different formats.

#### `TransformerInterface`

[](#transformerinterface)

```
public function transform(WP_Post $post, bool $isDryRun): WP_Post
```

Transformers handle:

- Data format conversion
- Field mapping
- Data validation
- Normalization

### 5. Syncers (`src/Syncers/`)

[](#5-syncers-srcsyncers)

Synchronization logic that determines what data needs to be created, updated, or deleted.

#### `AbstractPostsSyncer`

[](#abstractpostssyncer)

Advanced syncer implementation that:

- Compares source and destination data
- Identifies differences using configurable indexes
- Supports post content, meta, and taxonomy comparison
- Provides detailed sync statistics

**Configurable Comparison Indexes:**

- `postComparisonIndexes` - Post fields to compare
- `postMetaComparisonIndexes` - Meta fields to compare
- `postTermsComparisonIndexes` - Taxonomy terms to compare

### 6. Persisters (`src/Persisters/`)

[](#6-persisters-srcpersisters)

Data persistence layer that handles saving data to the destination.

#### `WpPostPersister`

[](#wppostpersister)

WordPress-specific persister that:

- Creates new posts
- Updates existing posts
- Handles post meta and taxonomies
- Manages post status and visibility

### 7. Requests &amp; Responses (`src/Requests/`, `src/Responses/`)

[](#7-requests--responses-srcrequests-srcresponses)

Request/response objects for structured data handling.

#### Import Requests

[](#import-requests)

- `ImportRequest` - Standard import request with dry-run support
- `ImportRequestInterface` - Contract for import requests

#### Sync Requests

[](#sync-requests)

- `SyncRequest` - Synchronization request with source/destination data
- `SyncRequestInterface` - Contract for sync requests

#### Responses

[](#responses)

- `ImportResponse` - Import operation results
- `SyncResponse` - Synchronization operation results with detailed statistics

### 8. Resetters (`src/Resetters/`)

[](#8-resetters-srcresetters)

Data cleanup and reset functionality.

#### `AbstractPostResetter`

[](#abstractpostresetter)

Base class for resetting imported data:

- Removes imported posts
- Cleans up associated meta and taxonomies
- Provides safe reset operations

### 9. Exceptions (`src/Exceptions/`)

[](#9-exceptions-srcexceptions)

Custom exception classes for import operations.

- `ImportException` - General import errors
- `TransformException` - Data transformation errors

Usage Example
-------------

[](#usage-example)

### 1. Create Your Importer

[](#1-create-your-importer)

```
