Create getter for update checker inside the cron worker

This commit is contained in:
Dmitriy Simushev 2015-06-05 09:45:25 +00:00
parent 5397f7014a
commit fbe53e3b29

View File

@ -66,9 +66,10 @@ class CronWorker
public function __construct(PoolInterface $cache, UpdateChecker $update_checker = null) public function __construct(PoolInterface $cache, UpdateChecker $update_checker = null)
{ {
$this->cache = $cache; $this->cache = $cache;
$this->updateChecker = is_null($update_checker)
? new UpdateChecker() if (!is_null($update_checker)) {
: $update_checker; $this->updateChecker = $update_checker;
}
} }
/** /**
@ -99,10 +100,11 @@ class CronWorker
if (Settings::get('autocheckupdates') == '1') { if (Settings::get('autocheckupdates') == '1') {
// Run the update checker // Run the update checker
if (!$this->updateChecker->run()) { $update_checker = $this->getUpdateChecker();
if (!$update_checker->run()) {
$this->errors = array_merge( $this->errors = array_merge(
$this->errors, $this->errors,
$this->updateChecker->getErrors() $update_checker->getErrors()
); );
return false; return false;
@ -137,4 +139,20 @@ class CronWorker
{ {
return $this->log; return $this->log;
} }
/**
* Retrives an instance of Update Checker attached to the worker.
*
* If there was no attached checker it creates a new one.
*
* @return UpdateChecker
*/
protected function getUpdateChecker()
{
if (is_null($this->updateChecker)) {
$this->updateChecker = new UpdateChecker();
}
return $this->updateChecker;
}
} }