Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix/updating-bard-con…
Browse files Browse the repository at this point in the history
…figs-in-fieldsets
  • Loading branch information
duncanmcclean committed Nov 29, 2024
2 parents 1af9ac9 + 86fb0ca commit b244852
Show file tree
Hide file tree
Showing 35 changed files with 455 additions and 62 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ jobs:

strategy:
matrix:
php: [8.3, 8.2]
php: [8.2, 8.3, 8.4]
laravel: [10.*, 11.*]
statamic: [^5.0]
stability: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]
exclude:
- php: 8.4
laravel: 10.*

name: ${{ matrix.php }} - ${{ matrix.statamic }} - ${{ matrix.laravel }}
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}

steps:
- name: Checkout code
Expand All @@ -31,8 +34,8 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "statamic/cms:${{ matrix.statamic }}" --no-interaction --no-update
composer install --no-interaction
composer require "illuminate/contracts:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-suggest
- name: Run PHPUnit
run: vendor/bin/phpunit
run: vendor/bin/phpunit
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 1.4.1 (2024-11-21)

### What's fixed
* Fixed error when saving XML import #39 by @duncanmcclean



## 1.4.0 (2024-11-18)

### What's new
* Added support for Dictionary fields #37 by @duncanmcclean



## 1.3.0 (2024-11-12)

### What's new
* Allow selecting a folder for downloaded assets #31 by @duncanmcclean
* Made more strings translatable and fixed issue when string matches name of lang file #33 by @duncanmcclean
* JSON arrays now get parsed when importing relationships #32 by @duncanmcclean



## 1.2.0 (2024-11-08)

### What's new
Expand Down
2 changes: 2 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ When you're configuring mappings for an Assets field, or a Bard field, a few add
* **Download when missing?**
* By default, when the importer comes across an asset it can't find in Statamic, it will skip it.
* However, if you wish, the importer can download any missing assets for you into the configured asset container.
* **Folder**
* By default, downloaded assets will use same folder structure as the original URL. If you'd like to download them into a specific folder, you can select one here.
When importing a Bard field, assets will only be imported when the "Container" config option has been set in the blueprint.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
}
},
"require": {
"statamic/cms": "^5.0",
"statamic/cms": "^5.41",
"spatie/simple-excel": "^3.7",
"symfony/dom-crawler": "^7.1",
"pixelfear/composer-dist-plugin": "^0.1.5",
"laravel/framework": "11.*"
"symfony/css-selector": "^7.1"
},
"require-dev": {
"laravel/pint": "^1.18",
"orchestra/testbench": "^8.0 || ^9.5.6",
"phpunit/phpunit": "^10.0"
"orchestra/testbench": "^8.28 || ^9.6.1",
"phpunit/phpunit": "^10.5.35"
},
"config": {
"allow-plugins": {
Expand Down
27 changes: 26 additions & 1 deletion lang/en/messages.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
<?php

return [
'migrations_needed' => 'In order to keep track of import progress, the importer uses Laravel\'s Job Batching feature. It uses a <code>job_batches</code> table in your database to store information about batches. Before you can run the importer, you will need to run the <code>php artisan migrate</code> command.',
'utility_description' => 'Import entries, taxonomies, and users from XML and CSV files.',

'configuration_instructions' => 'You can add or modify your Blueprint fields to customize what data is imported and what fieldtype it will be stored in. You can save, refresh, and come back to this import config later until it\'s ready to run.',
'destination_collection_instructions' => 'Select the collection to import entries into.',
'destination_site_instructions' => 'Which site should the entries be imported into?',
'destination_taxonomy_instructions' => 'Select the taxonomy to import terms into.',
'destination_type_instructions' => 'Choose what type of data are you importing.',
'import_file_instructions' => 'Upload a CSV or XML file to import. This will replace the current file.',
'import_file_instructions_create' => 'Upload a CSV or XML file to import.',
'import_name_instructions' => 'Name this import so you can identify it later.',
'mapping_instructions' => 'Map the fields from your import to the fields in your blueprint.',
'migrations_needed' => 'In order to keep track of import progress, the importer uses Laravel\'s Job Batching feature. It uses a <code>job_batches</code> table in your database to store information about batches. Before you can run the importer, you will need to run the <code>php artisan migrate</code> command.',
'strategy_instructions' => 'Choose what should happen when importing.',
'unique_field_instructions' => 'Select a "unique field" to determine if an item already exists.',

'assets_base_url_instructions' => 'The base URL to prepend to the path.',
'assets_download_when_missing_instructions' => 'If the asset can\'t be found in the asset container, should it be downloaded?',
'assets_folder_instructions' => 'By default, downloaded assets will use same folder structure as the original URL. You can specify a different folder here.',
'assets_related_field_instructions' => 'Which field does the data reference?',
'entries_create_when_missing_instructions' => 'Create the entry if it doesn\'t exist.',
'entries_related_field_instructions' => 'Which field does the data reference?',
'terms_create_when_missing_instructions' => 'Create the term if it doesn\'t exist.',
'terms_related_field_instructions' => 'Which field does the data reference?',
'toggle_format_instructions' => 'How is the value stored?',
'toggle_values_instructions' => 'Specify the values that represent true and false in your data. You may separate multiple values with a pipe (`|`).',
'users_create_when_missing_instructions' => 'Create the user if it doesn\'t exist.',
'users_related_field_instructions' => 'Which field does the data reference?',

'csv_delimiter_instructions' => 'Specify the delimiter to be used when reading the CSV file. You will need to save the import for the options to be updated.',
];
9 changes: 9 additions & 0 deletions lang/en/validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

return [
'file_type_not_allowed' => 'Only CSV and XML files can be imported at this time.',
'mappings_not_provided' => 'You must map at least one field.',
'site_not_configured_in_collection' => 'The chosen collection is not available on this site.',
'unique_field_without_mapping' => 'Please configure a mapping for this field.',
'uploaded_file_not_found' => 'The uploaded file could not be found.',
];
4 changes: 2 additions & 2 deletions src/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function update(Request $request, Import $import)
'path' => $path,
'destination' => collect($values['destination'])->filter()->all(),
'strategy' => $values['strategy'],
'source' => $values['source'],
'source' => $values['source'] ?? null,
'mappings' => $values['mappings'],
'unique_field' => $values['unique_field'],
]));
Expand Down Expand Up @@ -213,7 +213,7 @@ private function createBlueprint(): Blueprint

$blueprint->ensureFieldHasConfig('file', [
'display' => __('File'),
'instructions' => __('Upload a CSV or XML file to import.'),
'instructions' => __('importer::messages.import_file_instructions_create'),
'required' => true,
]);

Expand Down
24 changes: 12 additions & 12 deletions src/Imports/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function getBlueprint(?Import $import = null): \Statamic\Fields\Bl
'field' => [
'type' => 'text',
'display' => __('Name'),
'instructions' => __('Name this import so you can identify it later.'),
'instructions' => __('importer::messages.import_name_instructions'),
'validate' => 'required',
],
],
Expand All @@ -43,7 +43,7 @@ public static function getBlueprint(?Import $import = null): \Statamic\Fields\Bl
'field' => [
'type' => 'files',
'display' => __('Upload a new file'),
'instructions' => __('Upload a CSV or XML file to import. This will replace the current file.'),
'instructions' => __('importer::messages.import_file_instructions'),
'max_files' => 1,
'allowed_extensions' => ['csv', 'xml'],
'validate' => [
Expand All @@ -57,11 +57,11 @@ function (string $attribute, mixed $value, Closure $fail) {
$path = "statamic/file-uploads/{$value[0]}";

if (! Storage::disk('local')->exists($path)) {
$fail('The uploaded file could not be found.')->translate();
$fail('importer::validation.file_type_not_allowed')->translate();
}

if (! in_array(Storage::disk('local')->mimeType($path), static::$allowedMimeTypes)) {
$fail('Only CSV and XML files can be imported at this time.')->translate();
$fail('importer::validation.uploaded_file_not_found')->translate();
}
},
],
Expand All @@ -80,7 +80,7 @@ function (string $attribute, mixed $value, Closure $fail) {
'field' => [
'type' => 'button_group',
'display' => __('Data Type'),
'instructions' => __('Choose what type of data are you importing.'),
'instructions' => __('importer::messages.destination_type_instructions'),
'width' => 50,
'options' => [
['key' => 'entries', 'value' => __('Entries')],
Expand All @@ -95,7 +95,7 @@ function (string $attribute, mixed $value, Closure $fail) {
'field' => [
'type' => 'collections',
'display' => __('Collection'),
'instructions' => __('Select the collection to import entries into.'),
'instructions' => __('importer::messages.destination_collection_instructions'),
'width' => 50,
'max_items' => 1,
'mode' => 'select',
Expand All @@ -108,7 +108,7 @@ function (string $attribute, mixed $value, Closure $fail) {
'field' => [
'type' => 'taxonomies',
'display' => __('Taxonomy'),
'instructions' => __('Select the taxonomy to import terms into.'),
'instructions' => __('importer::messages.destination_taxonomy_instructions'),
'width' => 50,
'max_items' => 1,
'mode' => 'select',
Expand All @@ -121,7 +121,7 @@ function (string $attribute, mixed $value, Closure $fail) {
'field' => [
'type' => 'sites',
'display' => __('Site'),
'instructions' => __('Which site should the entries be imported into?'),
'instructions' => __('importer::messages.destination_site_instructions'),
'width' => 50,
'max_items' => 1,
'mode' => 'select',
Expand All @@ -132,7 +132,7 @@ function (string $attribute, mixed $value, Closure $fail) {
$collection = Collection::find(Arr::get(request()->destination, 'collection.0'));

if (count($value) && ! $collection->sites()->contains($value[0])) {
$fail('The chosen collection is not available on this site.')->translate();
$fail('importer::validation.site_not_configured_in_collection')->translate();
}
},
],
Expand All @@ -146,7 +146,7 @@ function (string $attribute, mixed $value, Closure $fail) {
'field' => [
'type' => 'checkboxes',
'display' => __('Import Strategy'),
'instructions' => __('Choose what should happen when importing.'),
'instructions' => __('importer::messages.strategy_instructions'),
'options' => [
['key' => 'create', 'value' => __('Create new items')],
['key' => 'update', 'value' => __('Update existing items')],
Expand All @@ -173,7 +173,7 @@ function (string $attribute, mixed $value, Closure $fail) {
'array',
function (string $attribute, mixed $value, Closure $fail) {
if (collect($value)->reject(fn (array $mapping) => empty($mapping['key']))->isEmpty()) {
$fail('You must map at least one field.')->translate();
$fail('importer::validation.mappings_not_provided')->translate();
}
},
],
Expand All @@ -194,7 +194,7 @@ function (string $attribute, mixed $value, Closure $fail) {
'required',
function (string $attribute, mixed $value, Closure $fail) {
if (! collect(request()->mappings)->reject(fn ($mapping) => empty($mapping['key']))->has($value)) {
$fail('Please configure a mapping for this field.')->translate();
$fail('importer::validation.unique_field_without_mapping')->translate();
}
},
],
Expand Down
5 changes: 3 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

class ServiceProvider extends AddonServiceProvider
{
public array $transformers = [
protected array $transformers = [
'assets' => Transformers\AssetsTransformer::class,
'bard' => Transformers\BardTransformer::class,
'date' => Transformers\DateTransformer::class,
'dictionary' => Transformers\DictionaryTransformer::class,
'entries' => Transformers\EntriesTransformer::class,
'terms' => Transformers\TermsTransformer::class,
'toggle' => Transformers\ToggleTransformer::class,
Expand All @@ -38,7 +39,7 @@ public function bootAddon()
Utility::extend(function () {
Utility::register('importer')
->title(__('Importer'))
->description(__('Import entries, taxonomies, and users from XML and CSV files.'))
->description(__('importer::messages.utility_description'))
->icon('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m4.5 8.5 9.5 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="m4.5 11.5 6 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="m4.5 5.5 7 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="m4.5 14.5 4 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="m4.5 17.5 4 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="M10.5 23.5h-9a1 1 0 0 1 -1 -1v-21a1 1 0 0 1 1 -1h13.293a1 1 0 0 1 0.707 0.293L19.207 4.5a1 1 0 0 1 0.293 0.707V8.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="M11.5 17.5a6 6 0 1 0 12 0 6 6 0 1 0 -12 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="m17.5 14.5 0 6" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="m17.5 20.5 -2.25 -2.25" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path><path d="m17.5 20.5 2.25 -2.25" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"></path></svg>')
->action([ImportController::class, 'index'])
->routes(function ($router) {
Expand Down
2 changes: 1 addition & 1 deletion src/Sources/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function fieldItems(): array
return [
'csv_delimiter' => [
'display' => __('CSV Delimiter'),
'instructions' => __('Specify the delimiter to be used when reading the CSV file. You will need to save the import for the options to be updated.'),
'instructions' => __('importer::messages.csv_delimiter_instructions'),
'type' => 'text',
'default' => ',',
],
Expand Down
Loading

0 comments on commit b244852

Please sign in to comment.