SyncJob: improve job execution

This commit is contained in:
Thomas Gelf 2016-05-25 11:46:27 +02:00
parent 8ebf04da1e
commit fe8c4bc6a3

View File

@ -13,20 +13,24 @@ class SyncJob extends JobHook
public function run()
{
if ($this->getSetting('apply_changes') === 'y') {
$this->syncRule()->applyChanges();
$db = $this->db();
$id = $this->getSetting('rule_id');
if ($id === '__ALL__') {
foreach (SyncRule::loadAll($db) as $rule) {
$this->runForRule($rule);
}
} else {
$this->syncRule()->checkForChanges();
$this->runForRule(SyncRule::load($id, $db));
}
}
protected function syncRule()
protected function runForRule(SyncRule $rule)
{
if ($this->rule === null) {
$this->rule = SyncRule::load($this->getSetting('rule_id'), $this->db());
if ($this->getSetting('apply_changes') === 'y') {
$rule->applyChanges();
} else {
$rule->checkForChanges();
}
return $this->rule;
}
public static function getDescription(QuickForm $form)
@ -88,8 +92,4 @@ class SyncJob extends JobHook
'__ALL__' => $form->translate('Run all rules at once')
) + $res;
}
public function isPending()
{
}
}