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

+ added stub_path to config file. #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions src/Orangehill/Iseed/Iseed.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function readStubFile($file)
* @return bool
* @throws Orangehill\Iseed\TableNotFoundException
*/
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')
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')
{
if (!$database) {
$database = config('database.default');
Expand Down Expand Up @@ -139,7 +139,7 @@ public function getData($table, $max, $exclude = null, $orderBy = null, $directi
$result = $result->select(array_diff($allColumns, $exclude));
}

if($orderBy) {
if ($orderBy) {
$result = $result->orderBy($orderBy, $direction);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public function hasTable($table)
* @param string $suffix
* @return string
*/
public function generateClassName($table, $prefix=null, $suffix=null)
public function generateClassName($table, $prefix = null, $suffix = null)
{
$tableString = '';
$tableName = explode('_', $table);
Expand All @@ -206,7 +206,7 @@ public function generateClassName($table, $prefix=null, $suffix=null)
*/
public function getStubPath()
{
return __DIR__ . DIRECTORY_SEPARATOR . 'stubs';
return config('iseed::config.stub_path', null) ?: DIR . DIRECTORY_SEPARATOR . 'stubs';
}

/**
Expand Down Expand Up @@ -253,7 +253,9 @@ public function populateStub($class, $stub, $table, $data, $chunkSize = null, $p
}

$stub = str_replace(
'{{prerun_event}}', $prerunEventInsert, $stub
'{{prerun_event}}',
$prerunEventInsert,
$stub
);

if (!is_null($table)) {
Expand All @@ -275,7 +277,9 @@ public function populateStub($class, $stub, $table, $data, $chunkSize = null, $p
}

$stub = str_replace(
'{{postrun_event}}', $postrunEventInsert, $stub
'{{postrun_event}}',
$postrunEventInsert,
$stub
);

$stub = str_replace('{{insert_statements}}', $inserts, $stub);
Expand Down
5 changes: 3 additions & 2 deletions src/config/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
return array(
'path' => '/database/seeders',
'chunk_size' => 500 // Maximum number of rows per insert statement
);
'chunk_size' => 500, // Maximum number of rows per insert statement,
'stub_path' => null, // custom seed stub path - exmaple file path stubs/seed.stub
);