Closed sjelfull closed 5 years ago
You can use the Console helper's start/update/endProgress methods.
start/update/endProgress
Example:
public function generate( $section = null, $count ) { if(ctype_digit($section)) { $section = Craft::$app->sections->getSectionById( (int) $section ); } else { $section = Craft::$app->sections->getSectionByHandle($section); } if(!$section) { echo "Section not found\n"; return false; } $faker = Factory::create(); $entryTypes = $section->getEntryTypes(); $current = 1; $total = count($entryTypes) * $count; Console::startProgress($current, $count); foreach ( $entryTypes as $entryType ) { for ( $x = 1; $x <= $count; $x ++ ) { $current++; Console::updateProgress($current, $count); $typeFields = Craft::$app->fields->getFieldsByLayoutId( $entryType->getFieldLayoutId() ); $entry = new Entry( [ 'sectionId' => (int) $section->id, 'typeId' => $entryType->id, 'title' => Seeder::$plugin->fields->Title(), ] ); Craft::$app->getElements()->saveElement( $entry ); $entry = Seeder::$plugin->seeder->populateFields( $typeFields, $entry ); Craft::$app->getElements()->saveElement( $entry ); $entry->id; Seeder::$plugin->seeder->saveSeededEntry($entry); } } Console::endProgress(); return $section->name; }
This is neat, thanks for the suggestion @sjelfull! Adding it to all the things :)
Finally got around to releasing this, out in 3.0.1!
You can use the Console helper's
start/update/endProgress
methods.Example: