2

Without taking the time to explain the reason behind the requirement, I need to make about 3,000 empty entries.

How can I do this, that is how can I generate X number of entries without manually saving them from the admin area, outside of writing my own plugin? I don't think there's any good way to just write some SQL and barf them into existence right inside the database :(

Edit:

So I'm fairly certain this would have to be done via custom plugin development if it is indeed possible. I've never made a Craft plugin before, so I'm a little gunshy!

I imagine the structure of the plugin would be something like this:

public function onSaveEntry(Event $event)
{
    $title = $entry->title;

    for ( $i = $title; $i<8000; $i++)
    {
        do
        {
            public function saveEntry(EntryModel $entry)
        }
    }
}

Now, this is pseudo-code at best. I'm not sure what to exactly do here. But I hope this illustrates my thinking:

  • When I save a new entry, I want this thing to fire.
  • Right now my entries have auto-generated titles: take the last entry and add one: 5000 -> 5001 -> 5002, etc.
  • As long as we have less than 8000 entries (technically 3000 entries, as our entry titles will be 5000 - 8000) we want to keep saving new entries.
  • Once we finally save an entry with a title of 7999 or 8000, stop making entries.

Is this possible? What do I need to do?

Thank you soooo much to whoever out there can help me out!

1

Here are two approaches you could take:

Seed Plugins

  • Sprout Import - Sprout Import has features for both Seeding and Weeding seeded data. Sprout Import uses Faker to generate fake data and makes Faker available to you in your templates too. If you need to customize your fake data, the docs give an example of how you can generate fake data as a template, and then import that data. Sprout Import also has APIs to add support for custom Elements, Settings, and Fields if more customization is needed. When you add fake data with Sprout Import, you can mark is as "Seed Data" and later remove it from your Craft install from the Weed tab.
  • A&M Seed - I have not used A&M Seed but I believe it's the only other plugin I've seen that is built specifically for seeding.

Import Plugins

As described with Sprout Import above, another approach to generating fake data is to generate fake data in an appropriate format that can be imported using an import plugin. Sprout Import accommodates this use case out of the box, but there are a handful of other Import plugins that you could generate data for and import directly.

Sprout Import and the Craft-Faker plugin both give you a way to use Faker in your twig templates to help generate Fake data to import. Each import plugin may have it's own requirements as to what format that data should be in, but Craft enables you to create Twig templates with whatever file extension you prefer (.json, .xml, etc).

  • 1
    Yikes... I completely forgot about the Import plugin. Now I remember a few weeks ago planning on just making a CSV and importing it... lol. The struggle is real. Thanks for the insightful suggestions, though!! – Steven Thate Sep 29 '17 at 18:37
1

Or you could just use an existing seeding plugin like A&M Seed. :)

Even if it does do exactly what you're looking for, you can use it as a starting point for your plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.