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

Commit 2519c02

Browse files
authored
Merge pull request #11 from dchymko/main
Update array functions for Statamic 5 / Laravel 11
2 parents 55cc876 + dcc5cf3 commit 2519c02

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ You can use the events above to do your own downloading of images and what not.
5353
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:
5454

5555
``` bash
56-
composer require RadPack/statamic-wp-import
56+
composer require RadPack/wp-import
5757
```
5858

5959
## How to Use

src/Helpers/Migrator.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Statamic\Facades\Stache;
1313
use Statamic\Facades\Taxonomy;
1414
use Statamic\Facades\Term;
15+
use Statamic\Support\Arr;
1516
use Symfony\Component\HttpFoundation\File\UploadedFile;
1617

1718
class Migrator
@@ -59,7 +60,7 @@ private function prepareMigration($migration)
5960
{
6061
$migration['pages'] = collect(
6162
$this->sortDeepest(
62-
array_get($migration, 'pages', [])->all()
63+
Arr::get($migration, 'pages', [])->all()
6364
)
6465
);
6566

@@ -93,7 +94,7 @@ private function sortDeepest($arr)
9394
*/
9495
private function createTaxonomies()
9596
{
96-
foreach (array_get($this->migration, 'taxonomies', []) as $taxonomy_slug => $taxonomy_data) {
97+
foreach (Arr::get($this->migration, 'taxonomies', []) as $taxonomy_slug => $taxonomy_data) {
9798
$taxonomy = Taxonomy::findByHandle($taxonomy_slug);
9899

99100
if (! $taxonomy) {
@@ -115,7 +116,7 @@ private function createTaxonomies()
115116
*/
116117
private function createTaxonomyTerms()
117118
{
118-
foreach (array_get($this->migration, 'terms', []) as $taxonomy_slug => $terms) {
119+
foreach (Arr::get($this->migration, 'terms', []) as $taxonomy_slug => $terms) {
119120
foreach ($terms as $term_slug => $term_data) {
120121
// Skip if this term was not checked in the summary.
121122
if (! $this->summary['taxonomies'][$taxonomy_slug]['terms'][$term_slug]['_checked']) {
@@ -144,7 +145,7 @@ private function createTaxonomyTerms()
144145
*/
145146
private function createCollections()
146147
{
147-
foreach (array_get($this->migration, 'collections', []) as $handle => $data) {
148+
foreach (Arr::get($this->migration, 'collections', []) as $handle => $data) {
148149
$collection = Collection::findByHandle($handle);
149150

150151
if (! $collection) {
@@ -181,7 +182,7 @@ private function createEntries()
181182

182183
$entry->date($meta['order']);
183184

184-
array_set($meta, 'data.slug', $slug);
185+
Arr::set($meta, 'data.slug', $slug);
185186

186187
foreach ($meta['data'] as $key => $value) {
187188
$entry->set($key, $value);
@@ -222,7 +223,7 @@ private function createPages()
222223
$page = Entry::make()->collection('pages')->slug($slug);
223224
}
224225

225-
array_set($meta, 'data.slug', $slug);
226+
Arr::set($meta, 'data.slug', $slug);
226227

227228
foreach ($meta['data'] as $key => $value) {
228229
$page->set($key, $value);

src/Helpers/Preparer.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace RadPack\StatamicWpImport\Helpers;
44

55
use Statamic\Facades\URL;
6+
use Statamic\Support\Arr;
67
use Statamic\Support\Str;
78

89
class Preparer
@@ -85,7 +86,7 @@ private function createCollections()
8586
return;
8687
}
8788

88-
foreach (array_get($this->data, 'collections', []) as $name => $entries) {
89+
foreach (Arr::get($this->data, 'collections', []) as $name => $entries) {
8990
$this->createCollection($name, $entries);
9091
$this->createEntries($name, $entries);
9192
}
@@ -161,7 +162,7 @@ private function replaceTaxonomies($data)
161162
foreach ($value as $i => $slug) {
162163
// Replace the slug with the ID. If it's not found for whatever reason,
163164
// we'll just leave the slug as-is.
164-
$value[$i] = array_get($this->migration['terms'][$field_name]->get($slug), 'id', $slug);
165+
$value[$i] = Arr::get($this->migration['terms'][$field_name]->get($slug), 'id', $slug);
165166
}
166167

167168
if ($is_string) {

src/Helpers/WpImporter.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use Statamic\Facades\Entry;
77
use Statamic\Facades\Term;
8+
use Statamic\Support\Arr;
89

910
class WpImporter
1011
{
@@ -24,7 +25,7 @@ public function summary($prepared)
2425
foreach ($prepared['pages'] as $page_url => $page) {
2526
$summary['pages'][$page_url] = [
2627
'url' => $page_url,
27-
'title' => array_get($page['data'], 'title'),
28+
'title' => Arr::get($page['data'], 'title'),
2829
'exists' => (bool) Entry::findByUri($page_url),
2930
'_checked' => true,
3031
];

0 commit comments

Comments
 (0)