public bool
findUpdates
(mixed $eid = 0, mixed $cacheTimeout = 0, mixed $minimumStability = self::STABILITY_STABLE, mixed $includeCurrent = false)
/**
* Finds the update for an extension. Any discovered updates are stored in the #__updates table.
*
* @param int|array $eid Extension Identifier or list of Extension Identifiers; if zero use all
* sites
* @param integer $cacheTimeout How many seconds to cache update information; if zero, force reload the
* update information
* @param integer $minimumStability Minimum stability for the updates; 0=dev, 1=alpha, 2=beta, 3=rc,
* 4=stable
* @param boolean $includeCurrent Should I include the current version in the results?
*
* @return boolean True if there are updates
*
* @since 1.7.0
*/
public function findUpdates($eid = 0, $cacheTimeout = 0, $minimumStability = self::STABILITY_STABLE, $includeCurrent = false)
{
$retval = false;
$results = $this->getUpdateSites($eid);
if (empty($results)) {
return $retval;
}
$now = time();
$earliestTime = $now - $cacheTimeout;
$sitesWithUpdates = array();
if ($cacheTimeout > 0) {
$sitesWithUpdates = $this->getSitesWithUpdates($earliestTime);
}
foreach ($results as $result) {
/**
* If we have already checked for updates within the cache timeout period we will report updates available
* only if there are update records matching this update site. Then we skip processing of the update site
* since it's already processed within the cache timeout period.
*/
if ($cacheTimeout > 0 && isset($result['last_check_timestamp']) && $result['last_check_timestamp'] >= $earliestTime) {
$retval = $retval || \in_array($result['update_site_id'], $sitesWithUpdates);
continue;
}
// Make sure there is no update left over in the database.
$db = $this->getDbo();
$query = $db->getQuery(true)->delete($db->quoteName('#__updates'))->where($db->quoteName('update_site_id') . ' = :id')->bind(':id', $result['update_site_id'], ParameterType::INTEGER);
$db->setQuery($query);
$db->execute();
$updateObjects = $this->getUpdateObjectsForSite($result, $minimumStability, $includeCurrent);
if (!empty($updateObjects)) {
$retval = true;
/** @var \Joomla\CMS\Table\Update $update */
foreach ($updateObjects as $update) {
$update->check();
$update->store();
}
}
// Finally, update the last update check timestamp
$this->updateLastCheckTimestamp($result['update_site_id']);
}
return $retval;
}