Skip to content

Commit

Permalink
add direction option
Browse files Browse the repository at this point in the history
  • Loading branch information
Gimmy committed Jul 8, 2017
1 parent 68e560d commit 839c034
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Orangehill/Iseed/Iseed.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function readStubFile($file)
* @return bool
* @throws Orangehill\Iseed\TableNotFoundException
*/
public function generateSeed($table, $database = null, $max = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null)
public function generateSeed($table, $database = null, $max = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC')
{
if (!$database) {
$database = config('database.default');
Expand All @@ -73,7 +73,7 @@ public function generateSeed($table, $database = null, $max = 0, $exclude = null
}

// Get the data
$data = $this->getData($table, $max, $exclude, $orderBy);
$data = $this->getData($table, $max, $exclude, $orderBy, $direction);

// Repack the data
$dataArray = $this->repackSeedData($data);
Expand Down Expand Up @@ -128,7 +128,7 @@ public function getSeedPath()
* @param string $table
* @return Array
*/
public function getData($table, $max, $exclude = null, $orderBy = null)
public function getData($table, $max, $exclude = null, $orderBy = null, $direction = 'ASC')
{
$result = \DB::connection($this->databaseName)->table($table);

Expand All @@ -138,7 +138,7 @@ public function getData($table, $max, $exclude = null, $orderBy = null)
}

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

if ($max) {
Expand Down
5 changes: 4 additions & 1 deletion src/Orangehill/Iseed/IseedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function fire()
$dumpAuto = intval($this->option('dumpauto'));
$indexed = !$this->option('noindex');
$orderBy = $this->option('orderby');
$direction = $this->option('direction');

if ($chunkSize < 1) {
$chunkSize = null;
Expand Down Expand Up @@ -85,7 +86,8 @@ public function fire()
$postrunEvent,
$dumpAuto,
$indexed,
$orderBy
$orderBy,
$direction
),
$table
);
Expand Down Expand Up @@ -143,6 +145,7 @@ protected function getOptions()
array('dumpauto', null, InputOption::VALUE_OPTIONAL, 'run composer dump-autoload', true),
array('noindex', null, InputOption::VALUE_NONE, 'no indexing in the seed', null),
array('orderby', null, InputOption::VALUE_OPTIONAL, 'orderby desc by column', null),
array('direction', null, InputOption::VALUE_OPTIONAL, 'orderby direction', null),
);
}

Expand Down

0 comments on commit 839c034

Please sign in to comment.