english/libraries/joomla/updater/updater.php
/**
	 * Finds an update for an extension
	 *
	 * @param   integer  $eid  Extension Identifier; if zero use all sites
	 *
	 * @return  boolean True if there are updates
	 *
	 * @since   11.1
	 */
Finds an update for an extension
@param   integer  $eid  Extension Identifier; if zero use all sites

@return  boolean True if there are updates


Finds an update for an extension @param integer $eid Extension Identifier ; if zero use all sites @return boolean True if there are updates
public function findUpdates($eid=0) {
		$result = ini_get('allow_url_fopen');
		if (empty($result)) {
			JError::raiseWarning('101', JText::_('JLIB_UPDATER_ERROR_COLLECTION_FOPEN'));
			return false;
		}
		$dbo = $this->getDBO();
		$retval = false;
		if(!is_array($eid)) {
			$query = 'SELECT DISTINCT update_site_id, type, location FROM #__update_sites WHERE enabled = 1';
		} else {
			$query = 'SELECT DISTINCT update_site_id, type, location FROM #__update_sites WHERE update_site_id IN (SELECT update_site_id FROM #__update_sites_extensions WHERE extension_id IN ('. implode(',', $eid) .'))';
		}
		$dbo->setQuery($query);
		$results = $dbo->loadAssocList();
		$result_count = count($results);
		for($i = 0; $i < $result_count; $i++)
		{
			$result = &$results[$i];
			$this->setAdapter($result['type']);
			if(!isset($this->_adapters[$result['type']])) {
				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']))
				{
					$results = $this->arrayUnique(array_merge($results, $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];
						$update = JTable::getInstance('update');
						$extension = JTable::getInstance('extension');
						$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();
							}
						}
					}
				}
				$update_result = true;
			} else if ($retval) {
				$update_result = true;
			}
		}
		return $retval;
	}
public function findUpdates ( $ eid = 0 ) { $ result = ini_get ( 'allow_url_fopen' ) ; if ( empty ( $ result ) ) { JError :: raiseWarning ( '101' , JText :: _ ( 'JLIB_UPDATER_ERROR_COLLECTION_FOPEN' ) ) ; return false ; } $ dbo = $ this -> getDBO ( ) ; $ retval = false ; if ( ! is_array ( $ eid ) ) { $ query = 'SELECT DISTINCT update_site_id, type, location FROM #__update_sites WHERE enabled = 1' ; } else { $ query = 'SELECT DISTINCT update_site_id, type, location FROM #__update_sites WHERE update_site_id IN (SELECT update_site_id FROM #__update_sites_extensions WHERE extension_id IN (' . implode ( ',' , $ eid ) . '))' ; } $ dbo -> setQuery ( $ query ) ; $ results = $ dbo -> loadAssocList ( ) ; $ result_count = count ( $ results ) ; for ( $ i = 0 ; $ i < $ result_count ; $ i ++ ) { $ result = & $ results [ $ i ] ; $ this -> setAdapter ( $ result [ 'type' ] ) ; if ( ! isset ( $ this -> _adapters [ $ result [ 'type' ] ] ) ) { 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' ] ) ) { $ results = $ this -> arrayUnique ( array_merge ( $ results , $ 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 ] ; $ update = JTable :: getInstance ( 'update' ) ; $ extension = JTable :: getInstance ( 'extension' ) ; $ 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 ( ) ; } } } } $ update_result = true ; } else if ( $ retval ) { $ update_result = true ; } } return $ retval ; }
Finds an update for an extension
 @param   integer  $eid  Extension Identifier; if zero use all sites
Finds an update for an extension @param integer $eid Extension Identifier ; if zero use all sites
// Check if fopen is allowed // Push it into an array // Ignore update sites requiring adapters we don't have installed // Set the extension id // We have an installed extension, check the update is actually newer // A potentially new extension to be installed // if there is an update, check that the version is newer then replaces