Skip to content

Commit 875df19

Browse files
committed
feat: Add --noregister option to skip DatabaseSeeder registration
Add new --noregister option that generates seed files without adding them to DatabaseSeeder.php. Useful for creating backup seeders or manually managing which seeders are registered. Based on PR #230 by @VukTodorovic, renamed from --noseed to --noregister for clearer semantics.
1 parent 545a8d4 commit 875df19

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ Example:
197197
php artisan iseed users --noindex
198198
```
199199

200+
### noregister
201+
By using --noregister the seed file will be generated but will not be added to `DatabaseSeeder.php`. This is useful when you want to create backup seeders or manually manage which seeders are registered.
202+
203+
Example:
204+
```
205+
php artisan iseed users --noregister
206+
```
207+
200208
### where
201209
Optional parameter which allows you to specify a SQL WHERE clause to filter the rows that will be included in the seed file. The WHERE clause should be provided as a string and will be applied directly to the SQL query.
202210

src/Orangehill/Iseed/Iseed.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ public function readStubFile($file)
6464
* @param int $max
6565
* @param string $prerunEvent
6666
* @param string $postrunEvent
67+
* @param bool $register
6768
* @return bool
6869
* @throws Orangehill\Iseed\TableNotFoundException
6970
*/
70-
public function generateSeed($table, $prefix = null, $suffix = null, $database = null, $max = 0, $chunkSize = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC', $whereClause = null)
71+
public function generateSeed($table, $prefix = null, $suffix = null, $database = null, $max = 0, $chunkSize = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC', $whereClause = null, $register = true)
7172
{
7273
if (!$database) {
7374
$database = config('database.default');
@@ -118,8 +119,12 @@ public function generateSeed($table, $prefix = null, $suffix = null, $database =
118119
$this->composer->dumpAutoloads();
119120
}
120121

121-
// Update the DatabaseSeeder.php file
122-
return $this->updateDatabaseSeederRunMethod($className) !== false;
122+
// Update the DatabaseSeeder.php file (unless --noregister is used)
123+
if ($register) {
124+
return $this->updateDatabaseSeederRunMethod($className) !== false;
125+
}
126+
127+
return true;
123128
}
124129

125130
/**

src/Orangehill/Iseed/IseedCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function fire()
7070
$postrunEvents = explode(",", $this->option('postrun'));
7171
$dumpAuto = intval($this->option('dumpauto'));
7272
$indexed = !$this->option('noindex');
73+
$register = !$this->option('noregister');
7374
$orderBy = $this->option('orderby');
7475
$direction = $this->option('direction');
7576
$prefix = $this->option('classnameprefix');
@@ -110,7 +111,8 @@ public function fire()
110111
$indexed,
111112
$orderBy,
112113
$direction,
113-
$whereClause
114+
$whereClause,
115+
$register
114116
),
115117
$table
116118
);
@@ -134,7 +136,8 @@ public function fire()
134136
$indexed,
135137
$orderBy,
136138
$direction,
137-
$whereClause
139+
$whereClause,
140+
$register
138141
),
139142
$table
140143
);
@@ -173,6 +176,7 @@ protected function getOptions()
173176
array('postrun', null, InputOption::VALUE_OPTIONAL, 'postrun event name', null),
174177
array('dumpauto', null, InputOption::VALUE_OPTIONAL, 'run composer dump-autoload', true),
175178
array('noindex', null, InputOption::VALUE_NONE, 'no indexing in the seed', null),
179+
array('noregister', null, InputOption::VALUE_NONE, 'do not register in DatabaseSeeder.php', null),
176180
array('orderby', null, InputOption::VALUE_OPTIONAL, 'orderby desc by column', null),
177181
array('direction', null, InputOption::VALUE_OPTIONAL, 'orderby direction', null),
178182
array('classnameprefix', null, InputOption::VALUE_OPTIONAL, 'prefix for class and file name', null),

0 commit comments

Comments
 (0)