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

Update array functions for Statamic 5 / Laravel 11 #11

Merged
merged 8 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ You can use the events above to do your own downloading of images and what not.
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:

``` bash
composer require RadPack/statamic-wp-import
composer require RadPack/wp-import
```

## How to Use
Expand Down
13 changes: 7 additions & 6 deletions src/Helpers/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Statamic\Facades\Stache;
use Statamic\Facades\Taxonomy;
use Statamic\Facades\Term;
use Statamic\Support\Arr;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class Migrator
Expand Down Expand Up @@ -59,7 +60,7 @@ private function prepareMigration($migration)
{
$migration['pages'] = collect(
$this->sortDeepest(
array_get($migration, 'pages', [])->all()
Arr::get($migration, 'pages', [])->all()
)
);

Expand Down Expand Up @@ -93,7 +94,7 @@ private function sortDeepest($arr)
*/
private function createTaxonomies()
{
foreach (array_get($this->migration, 'taxonomies', []) as $taxonomy_slug => $taxonomy_data) {
foreach (Arr::get($this->migration, 'taxonomies', []) as $taxonomy_slug => $taxonomy_data) {
$taxonomy = Taxonomy::findByHandle($taxonomy_slug);

if (! $taxonomy) {
Expand All @@ -115,7 +116,7 @@ private function createTaxonomies()
*/
private function createTaxonomyTerms()
{
foreach (array_get($this->migration, 'terms', []) as $taxonomy_slug => $terms) {
foreach (Arr::get($this->migration, 'terms', []) as $taxonomy_slug => $terms) {
foreach ($terms as $term_slug => $term_data) {
// Skip if this term was not checked in the summary.
if (! $this->summary['taxonomies'][$taxonomy_slug]['terms'][$term_slug]['_checked']) {
Expand Down Expand Up @@ -144,7 +145,7 @@ private function createTaxonomyTerms()
*/
private function createCollections()
{
foreach (array_get($this->migration, 'collections', []) as $handle => $data) {
foreach (Arr::get($this->migration, 'collections', []) as $handle => $data) {
$collection = Collection::findByHandle($handle);

if (! $collection) {
Expand Down Expand Up @@ -181,7 +182,7 @@ private function createEntries()

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

array_set($meta, 'data.slug', $slug);
Arr::set($meta, 'data.slug', $slug);

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

array_set($meta, 'data.slug', $slug);
Arr::set($meta, 'data.slug', $slug);

foreach ($meta['data'] as $key => $value) {
$page->set($key, $value);
Expand Down
5 changes: 3 additions & 2 deletions src/Helpers/Preparer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace RadPack\StatamicWpImport\Helpers;

use Statamic\Facades\URL;
use Statamic\Support\Arr;
use Statamic\Support\Str;

class Preparer
Expand Down Expand Up @@ -85,7 +86,7 @@ private function createCollections()
return;
}

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

if ($is_string) {
Expand Down
3 changes: 2 additions & 1 deletion src/Helpers/WpImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Statamic\Facades\Entry;
use Statamic\Facades\Term;
use Statamic\Support\Arr;

class WpImporter
{
Expand All @@ -24,7 +25,7 @@ public function summary($prepared)
foreach ($prepared['pages'] as $page_url => $page) {
$summary['pages'][$page_url] = [
'url' => $page_url,
'title' => array_get($page['data'], 'title'),
'title' => Arr::get($page['data'], 'title'),
'exists' => (bool) Entry::findByUri($page_url),
'_checked' => true,
];
Expand Down