Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update IseedCommand.php #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 59 additions & 45 deletions src/Orangehill/Iseed/IseedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function fire()
$direction = $this->option('direction');
$prefix = $this->option('classnameprefix');
$suffix = $this->option('classnamesuffix');
$separate = intval($this->option('separate'));

if ($max < 1) {
$max = null;
Expand All @@ -74,6 +75,8 @@ public function fire()
if ($chunkSize < 1) {
$chunkSize = null;
}

$j = $separate > 1 ? $separate : 1;

$tableIncrement = 0;
foreach ($tables as $table) {
Expand All @@ -88,50 +91,60 @@ public function fire()
}
$tableIncrement++;

// generate file and class name based on name of the table
list($fileName, $className) = $this->generateFileName($table, $prefix, $suffix);

// if file does not exist or force option is turned on generate seeder
if (!\File::exists($fileName) || $this->option('force')) {
$this->printResult(
app('iseed')->generateSeed(
for ($i = 0; $i < $j; $i++) {
// generate file and class name based on name of the table
list($fileName, $className) = $this->generateFileName($table, $prefix, $suffix, ($separate > 1 ? ($i + 1) : null));

// if file does not exist or force option is turned on generate seeder
if (!\File::exists($fileName) || $this->option('force')) {
$this->printResult(
app('iseed')->generateSeed(
$table,
$prefix,
$suffix,
$this->option('database'),
$max,
$chunkSize,
$exclude,
$prerunEvent,
$postrunEvent,
$dumpAuto,
$indexed,
$orderBy,
$direction,
$separate,
($separate > 1 ? $i : null)
),
$table,
$prefix,
$suffix,
$this->option('database'),
$max,
$chunkSize,
$exclude,
$prerunEvent,
$postrunEvent,
$dumpAuto,
$indexed,
$orderBy,
$direction
),
$table
);
continue;
}

if ($this->confirm('File ' . $className . ' already exist. Do you wish to override it? [yes|no]')) {
// if user said yes overwrite old seeder
$this->printResult(
app('iseed')->generateSeed(
($separate > 1 ? ($i + 1) : null)
);
continue;
}

if ($this->confirm('File ' . $className . ' already exist. Do you wish to override it? [yes|no]')) {
// if user said yes overwrite old seeder
$this->printResult(
app('iseed')->generateSeed(
$table,
$prefix,
$suffix,
$this->option('database'),
$max,
$chunkSize,
$exclude,
$prerunEvent,
$postrunEvent,
$dumpAuto,
$indexed,
$orderBy,
$direction,
$separate,
($separate > 1 ? $i : null)
),
$table,
$prefix,
$suffix,
$this->option('database'),
$max,
$chunkSize,
$exclude,
$prerunEvent,
$postrunEvent,
$dumpAuto,
$indexed
),
$table
);
($separate > 1 ? ($i + 1) : null)
);
}
}
}

Expand Down Expand Up @@ -172,6 +185,7 @@ protected function getOptions()
array('direction', null, InputOption::VALUE_OPTIONAL, 'orderby direction', null),
array('classnameprefix', null, InputOption::VALUE_OPTIONAL, 'prefix for class and file name', null),
array('classnamesuffix', null, InputOption::VALUE_OPTIONAL, 'suffix for class and file name', null),
array('separate', null, InputOption::VALUE_OPTIONAL, 'separate file', null),
);
}

Expand All @@ -185,11 +199,11 @@ protected function getOptions()
protected function printResult($successful, $table)
{
if ($successful) {
$this->info("Created a seed file from table {$table}");
$this->info("Created a seed" . (' ' . $i . ' ' ?? ' ') . "file from table {$table}");
return;
}

$this->error("Could not create seed file from table {$table}");
$this->error("Could not create seed" . (' ' . $i . ' ' ?? ' ') . "file from table {$table}");
}

/**
Expand All @@ -205,7 +219,7 @@ protected function generateFileName($table, $prefix=null, $suffix=null)
}

// Generate class name and file name
$className = app('iseed')->generateClassName($table, $prefix, $suffix);
$className = app('iseed')->generateClassName($table, $prefix, $suffix, $i);
$seedPath = base_path() . config('iseed::config.path');
return [$seedPath . '/' . $className . '.php', $className . '.php'];
}
Expand Down