10 defined(
'JPATH_PLATFORM') or die;
12 jimport('joomla.filesystem.file');
13 jimport('joomla.filesystem.folder');
14 jimport('joomla.filesystem.path');
16 jimport('joomla.utilities.arrayhelper');
38 public function __construct()
41 parent::__construct(__DIR__,
'JUpdater');
52 public static function getInstance()
54 if (!isset(self::$instance))
58 return self::$instance;
71 public function findUpdates($eid = 0, $cacheTimeout = 0)
74 $db = $this->getDBO();
80 $query =
'SELECT DISTINCT update_site_id, type, location, last_check_timestamp FROM #__update_sites WHERE enabled = 1';
84 $query =
'SELECT DISTINCT update_site_id, type, location, last_check_timestamp FROM #__update_sites' .
85 ' WHERE update_site_id IN' .
86 ' (SELECT update_site_id FROM #__update_sites_extensions WHERE extension_id IN (' . implode(
',', $eid) .
'))';
88 $db->setQuery($query);
89 $results = $db->loadAssocList();
90 $result_count = count($results);
92 for ($i = 0; $i < $result_count; $i++)
94 $result = &$results[$i];
95 $this->setAdapter($result[
'type']);
96 if (!isset($this->_adapters[$result[
'type']]))
101 if ($cacheTimeout > 0)
103 if (isset($result[
'last_check_timestamp']) && ($now - $result[
'last_check_timestamp'] <= $cacheTimeout))
111 $update_result = $this->_adapters[$result[
'type']]->findUpdate($result);
112 if (is_array($update_result))
114 if (array_key_exists(
'update_sites', $update_result) && count($update_result[
'update_sites']))
117 $result_count = count($results);
119 if (array_key_exists(
'updates', $update_result) && count($update_result[
'updates']))
121 for ($k = 0, $count = count($update_result[
'updates']); $k < $count; $k++)
123 $current_update = &$update_result[
'updates'][$k];
129 'element' => strtolower($current_update->get(
'element')),
'type' => strtolower($current_update->get(
'type')),
130 'client_id' => strtolower($current_update->get(
'client_id')),
131 'folder' => strtolower($current_update->get(
'folder'))
138 'element' => strtolower($current_update->get(
'element')),
'type' => strtolower($current_update->get(
'type')),
139 'client_id' => strtolower($current_update->get(
'client_id')),
140 'folder' => strtolower($current_update->get(
'folder'))
149 $extension->load($eid);
150 $data = json_decode($extension->manifest_cache,
true);
151 if (version_compare($current_update->version, $data[
'version'],
'>') == 1)
153 $current_update->extension_id = $eid;
154 $current_update->store();
160 $current_update->store();
168 if (version_compare($current_update->version, $update->version,
'>') == 1)
170 $current_update->store();
178 $query = $db->getQuery(
true)
179 ->update($db->quoteName(
'#__update_sites'))
180 ->
set($db->quoteName(
'last_check_timestamp') .
' = ' . $db->quote($now))
181 ->where($db->quoteName(
'update_site_id') .
' = ' . $db->quote($result[
'update_site_id']));
182 $db->setQuery($query);
197 public function update($id)
200 $updaterow->load($id);
202 if ($update->loadFromXML($updaterow->detailsurl))
204 return $update->install();