445

Product support

Get help in the plugin support forum.

Categories

This is a helper plugin to simplify the import of data from PHP, YAML and XML files. It will not do anything on its own, you need to extend the plugin Import class from your own plugins as described on the documentation.

You need to create your own import class like this:

<?php namespace YourNamespace\YourPlugin\Classes;

use Utopigs\Import\Classes\Import as BaseImport;

class Import extends BaseImport
{
    public function __construct()
    {
        $this->path = base_path('import/');
    }

    public function importCategories()
    {
        $result = $this->loadImportFile('categories.yaml');

        $this->importModel('\YourNamespace\YourPlugin\Models\Category', $result);
    }

    public function importTags()
    {
        $result = $this->loadImportFile('tags.yaml');

        $this->importModel('\YourNamespace\YourPlugin\Models\Tag', $result);
    }

    public function importPosts()
    {
        $result = $this->loadImportFile('posts.yaml');

        $this->importModel('\YourNamespace\YourPlugin\Models\Post', $result, ['tags'], ['image']);
    }
}

Check the documentation in the plugin Utopigs\Import\Classes\Import class for information about the available parameters for this methods. If you need more advanced import options, you can copy the code in your own import class and modify it as needed.

In your website root folder you should have an 'import' folder with this content:

categories.yaml:

- title: 'Category 1'
- title: 'Category 2'

tags.yaml:

  • title: 'Tag 1'
  • title: 'Tag 2'
  • title: 'Tag 3'
  • title: 'Tag 4'

posts.yaml:

    title: 'Post 1 title'
    text: >
        <p>Some html text</p>
        <p>More text</p>
    category_id: 1
    tags: [1,2,3]
    image: 'post1-picture.jpg'
-
    title: 'Post 2 title'
    text: >
        <p>Some html text</p>
        <p>More text</p>
    category_id: 2
    tags: [1,2,3]
    image: 'post2-picture.jpg'

Then you can import your data like this:

$import = new \YourNamespace\YourPlugin\Classes\Import;
$import->importCategories();
$import->importTags();
$import->importPosts();
1.0.5

Validate that import path is set

Mar 12, 2024

1.0.4

Fixes in demo data import for October CMS 3.6

Mar 10, 2024

1.0.3

Fix composer.json

Dec 04, 2023

1.0.2

Fix version number format for OctoberCMS v3

Dec 04, 2023

1.0.1

Add option to load theme settings

Oct 07, 2020

1.0.0

Import plugin

Jun 26, 2020