Skip to content

Add “limit” option to CopyAll, CleanAll samplers #1

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

Merged
merged 1 commit into from
Mar 2, 2017
Merged
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
8 changes: 8 additions & 0 deletions src/BaseSampler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ abstract class BaseSampler implements SamplerInterface
* @var array
*/
protected $referenceFields = [];

/**
* Max number to match (default Db order)
*
* @var integer
*/
protected $limit;

/**
* Table name
Expand Down Expand Up @@ -147,6 +154,7 @@ public function setReferenceStore(ReferenceStore $referenceStore)
public function loadConfig($config)
{
$this->referenceFields = isset($config->remember) ? $config->remember : [];
$this->limit = isset($config->limit) ? (int)$config->limit : false;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Sampler/CleanAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ public function loadConfig($config)
*/
public function getRows()
{
$query = $this->sourceConnection->createQueryBuilder()->select('*')->from($this->tableName)->execute();
$query = $this->sourceConnection->createQueryBuilder()->select('*')->from($this->tableName);

$rows = $query->fetchAll();
if ($this->limit) {
$query->setMaxResults($this->limit);
}

$rows = $query->execute()->fetchAll();

foreach ($rows as &$row) {
$this->rowCleaner->cleanRow($row);
Expand Down
8 changes: 6 additions & 2 deletions src/Sampler/CopyAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ public function getName()

public function getRows()
{
$query = $this->sourceConnection->createQueryBuilder()->select('*')->from($this->tableName)->execute();
$query = $this->sourceConnection->createQueryBuilder()->select('*')->from($this->tableName);

return $query->fetchAll();
if ($this->limit) {
$query->setMaxResults($this->limit);
}

return $query->execute()->fetchAll();
}
}
8 changes: 0 additions & 8 deletions src/Sampler/Matched.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ class Matched extends BaseSampler
*/
protected $constraints;

/**
* Max number to match (default Db order)
*
* @var integer
*/
protected $limit;

/**
* Return a unique name for this sampler for informational purposes
*
Expand All @@ -59,7 +52,6 @@ public function loadConfig($config)
{
parent::loadConfig($config);
$this->constraints = (array)$this->demandParameterValue($config, 'constraints');
$this->limit = isset($config->limit) ? (int)$config->limit : false;
}

/**
Expand Down