Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit deafa1b

Browse files
committed
Cleanup
1 parent c1523a8 commit deafa1b

File tree

9 files changed

+69
-70
lines changed

9 files changed

+69
-70
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Note: This addon works in conjunction with a [Wordpress plugin](https://github.c
66

77
## Note
88

9-
This is a rough addon the Rad Pack inherited from @jezzdk. We're open to PRs and collaboration, though the Statamic Core Team is working on a different approach that might replace this in the near(ish) future.
9+
This is a rough addon the Rad Pack inherited from [@jezzdk](https://github.com/jezzdk). It's based on the v2 method of generating a JSON file with a separate WP plugin, which isn't ideal, but should still be functional.
10+
11+
We're open to PRs and collaboration, though the Statamic Core Team is working on a different approach that will likely replace this in the near future.
1012

1113

1214
## Features
@@ -51,12 +53,12 @@ You can use the events above to do your own downloading of images and what not.
5153
You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root:
5254

5355
``` bash
54-
composer require jezzdk/statamic-wp-import
56+
composer require RadPack/statamic-wp-import
5557
```
5658

5759
## How to Use
5860

59-
First of all, you must export your data using the [Export to Statamic Wordpress Plugin](https://github.com/jezzdk/wordpress-to-statamic-exporter). Check anything you wish to export, but have the notes above in mind.
61+
First of all, you must export your data using the [Export to Statamic Wordpress Plugin](https://github.com/RadPack/wordpress-to-statamic-exporter). Check anything you wish to export, but have the notes above in mind.
6062

6163
Go to the `Tools > WP Import` section and upload the json file.
6264

@@ -105,7 +107,7 @@ return [
105107

106108
You can publish it with the command:
107109

108-
`php artisan vendor:publish --tag=statamic-wp-import`
110+
`php artisan vendor:publish --tag=wp-import`
109111

110112
## Known issues
111113

composer.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
{
2-
"name": "jezzdk/statamic-wp-import",
2+
"name": "statamic-rad-pack/wp-import",
33
"autoload": {
44
"psr-4": {
5-
"Jezzdk\\StatamicWpImport\\": "src"
5+
"RadPack\\StatamicWpImport\\": "src"
66
}
77
},
88
"authors": [
99
{
1010
"name": "Jess Stopa"
1111
}
1212
],
13-
"support": {
14-
"email": "[email protected]"
15-
},
1613
"extra": {
1714
"statamic": {
1815
"name": "Statamic WP Import",
1916
"description": "Import Wordpress content into Statamic"
2017
},
2118
"laravel": {
2219
"providers": [
23-
"Jezzdk\\StatamicWpImport\\ServiceProvider"
20+
"RadPack\\StatamicWpImport\\ServiceProvider"
2421
]
2522
}
2623
}

resources/views/upload.blade.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44

55
@section('content')
66

7-
<header class="mb-3"><h1>WP Import</h1></header>
7+
<header class="mb-6">
8+
<h1>WP Import</h1>
9+
</header>
810

9-
<div class="card p-2 content">
11+
<div class="card p-4 content">
1012
<form action="{{ cp_route('wp-import.upload') }}" method="POST" enctype="multipart/form-data">
1113
{{ csrf_field() }}
12-
<h2 class="font-bold">JSON file</h2>
13-
<p class="text-grey text-sm my-1">Upload the JSON file you have exported with the official <a href="https://github.com/statamic/wordpress-to-statamic-exporter" target="_blank">WordPress plugin</a>.</p>
14-
<div class="flex justify-between items-center">
15-
<div class="pr-4">
16-
<input type="file" class="form-control" name="file" />
17-
</div>
14+
<h2 class="font-bold">Upload</h2>
15+
<p class="text-grey text-sm my-1">Upload the JSON file you have exported with <a href="https://github.com/jezzdk/wordpress-to-statamic-exporter" target="_blank">this WordPress plugin</a>.</p>
16+
<div class="flex space-x-3 items-center mt-3">
17+
<input type="file" class="border rounded px-3 py-2 text-sm w-full" name="file" />
1818
<div>
1919
<button type="submit" class="btn btn-primary">Import</button>
2020
</div>
2121
</div>
2222
</form>
2323
</div>
2424

25-
@endsection
25+
@include('statamic::partials.docs-callout', [
26+
'topic' => __('this addon'),
27+
'url' => 'https://statamic.com/addons/rad-pack/wp-import'
28+
])
29+
30+
@endsection

routes/cp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Illuminate\Support\Facades\Route;
4-
use Jezzdk\StatamicWpImport\Http\Controllers\ImportController;
4+
use RadPack\StatamicWpImport\Http\Controllers\ImportController;
55

66
Route::group(['prefix' => 'wp-import'], function () {
77
Route::get('/', [ImportController::class, 'index'])->name('wp-import.index');

src/Helpers/Migrator.php

+17-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Jezzdk\StatamicWpImport\Helpers;
3+
namespace RadPack\StatamicWpImport\Helpers;
44

55
use Exception;
66
use Illuminate\Support\Facades\Http;
@@ -10,8 +10,8 @@
1010
use Statamic\Facades\Collection;
1111
use Statamic\Facades\Entry;
1212
use Statamic\Facades\Stache;
13-
use Statamic\Facades\Term;
1413
use Statamic\Facades\Taxonomy;
14+
use Statamic\Facades\Term;
1515
use Symfony\Component\HttpFoundation\File\UploadedFile;
1616

1717
class Migrator
@@ -32,9 +32,6 @@ class Migrator
3232

3333
/**
3434
* Perform the migration
35-
*
36-
* @param $migration
37-
* @param $summary
3835
*/
3936
public function migrate($migration, $summary)
4037
{
@@ -55,7 +52,7 @@ public function migrate($migration, $summary)
5552
/**
5653
* Prepare the migration
5754
*
58-
* @param array $migration
55+
* @param array $migration
5956
* @return array
6057
*/
6158
private function prepareMigration($migration)
@@ -72,8 +69,8 @@ private function prepareMigration($migration)
7269
/**
7370
* Sort an array by folder depth (amount of slashes)
7471
*
75-
* @param array $arr An array with paths for keys
76-
* @return array The sorted array
72+
* @param array $arr An array with paths for keys
73+
* @return array The sorted array
7774
*/
7875
private function sortDeepest($arr)
7976
{
@@ -99,7 +96,7 @@ private function createTaxonomies()
9996
foreach (array_get($this->migration, 'taxonomies', []) as $taxonomy_slug => $taxonomy_data) {
10097
$taxonomy = Taxonomy::findByHandle($taxonomy_slug);
10198

102-
if (!$taxonomy) {
99+
if (! $taxonomy) {
103100
$taxonomy = Taxonomy::make($taxonomy_slug);
104101
}
105102

@@ -121,13 +118,13 @@ private function createTaxonomyTerms()
121118
foreach (array_get($this->migration, 'terms', []) as $taxonomy_slug => $terms) {
122119
foreach ($terms as $term_slug => $term_data) {
123120
// Skip if this term was not checked in the summary.
124-
if (!$this->summary['taxonomies'][$taxonomy_slug]['terms'][$term_slug]['_checked']) {
121+
if (! $this->summary['taxonomies'][$taxonomy_slug]['terms'][$term_slug]['_checked']) {
125122
continue;
126123
}
127124

128125
$term = Term::findBySlug($term_slug, $taxonomy_slug);
129126

130-
if (!$term) {
127+
if (! $term) {
131128
$term = Term::make($term_slug)->taxonomy($taxonomy_slug);
132129
}
133130

@@ -150,7 +147,7 @@ private function createCollections()
150147
foreach (array_get($this->migration, 'collections', []) as $handle => $data) {
151148
$collection = Collection::findByHandle($handle);
152149

153-
if (!$collection) {
150+
if (! $collection) {
154151
$collection = Collection::make($handle);
155152
}
156153

@@ -172,13 +169,13 @@ private function createEntries()
172169
foreach ($this->migration['entries'] as $collection => $entries) {
173170
foreach ($entries as $slug => $meta) {
174171
// Skip if this entry was not checked in the summary.
175-
if (!$this->summary['collections'][$collection]['entries'][$slug]['_checked']) {
172+
if (! $this->summary['collections'][$collection]['entries'][$slug]['_checked']) {
176173
continue;
177174
}
178175

179176
$entry = Entry::query()->where('collection', $collection)->where('slug', $slug)->first();
180177

181-
if (!$entry) {
178+
if (! $entry) {
182179
$entry = Entry::make()->collection($collection)->slug($slug);
183180
}
184181

@@ -212,7 +209,7 @@ private function createPages()
212209
{
213210
foreach ($this->migration['pages'] as $url => $meta) {
214211
// Skip if this page was not checked in the summary.
215-
if (!$this->summary['pages'][$url]['_checked']) {
212+
if (! $this->summary['pages'][$url]['_checked']) {
216213
continue;
217214
}
218215

@@ -221,7 +218,7 @@ private function createPages()
221218

222219
$page = Entry::query()->where('collection', 'pages')->where('slug', $slug)->first();
223220

224-
if (!$page) {
221+
if (! $page) {
225222
$page = Entry::make()->collection('pages')->slug($slug);
226223
}
227224

@@ -245,13 +242,10 @@ private function createPages()
245242

246243
/**
247244
* Create an asset from a URL
248-
*
249-
* @param string|null $url
250-
* @return Asset|bool
251245
*/
252-
private function downloadAsset(string $url = null, string $collection, string $slug): Asset|bool
246+
private function downloadAsset(?string $url, string $collection, string $slug): Asset|bool
253247
{
254-
if (!$url) {
248+
if (! $url) {
255249
return false;
256250
}
257251

@@ -285,7 +279,8 @@ private function downloadAsset(string $url = null, string $collection, string $s
285279

286280
return $asset;
287281
} catch (Exception $e) {
288-
logger('Image download failed: ' . $e->getMessage());
282+
logger('Image download failed: '.$e->getMessage());
283+
289284
return false;
290285
}
291286
}

src/Helpers/Preparer.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<?php
22

3-
namespace Jezzdk\StatamicWpImport\Helpers;
3+
namespace RadPack\StatamicWpImport\Helpers;
44

55
use Statamic\Facades\URL;
66
use Statamic\Support\Str;
77

88
class Preparer
99
{
1010
private $data;
11+
1112
private $migration = [];
1213

1314
public function prepare(array $data)
1415
{
1516
$this->data = $data;
1617

17-
if (!isset($this->data['pages']) || !is_array($this->data['pages'])) {
18+
if (! isset($this->data['pages']) || ! is_array($this->data['pages'])) {
1819
$this->data['pages'] = [];
1920
}
2021

@@ -53,14 +54,14 @@ protected function filterMetaData()
5354

5455
private function createTaxonomies()
5556
{
56-
if (!isset($this->data['taxonomies'])) {
57+
if (! isset($this->data['taxonomies'])) {
5758
return;
5859
}
5960

6061
foreach ($this->data['taxonomies'] as $taxonomy_name => $terms) {
6162
$this->migration['taxonomies']->put($taxonomy_name, [
6263
'title' => Str::title($taxonomy_name),
63-
'route' => '/' . $taxonomy_name . '/{slug}'
64+
'route' => '/'.$taxonomy_name.'/{slug}',
6465
]);
6566

6667
$this->migration['terms']->put($taxonomy_name, collect());
@@ -80,7 +81,7 @@ private function createTaxonomies()
8081

8182
private function createCollections()
8283
{
83-
if (!isset($this->data['collections'])) {
84+
if (! isset($this->data['collections'])) {
8485
return;
8586
}
8687

@@ -93,13 +94,13 @@ private function createCollections()
9394
/**
9495
* Create a collection
9596
*
96-
* @param string $collection
97+
* @param string $collection
9798
* @param array $entries
9899
* @return void
99100
*/
100101
private function createCollection($collection, $entries)
101102
{
102-
$route = '/' . $collection . '/{slug}';
103+
$route = '/'.$collection.'/{slug}';
103104

104105
$collection = str_replace('/', '-', $collection);
105106

@@ -116,7 +117,7 @@ private function createCollection($collection, $entries)
116117

117118
$this->migration['collections']->put($collection, [
118119
'order' => $type,
119-
'route' => $route
120+
'route' => $route,
120121
]);
121122

122123
$this->migration['entries']->put($collection, collect());
@@ -125,7 +126,7 @@ private function createCollection($collection, $entries)
125126
/**
126127
* Create the entries in a collection
127128
*
128-
* @param string $collection
129+
* @param string $collection
129130
* @param array $entries
130131
* @return void
131132
*/
@@ -141,13 +142,13 @@ private function createEntries($collection, $entries)
141142
/**
142143
* Replace slugs in taxonomy fields with their IDs
143144
*
144-
* @param array $data The array of data to modify
145-
* @return array The modified array
145+
* @param array $data The array of data to modify
146+
* @return array The modified array
146147
*/
147148
private function replaceTaxonomies($data)
148149
{
149150
foreach ($data as $field_name => &$value) {
150-
if (!$this->isTaxonomyField($field_name)) {
151+
if (! $this->isTaxonomyField($field_name)) {
151152
continue;
152153
}
153154

@@ -175,7 +176,7 @@ private function replaceTaxonomies($data)
175176
* Is a given $key a taxonomy field name?
176177
*
177178
* @param string $key
178-
* @return boolean
179+
* @return bool
179180
*/
180181
private function isTaxonomyField($key)
181182
{

0 commit comments

Comments
 (0)