goldfinch/harvest

Harvest is a seeder component that helps you to bundle automation run by Taz

Installs: 451

Dependents: 11

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

v2.0.2 2024-05-14 01:39 UTC

This package is auto-updated.

Last update: 2024-12-14 02:59:46 UTC


README

Silverstripe Version Package Version Total Downloads License

Harvest is a seeder component 🚟 that helps you to bundle automation run by Taz🌪️.

Install

composer require goldfinch/harvest

Available Taz commands

If you haven't used Taz🌪️ before, taz file must be presented in your root project folder cp vendor/goldfinch/taz/taz taz

Create new harvest

php taz make:harvest

List all available harvesters

php taz harvest

Run specific harvest

php taz harvest myharvest

Run all available harvesters

php taz harvest:all

Use Case example

Let's create a new harvest calling Pages that will handle Page Mill which will generate fake records for us by firing a single command.

1. Create new harvest

php taz make:harvest Pages
# What [short name] does this harvest need to be called by? : pages

After creating new harvest, we need to run dev/build to update harvest list

php taz dev/build

Now our harvest pages should be available in the harvest list, let's check that:

php taz harvest

2. Create new mill

As we decide that our harvest will manage mill factory, we need to create one. For more info about mills please refer to goldfinch/mill

php taz make:mill Page
# What [class name] does this mill is going to work with? : Page

Let's modify our Mill by adding some placeholder data:

namespace App\Mills;

use Goldfinch\Mill\Mill;

class PageMill extends Mill
{
    public function factory(): array
    {
        return [
            'Title' => $this->faker->catchPhrase(),
            'Content' => $this->faker->paragraph(20),
        ];
    }
}

We also need to make sure that Millable trait is added to Page class as it states in goldfinch/mill.

namespace {

    use Goldfinch\Mill\Traits\Millable;
    use SilverStripe\CMS\Model\SiteTree;

    class Page extends SiteTree
    {
        use Millable;

        private static $db = [];
    }
}

3. Prepare your harvest

Now we can go back to our PageHarvest that was created by Taz in the first step and add our mill to it.

namespace App\Harvest;

use Goldfinch\Harvest\Harvest;

class PagesHarvest extends Harvest
{
    public static function run(): void
    {
        \Page::mill(10)->make();
    }
}

4. Use harvest

Now our harvest is ready to rock along with Taz. By firing our harvest, we should get 10 newly generated pages in admin site tree.

php taz harvest pages

Recommendation

This module plays nicely with mill factory goldfinch/mill

License

The MIT License (MIT)