Create the Seeder

@throws \Exception
@return void
160001
private function createSeeder(): void
    {
        $aFields  = $this->getArguments();
        $aCreated = [];

        try {

            $aModels = array_filter(explode(',', $aFields['MODEL_NAME']));
            sort($aModels);

            foreach ($aModels as $sModel) {

                $aFields['MODEL_NAME'] = $sModel;
                $this->oOutput->write('Creating seeder <comment>' . $sModel . '</comment>... ');

                //  Validate model exists by attempting to load it
                if (!stringToBoolean($this->oInput->getOption('skip-check'))) {
                    Factory::model($sModel, $aFields['MODEL_PROVIDER']);
                }

                //  Check for existing seeder
                $sPath = static::SEEDER_PATH . $sModel . '.php';
                if (file_exists($sPath)) {
                    throw new SeederExistsException(
                        'Seeder "' . $sModel . '" exists already at path "' . $sPath . '"'
                    );
                }

                $this->createFile($sPath, $this->getResource('template/seeder.php', $aFields));
                $aCreated[] = $sPath;
                $this->oOutput->writeln('<info>done!</info>');
            }

        } catch (\Exception $e) {
            $this->oOutput->writeln('<error>failed!</error>');
            //  Clean up created seeders
            if (!empty($aCreated)) {
                $this->oOutput->writeln('<error>Cleaning up - removing newly created files</error>');
                foreach ($aCreated as $sPath) {
                    @unlink($sPath);
                }
            }
            throw $e;
        }
    }
1299791
public function generate($seeder)
    {
        $generator = new Generator(
            $this->setting->getSeederDirectory(),
            "{$seeder}_seeder"
        );

        if ($generator->fileExists()) {
            echo "\033[0;31mThe seeder already exists.\033[00m";

            exit(1);
        }

        $num = (int)  $this->arg->options()->get('--seed', 5);

        $generator->write('seed', [
            'num' => $num,
            'name' => $seeder
        ]);

        echo "\033[0;32mThe seeder has been created.\033[00m\n";

        exit(0);
    }
489326
public function fire()
    {
        $this->info('Creating seeds from database...');

        $path           = $this->option('path');
        $connectionName = $this->option('connection');

        $tableNames = $this->getDatabaseTableNames($connectionName);

        /** @var \ViKon\DbExporter\Meta\Seed[] $seeds */
        $seeds      = [];
        $seederCall = [];
        foreach ($tableNames as $tableName) {
            if ($this->skipTable($tableName)) {
                continue;
            }

            $seeds[$tableName] = new Seed($connectionName, $tableName);
            $seeds[$tableName]->setPath($path);
            $seeds[$tableName]->writeSeedOut($this->output, $this->option('force'));
            $seederCall[] = '$this->call(\'' . $seeds[$tableName]->getClass() . '\');';
        }

        $this->writeToFileFromTemplate($path . '/Test.php', 'seederCall', $this->output, [
            'className' => 'Test',
            'call'      => implode("\n", $seederCall),
        ], $this->option('force'));

        $this->info('Seeds successfully created');
    }
215971
private function seed()
    {
        foreach ($this->input as $key => $value) {
            if (!$this->call($this->before, $value, $key)) {
                return;
            }

            yield $key => $value;

            if (!$this->call($this->after, $value, $key)) {
                return;
            }
        }
    }
1020591
public function create()
    {
        $conn = $this->connection->getConnection();
        $db = r\db($this->connection->getDatabaseName());
        $db->tableCreate($this->table)->run($conn);
    }
716903
public function create()
    {
        event(new BeforeCreate($this));

        $this->beforeCreate();

        $this->doCreate();

        $this->afterCreate();

        event(new AfterCreate($this));
    }
915187
public function create()
    {
        $params = array(
            'start' => $this->getStart(),
            'hash' => $this->getHash(),
            'parameters' => implode(',', $this->getParameters())
        );
        if (is_int($this->end)) {
            $params['end'] = $this->getEnd();
        }
        $this->fromResponse($this->getUser()->post('preview/create', $params));
    }
308722
protected function getSeeder()
    {
        $class = $this->getClassName();

        if (!class_exists($class)) {
            $file = database_path('/seeds/' . $class . '.php');

            if (is_file($file)) {
                require_once $file;
            }
        }

        return new $class($this->container, $this);
    }
890694
public function create()
    {
        $entry = $this->collection->newInstance()->set($this->getCriteria());

        $this->data['entry'] = $entry;

        if ($this->request->isPost()) {
            try {
                $result = $entry->set($this->request->getBody())->save();

                h('notification.info', $this->clazz.' created.');

                h('controller.create.success', array(
                    'model' => $entry
                ));
            } catch (Stop $e) {
                throw $e;
            } catch (Exception $e) {
                // no more set notification.error since notificationmiddleware will
                // write this later
                // h('notification.error', $e);

                h('controller.create.error', array(
                    'model' => $entry,
                    'error' => $e,
                ));

                // rethrow error to make sure notificationmiddleware know what todo
                throw $e;
            }
        }

    }
562102
public function run()
    {
        // php artisan db:seed --class="PermissionsTableSeeder"
        $permissions = [
            [
                'name' => 'manage_users',
            ],
            [
                'name' => 'manage_pages',
            ],
            [
                'name' => 'access_admin',
            ],
        ];

        // Only add new
        $allPermissions = Permission::all()->pluck('name')->toArray();

        foreach ($permissions as $permission) {
            if (! in_array($permission['name'], $allPermissions)) {
                Permission::create($permission);
            }
        }
    }
1061114
protected function createFolders()
    {
        $dir    = null;
        $target = $this->getTargetDirectory();

        /** @noinspection IsEmptyFunctionUsageInspection */
        if (!empty($target)) {
            $dir = rtrim($target, '/') . DIRECTORY_SEPARATOR;
            $this->setTarget($dir);
        }

        if ($dir !== null && !is_dir($dir) && $this->isAllowCreateFolders()) {
            /** @noinspection NotOptimalIfConditionsInspection */
            /** @noinspection PhpUsageOfSilenceOperatorInspection */
            if (!@mkdir($dir, 0777, true) && !is_dir($dir)) {
                throw new Exception\NoSuchDirectoryException(
                    sprintf('Directory %s does not exists.', $dir)
                );
            }
        }
    }
406188
public function run()
    {
        $this->call(ImageStylesTableSeeder::class);
        $this->call(PermissionsTableSeeder::class);
        $this->call(RolesTableSeeder::class);
        $this->call(UsersTableSeeder::class);
    }
198547
protected function seedRoot(? Foundation\AbstractActor $founder = null): void
   {  
       $graph_id = $this->database()->get("configs:graph_id");

       if(isset($graph_id)) {
         $this->logger()->info(
           "Existing network with id: %s", 
           $graph_id
         );
         $this["graph"] = $this->share(function($c) use($graph_id) {
            return $c["gs"]->node($graph_id);
          });
           $this["founder"] = $this->share(function($c) { 
           $founder = $c["graph"]->getFounder();
           return $founder;
         });
       }
       else {
          $this->logger()->info("Creating a new graph from scratch");
          if(!is_null($founder)) {
            $founder->persist();
          }
          else {
            throw new Exceptions\FounderMustBeSetException();
          }
          $this["founder"] = $this->share(function($c) use ($founder) {
              return $founder;
          });
          $this["graph"] = $this->share(function($c) {
            $graph_class = $c["config"]->default_objects->graph;
            $graph = new $graph_class($c, $c["founder"], $c["space"], $c["founder"]);
            $c["logger"]->info("Changing founder context as graph");
            $c["founder"]->changeContext($graph);
            //$c["founder"]->hydrate($c, $c["graph"]); // // to make sure that is set up, since the services are now available.
            return $graph;
          });
         $this->database()->set("configs:graph_id", $this->graph()->id());
         $this->logger()->info(
           "New graph with id: %s and founder: %s", $this->graph()->id(), $this->founder()->id()
         );
       }

       $this->logger()->info("Root seed complete. Time to integrate space & graph");
       $this["gs"]->warmUpCache();

       try {
        //  $this["space"]->add($this["graph"]);
          
       }
       catch(NodeAlreadyMemberException $e) {
          // do nothing
       }

       
   }
158493
public function create()
    {
        try {
            $schema = explode(';', str_replace(PHP_EOL, '', $this->getSchema()));
            array_pop($schema);

            # db structure
            $sql = array_shift($schema);
            $this->db->query($sql . ';');

            # indecies
            foreach($schema as $sql) {
                $this->db->query($sql . ';');
            }
        } catch(Exception $e) {
            throw new Exception($e->getMessage(), 1);
        }
    }
805901
public function run()
    {
        $this->seed('CategoriesTableSeeder');
        $this->seed('UsersTableSeeder');
        $this->seed('PostsTableSeeder');
        $this->seed('PagesTableSeeder');
        $this->seed('SettingsTableSeeder');
        $this->seed('TranslationsTableSeeder');
    }
502619
public function run(): void
    {
        foreach ($this->seed as $key => $value) {
            $this->call($this->each, $value, $key);
        }
    }
917246
public function persist(): void
    {
        foreach ($this->create() as $seed) {
            $this->seeder->persist($seed);
            $this->persistedSeeds++;
        }

        $this->seeder->flush();
    }