ImportSource: add helper methods able to fetch...

...the latest run or the latest run before a specific timestamp as an object
This commit is contained in:
Thomas Gelf 2016-06-24 11:48:54 +02:00
parent 9ae70a4377
commit 57c760bca9
1 changed files with 33 additions and 0 deletions

View File

@ -29,6 +29,39 @@ class ImportSource extends DbObjectWithSettings
protected $settingsRemoteId = 'source_id';
public function fetchLatestRun()
{
return $this->fetchLastRunBefore(time());
}
public function fetchLastRunBefore($timestamp)
{
if (! $this->hasBeenLoadedFromDb()) {
return null;
}
if ($timestamp === null) {
$timestamp = time();
}
$db = $this->getDb();
$query = $db->select()->from(
array('ir' => 'import_run'),
'ir.id'
)->where('ir.source_id = ?', $this->id)
->where('ir.end_time < ?', date('Y-m-d H:i:s', $timestamp))
->order('ir.end_time DESC')
->limit(1);
$runId = $db->fetchOne($query);
if ($runId) {
return ImportRun::fromDb($this->connection);
} else {
return null;
}
}
public function fetchRowModifiers()
{
$db = $this->getDb();