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

Commit 3c63dfc

Browse files
committed
Added config file
Added checkboxes to check/uncheck all
1 parent b104d0e commit 3c63dfc

File tree

7 files changed

+142
-69
lines changed

7 files changed

+142
-69
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ The summary will show you if anything was already found in your installation. If
6565

6666
Done :)
6767

68+
## Config
69+
70+
The content of the config file looks like this:
71+
72+
```
73+
<?php
74+
75+
return [
76+
77+
/*
78+
* Enable downloading of featured image. The default is 'true'.
79+
*/
80+
'download_images' => true,
81+
82+
/*
83+
* Filter out meta data keys prefixed with '_'. The default is 'true'.
84+
*/
85+
'exclude_underscore_data' => true,
86+
87+
];
88+
```
89+
90+
You can publish it with the command:
91+
92+
`php artisan vendor:publish --tag=statamic-wp-import`
93+
6894
## Known issues
6995

7096
You might get timeout errors if you're importing large datasets and/or many images. In that case you might want to tweak the timeouts on your server or run the import locally.

config/statamic-wp-import.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
* Enable downloading of featured image. The default is 'true'.
7+
*/
8+
'download_images' => true,
9+
10+
/*
11+
* Filter out meta data keys prefixed with '_'. The default is 'true'.
12+
*/
13+
'exclude_underscore_data' => true,
14+
15+
];

dist/js/addon.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/components/Importer.vue

+12
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ export default {
112112
});
113113
},
114114
115+
uncheckAll: function(items) {
116+
_.each(items, (item) => {
117+
item._checked = false;
118+
});
119+
},
120+
121+
checkAll: function(items) {
122+
_.each(items, (item) => {
123+
item._checked = true;
124+
});
125+
},
126+
115127
size: function (obj) {
116128
return _.size(obj);
117129
},

resources/views/summary.blade.php

+57-48
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="form-group">
2121
<div class="py-1.5 px-2 text-sm w-full rounded-md bg-yellow border border-yellow-dark mb-3" role="alert" v-if="hasDuplicates(summary.pages)">
2222
Duplicate items found
23-
<span class="text-xs ml-2">(<a @click.prevent="uncheckDuplicates(summary.pages)" href="#" class="text-blue hover:underline">Uncheck duplicates</a>)</span>
23+
<span class="text-xs ml-1">(<a @click.prevent="uncheckDuplicates(summary.pages)" href="#" class="text-blue hover:underline">Uncheck duplicates</a>)</span>
2424
</div>
2525

2626
<label>Entries</label>
@@ -30,21 +30,24 @@
3030
<a @click="showAllPages = false" v-else>Hide</a>
3131
</p>
3232

33-
<table class="w-full mt-2 mb-4" v-if="showAllPages">
34-
<thead>
35-
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1"></th>
36-
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1">URL</th>
37-
</thead>
38-
<tbody class="border-t border-grey-60">
39-
<tr v-for="(page, i) in summary.pages">
40-
<td class="px-2 py-1 w-4" :class="{ 'bg-yellow': page.exists }">
41-
<input type="checkbox" v-model="page._checked" id="page-@{{ i }}" />
42-
<label for="page-@{{ i }}"></label>
43-
</td>
44-
<td class="px-2 py-1 text-xs" :class="{ 'bg-yellow': page.exists }">@{{ page.url }}</td>
45-
</tr>
46-
</tbody>
47-
</table>
33+
<div v-show="showAllPages">
34+
<a @click.prevent="uncheckAll(summary.pages)" href="#" class="text-xs text-blue hover:underline">Uncheck all</a> / <a @click.prevent="checkAll(summary.pages)" href="#" class="text-xs text-blue hover:underline">Check all</a>
35+
<table class="w-full mt-2 mb-4">
36+
<thead>
37+
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1"></th>
38+
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1">URL</th>
39+
</thead>
40+
<tbody class="border-t border-grey-60">
41+
<tr v-for="(page, i) in summary.pages">
42+
<td class="px-2 py-1 w-4" :class="{ 'bg-yellow': page.exists }">
43+
<input type="checkbox" v-model="page._checked" id="page-@{{ i }}" />
44+
<label for="page-@{{ i }}"></label>
45+
</td>
46+
<td class="px-2 py-1 text-xs" :class="{ 'bg-yellow': page.exists }">@{{ page.url }}</td>
47+
</tr>
48+
</tbody>
49+
</table>
50+
</div>
4851
</div>
4952
</div>
5053

@@ -57,7 +60,7 @@
5760
<div class="form-group">
5861
<div class="py-1.5 px-2 text-sm w-full rounded-md bg-yellow border border-yellow-dark mb-3" role="alert" v-if="hasDuplicates(collection.entries)">
5962
Duplicate items found
60-
<span class="text-xs ml-2">(<a @click.prevent="uncheckDuplicates(collection.entries)" href="#" class="text-blue hover:underline">Uncheck duplicates</a>)</span>
63+
<span class="text-xs ml-1">(<a @click.prevent="uncheckDuplicates(collection.entries)" href="#" class="text-blue hover:underline">Uncheck duplicates</a>)</span>
6164
</div>
6265

6366
<label>Entries</label>
@@ -67,21 +70,24 @@
6770
<a href="#" @click.prevent="hideCollection(collectionName)" v-else>Hide</a>
6871
</p>
6972

70-
<table class="w-full mt-2 mb-4" v-show="shouldShowCollection(collectionName)">
71-
<thead>
72-
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1"></th>
73-
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1">Slug</th>
74-
</thead>
75-
<tbody class="border-t border-grey-60">
76-
<tr v-for="(entry, slug) in collection.entries">
77-
<td class="px-2 py-1 w-4" :class="{ 'bg-yellow': entry.exists }">
78-
<input type="checkbox" v-model="entry._checked" id="c-@{{ collectionName }}-@{{ slug }}" />
79-
<label for="c-@{{ collectionName }}-@{{ slug }}"></label>
80-
</td>
81-
<td class="px-2 py-1 text-xs" :class="{ 'bg-yellow': entry.exists }">@{{ entry.slug }}</td>
82-
</tr>
83-
</tbody>
84-
</table>
73+
<div v-show="shouldShowCollection(collectionName)">
74+
<a @click.prevent="uncheckAll(collection.entries)" href="#" class="text-xs text-blue hover:underline">Uncheck all</a> / <a @click.prevent="checkAll(collection.entries)" href="#" class="text-xs text-blue hover:underline">Check all</a>
75+
<table class="w-full mt-2 mb-4">
76+
<thead>
77+
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1"></th>
78+
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1">Slug</th>
79+
</thead>
80+
<tbody class="border-t border-grey-60">
81+
<tr v-for="(entry, slug) in collection.entries">
82+
<td class="px-2 py-1 w-4" :class="{ 'bg-yellow': entry.exists }">
83+
<input type="checkbox" v-model="entry._checked" id="c-@{{ collectionName }}-@{{ slug }}" />
84+
<label for="c-@{{ collectionName }}-@{{ slug }}"></label>
85+
</td>
86+
<td class="px-2 py-1 text-xs" :class="{ 'bg-yellow': entry.exists }">@{{ entry.slug }}</td>
87+
</tr>
88+
</tbody>
89+
</table>
90+
</div>
8591
</div>
8692
</div>
8793

@@ -94,7 +100,7 @@
94100
<div class="form-group">
95101
<div class="py-1.5 px-2 text-sm w-full rounded-md bg-yellow border border-yellow-dark mb-3" role="alert" v-if="hasDuplicates(taxonomy.terms)">
96102
Duplicate items found
97-
<span class="text-xs ml-2">(<a @click.prevent="uncheckDuplicates(taxonomy.terms)" href="#" class="text-blue hover:underline">Uncheck duplicates</a>)</span>
103+
<span class="text-xs ml-1">(<a @click.prevent="uncheckDuplicates(taxonomy.terms)" href="#" class="text-blue hover:underline">Uncheck duplicates</a>)</span>
98104
</div>
99105
<label>Terms</label>
100106
<p>
@@ -103,21 +109,24 @@
103109
<a href="#" @click.prevent="hideTaxonomy(taxonomyName)" v-else>Hide</a>
104110
</p>
105111

106-
<table class="w-full mt-2 mb-4" v-if="shouldShowTaxonomy(taxonomyName)">
107-
<thead>
108-
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1 w-4"></th>
109-
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1">Slug</th>
110-
</thead>
111-
<tbody class="border-t border-grey-60">
112-
<tr v-for="(term, slug) in taxonomy.terms">
113-
<td class="px-2 py-1 w-4" :class="{ 'bg-yellow': term.exists }">
114-
<input type="checkbox" v-model="term._checked" id="t-@{{ taxonomyName }}-@{{ slug }}" />
115-
<label for="t-@{{ taxonomyName }}-@{{ slug }}"></label>
116-
</td>
117-
<td class="px-2 py-1 text-xs" :class="{ 'bg-yellow': term.exists }">@{{ term.slug }}</td>
118-
</tr>
119-
</tbody>
120-
</table>
112+
<div v-show="shouldShowTaxonomy(taxonomyName)">
113+
<a @click.prevent="uncheckAll(taxonomy.terms)" href="#" class="text-xs text-blue hover:underline">Uncheck all</a> / <a @click.prevent="checkAll(taxonomy.terms)" href="#" class="text-xs text-blue hover:underline">Check all</a>
114+
<table class="w-full mt-2 mb-4">
115+
<thead>
116+
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1 w-4"></th>
117+
<th class="text-left uppercase text-grey-60 text-xs px-2 py-1">Slug</th>
118+
</thead>
119+
<tbody class="border-t border-grey-60">
120+
<tr v-for="(term, slug) in taxonomy.terms">
121+
<td class="px-2 py-1 w-4" :class="{ 'bg-yellow': term.exists }">
122+
<input type="checkbox" v-model="term._checked" id="t-@{{ taxonomyName }}-@{{ slug }}" />
123+
<label for="t-@{{ taxonomyName }}-@{{ slug }}"></label>
124+
</td>
125+
<td class="px-2 py-1 text-xs" :class="{ 'bg-yellow': term.exists }">@{{ term.slug }}</td>
126+
</tr>
127+
</tbody>
128+
</table>
129+
</div>
121130
</div>
122131
</div>
123132

src/Helpers/Migrator.php

+28-19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Jezzdk\StatamicWpImport\Helpers;
44

5+
use Exception;
56
use Illuminate\Support\Facades\Storage;
67
use Statamic\Assets\Asset;
78
use Statamic\Facades\AssetContainer;
@@ -179,10 +180,12 @@ private function createEntries()
179180
'slug' => $slug
180181
]));
181182

182-
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', $collection);
183+
if (config('statamic-wp-import.download_images')) {
184+
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', $collection);
183185

184-
if ($asset) {
185-
$entry->set('featured_image', $asset->path());
186+
if ($asset) {
187+
$entry->set('featured_image', $asset->path());
188+
}
186189
}
187190

188191
$entry->save();
@@ -216,10 +219,12 @@ private function createPages()
216219
'slug' => $slug
217220
]));
218221

219-
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', 'pages');
222+
if (config('statamic-wp-import.download_images')) {
223+
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', 'pages');
220224

221-
if ($asset) {
222-
$page->set('image', $asset->path());
225+
if ($asset) {
226+
$page->set('featured_image', $asset->path());
227+
}
223228
}
224229

225230
$page->save();
@@ -238,23 +243,27 @@ private function downloadAsset(string $url = null, string $container): Asset|boo
238243
return false;
239244
}
240245

241-
$image = file_get_contents($url);
242-
$originalImageName = basename($url);
246+
try {
247+
$image = @file_get_contents($url);
248+
$originalImageName = basename($url);
243249

244-
Storage::put($tempFile = 'temp', $image);
250+
Storage::put($tempFile = 'temp', $image);
245251

246-
$assetContainer = AssetContainer::findByHandle('assets');
252+
$assetContainer = AssetContainer::findByHandle('assets');
247253

248-
$asset = $assetContainer->makeAsset("imports/{$container}/{$originalImageName}")
249-
->upload(
250-
new UploadedFile(
251-
Storage::path($tempFile),
252-
$originalImageName,
253-
)
254-
);
254+
$asset = $assetContainer->makeAsset("imports/{$container}/{$originalImageName}")
255+
->upload(
256+
new UploadedFile(
257+
Storage::path($tempFile),
258+
$originalImageName,
259+
)
260+
);
255261

256-
$asset->save();
262+
$asset->save();
257263

258-
return $asset;
264+
return $asset;
265+
} catch (Exception $e) {
266+
return false;
267+
}
259268
}
260269
}

src/Helpers/Preparer.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public function prepare(array $data)
3131
$this->createTaxonomies();
3232
$this->createCollections();
3333

34-
$this->filterMetaData();
34+
if (config('statamic-wp-import.exclude_underscore_data')) {
35+
$this->filterMetaData();
36+
}
3537

3638
return $this->migration;
3739
}

0 commit comments

Comments
 (0)