Actions

API16

JUpdater/findUpdates

From Joomla! Documentation

< API16:JUpdater
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Finds an update for an extension

[Edit Descripton]

Description:JUpdater/findUpdates

Syntax

findUpdates($eid=0)
Parameter Name Default Value Description
$eid 0 Extension Identifier; if zero use all sites

Returns

boolean If there are updates or not

Defined in

libraries/joomla/updater/updater.php

Importing

jimport( 'joomla.updater.updater' );

Source Body

public function findUpdates($eid=0) {
        $dbo =& $this->getDBO();
        $retval = false;
        // push it into an array
        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']);
                $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; $k < count($update_result['updates']); $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) {
                                                // set the extension id
                                                if($eid) {
                                                        // we have an installed extension, check the update is actually newer
                                                        $extension->load($eid);
                                                        $data = unserialize($extension->manifest_cache);
                                                        if(version_compare($current_update->version, $data['version'], '>') == 1) {
                                                                //echo '<p>Storing extension since '. $attrs['VERSION'] .' > ' . $data['version']. '</p>';
                                                                $current_update->extension_id = $eid;
                                                                $current_update->store();
                                                        }
                                                } else {
                                                        // a potentially new extension to be installed
                                                        //echo '<p>Storing since no equivalent extension is installed</p>';
                                                        $current_update->store();
                                                }
                                        } else {
                                                $update->load($uid);
                                                // if there is an update, check that the version is newer then replaces
                                                if(version_compare($current_update->version, $update->version, '>') == 1) {
                                                        //echo '<p>Storing extension since '. $attrs['VERSION'] .' > ' . $data['version']. '</p>';
                                                        $current_update->store();
                                                }
                                        }//else { echo '<p>Found a matching update for '. $attrs['NAME'] .'</p>';}
                                }
                        }
                        $update_result = true;
                } else if ($retval) {
                        $update_result = true;
                }
        }
        return $retval;
}

[Edit See Also] SeeAlso:JUpdater/findUpdates

Examples

<CodeExamplesForm />