{
$retval = false;
if (!is_array($eid))
{
$query = 'SELECT DISTINCT update_site_id, type, location, last_check_timestamp FROM #__update_sites WHERE enabled = 1';
}
else
{
$query = 'SELECT DISTINCT update_site_id, type, location, last_check_timestamp FROM #__update_sites' .
' WHERE update_site_id IN' .
' (SELECT update_site_id FROM #__update_sites_extensions WHERE extension_id IN (' . implode(',', $eid) . '))';
}
$db->setQuery($query);
$results = $db->loadAssocList();
$result_count = count($results);
$now = time();
for ($i = 0; $i < $result_count; $i++)
{
$result = &$results[$i];
if (!isset($this->_adapters[$result['type']]))
{
continue;
}
if ($cacheTimeout > 0)
{
if (isset($result['last_check_timestamp']) && ($now - $result['last_check_timestamp'] <= $cacheTimeout))
{
$retval = true;
continue;
}
}
$update_result = $this->_adapters[$result['type']]->findUpdate($result);
if (is_array($update_result))
{
if (array_key_exists('update_sites', $update_result) && count($update_result['update_sites']))
{
$result_count = count($results);
}
if (array_key_exists('updates', $update_result) && count($update_result['updates']))
{
for ($k = 0, $count = count($update_result['updates']); $k < $count; $k++)
{
$current_update = &$update_result['updates'][$k];
$uid = $update
->find(
array(
'element' => strtolower($current_update->get('element')), 'type' => strtolower($current_update->get('type')),
'client_id' => strtolower($current_update->get('client_id')),
'folder' => strtolower($current_update->get('folder'))
)
);
$eid = $extension
->find(
array(
'element' => strtolower($current_update->get('element')), 'type' => strtolower($current_update->get('type')),
'client_id' => strtolower($current_update->get('client_id')),
'folder' => strtolower($current_update->get('folder'))
)
);
if (!$uid)
{
if ($eid)
{
$extension->load($eid);
$data = json_decode($extension->manifest_cache, true);
if (version_compare($current_update->version, $data['version'], '>') == 1)
{
$current_update->extension_id = $eid;
$current_update->store();
}
}
else
{
$current_update->store();
}
}
else
{
$update->load($uid);
if (version_compare($current_update->version, $update->version, '>') == 1)
{
$current_update->store();
}
}
}
}
}
$query = $db->getQuery(true)
->update($db->quoteName('#__update_sites'))
->set($db->quoteName('last_check_timestamp') . ' = ' . $db->quote($now))
->where($db->quoteName('update_site_id') . ' = ' . $db->quote($result['update_site_id']));
$db->setQuery($query);
$db->execute();
}
return $retval;
}