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

Commit 7a4b3d8

Browse files
committed
Added option to skip existing images
Added import timer Refactored the setting of data to prevent complete rewrites
1 parent 9bfcaa8 commit 7a4b3d8

File tree

6 files changed

+93
-13
lines changed

6 files changed

+93
-13
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ return [
7979
*/
8080
'download_images' => true,
8181
82+
/*
83+
* Whether to skip download of an image if it already exist. The default is 'false'.
84+
*/
85+
'skip_existing_images' => false,
86+
8287
/*
8388
* Enable image overwriting. When set to false, a new image are created with a timestamp suffix, if the image already exists. The default is 'false'.
8489
*/

config/statamic-wp-import.php

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
*/
88
'download_images' => true,
99

10+
/*
11+
* Whether to skip download of an image if it already exist. The default is 'false'.
12+
*/
13+
'skip_existing_images' => false,
14+
1015
/*
1116
* Enable image overwriting. When set to false, a new image are created with a timestamp suffix, if the image already exists. The default is 'false'.
1217
*/

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

+28
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export default {
2020
showAllPages: false,
2121
showCollections: [],
2222
showTaxonomies: [],
23+
counter: null,
24+
hours: 0,
25+
minutes: 0,
26+
seconds: 0
2327
}
2428
},
2529
@@ -55,6 +59,8 @@ export default {
5559
5660
this.$progress.start('wp-import')
5761
62+
this.startTimer()
63+
5864
fetch(cp_url('wp-import/import'), {
5965
method: 'POST',
6066
headers: {
@@ -78,6 +84,8 @@ export default {
7884
7985
this.$progress.complete('wp-import')
8086
87+
this.stopTimer()
88+
8189
return response.json();
8290
}).then((data) => {
8391
console.log(data)
@@ -190,6 +198,26 @@ export default {
190198
}
191199
192200
return totalEntries
201+
},
202+
203+
startTimer () {
204+
this.minutes = this.checkSingleDigit(0)
205+
this.seconds = this.checkSingleDigit(0)
206+
207+
this.counter = setInterval(() => {
208+
const date = new Date(0, 0, 0, 0, 0, parseInt(this.seconds) + 1)
209+
this.hours = date.getHours()
210+
this.minutes = this.checkSingleDigit(date.getMinutes())
211+
this.seconds = this.checkSingleDigit(date.getSeconds())
212+
}, 1000)
213+
},
214+
215+
stopTimer () {
216+
clearInterval(this.counter)
217+
},
218+
219+
checkSingleDigit (digit) {
220+
return ('0' + digit).slice(-2)
193221
}
194222
}
195223
};

resources/views/summary.blade.php

+31-4
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,17 @@
140140
<div>
141141
<div class="card mb-3">
142142
<h2 class="mb-2">Importing</h2>
143-
<div class="loading loading-basic">
144-
<span class="icon icon-circular-graph animation-spin"></span> Please wait
143+
<div class="w-full flex justify-between items-center">
144+
<div class="loading loading-basic">
145+
<span class="icon icon-circular-graph animation-spin"></span> Please wait
146+
</div>
147+
<div class="flex text-grey-50 text-sm">
148+
<div v-show="hours > 0">@{{ hours }}</div>
149+
<div v-show="hours > 0">:</div>
150+
<div>@{{ minutes }}</div>
151+
<div>:</div>
152+
<div>@{{ seconds }}</div>
153+
</div>
145154
</div>
146155
</div>
147156
</div>
@@ -151,7 +160,16 @@
151160
<div>
152161
<div class="card mb-3">
153162
<h2 class="mb-2">Import complete</h2>
154-
<p>Import has completed</p>
163+
<div class="w-full flex justify-between items-center">
164+
<p>Import has completed</p>
165+
<div class="flex text-grey-50 text-sm">
166+
<div v-show="hours > 0">@{{ hours }}</div>
167+
<div v-show="hours > 0">:</div>
168+
<div>@{{ minutes }}</div>
169+
<div>:</div>
170+
<div>@{{ seconds }}</div>
171+
</div>
172+
</div>
155173
</div>
156174
</div>
157175
</template>
@@ -160,7 +178,16 @@
160178
<div>
161179
<div class="card">
162180
<h2 class="mb-2">Import failed</h2>
163-
<p>@{{ importError }}</p>
181+
<div class="w-full flex justify-between items-center">
182+
<p>@{{ importError }}</p>
183+
<div class="flex text-grey-50 text-sm">
184+
<div v-show="hours > 0">@{{ hours }}</div>
185+
<div v-show="hours > 0">:</div>
186+
<div>@{{ minutes }}</div>
187+
<div>:</div>
188+
<div>@{{ seconds }}</div>
189+
</div>
190+
</div>
164191
</div>
165192
</div>
166193
</template>

src/Helpers/Migrator.php

+23-8
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ private function createTaxonomies()
103103
$taxonomy = Taxonomy::make($taxonomy_slug);
104104
}
105105

106-
$taxonomy->data($taxonomy_data);
106+
foreach ($taxonomy_data as $key => $value) {
107+
$taxonomy->set($key, $value);
108+
}
107109

108110
$taxonomy->save();
109111
}
@@ -129,7 +131,11 @@ private function createTaxonomyTerms()
129131
$term = Term::make($term_slug)->taxonomy($taxonomy_slug);
130132
}
131133

132-
$term->data($term_data)->save();
134+
foreach ($term_data as $key => $value) {
135+
$term->set($key, $value);
136+
}
137+
138+
$term->save();
133139
}
134140
}
135141
}
@@ -177,9 +183,12 @@ private function createEntries()
177183
}
178184

179185
$entry->date($meta['order']);
180-
$entry->data(array_merge($meta['data'], [
181-
'slug' => $slug
182-
]));
186+
187+
array_set($meta, 'data.slug', $slug);
188+
189+
foreach ($meta['data'] as $key => $value) {
190+
$entry->set($key, $value);
191+
}
183192

184193
if (config('statamic-wp-import.download_images')) {
185194
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', $collection, $slug);
@@ -216,9 +225,11 @@ private function createPages()
216225
$page = Entry::make()->collection('pages')->slug($slug);
217226
}
218227

219-
$page->data(array_merge($meta['data'], [
220-
'slug' => $slug
221-
]));
228+
array_set($meta, 'data.slug', $slug);
229+
230+
foreach ($meta['data'] as $key => $value) {
231+
$page->set($key, $value);
232+
}
222233

223234
if (config('statamic-wp-import.download_images')) {
224235
$asset = $this->downloadAsset($meta['data']['featured_image_url'] ?? '', 'pages', $slug);
@@ -255,6 +266,10 @@ private function downloadAsset(string $url = null, string $collection, string $s
255266

256267
$asset = $assetContainer->makeAsset("{$collection}/{$slug}/{$originalImageName}");
257268

269+
if ($asset->exists() && config('statamic-wp-import.skip_existing_images')) {
270+
return $asset;
271+
}
272+
258273
if ($asset->exists() && config('statamic-wp-import.overwrite_images')) {
259274
$asset->delete();
260275
}

0 commit comments

Comments
 (0)