getQuery(true) ->select('update_site_id') ->from('#__update_sites') ->where('location = ' . $db->quote($location)); $db->setQuery($query); $update_site_id = (int) $db->loadResult(); // If it doesn't exist, add it! if (!$update_site_id) { $query->clear() ->insert('#__update_sites') ->columns(array($db->quoteName('name'), $db->quoteName('type'), $db->quoteName('location'), $db->quoteName('enabled'))) ->values($db->quote($name) . ', ' . $db->quote($type) . ', ' . $db->quote($location) . ', ' . (int) $enabled); $db->setQuery($query); if ($db->execute()) { // Link up this extension to the update site $update_site_id = $db->insertid(); } } // Check if it has an update site id (creation might have faileD) if ($update_site_id) { // Look for an update site entry that exists $query->clear() ->select('update_site_id') ->from('#__update_sites_extensions') ->where('update_site_id = ' . $update_site_id) ->where('extension_id = ' . $this->eid); $db->setQuery($query); $tmpid = (int) $db->loadResult(); if (!$tmpid) { // Link this extension to the relevant update site $query->clear() ->insert('#__update_sites_extensions') ->columns(array($db->quoteName('update_site_id'), $db->quoteName('extension_id'))) ->values($update_site_id . ', ' . $this->eid); $db->setQuery($query); $db->execute(); } } } /** * Handle post extension install update sites * * @param JInstaller $installer Installer object * @param integer $eid Extension Identifier * * @return void * * @since 1.6 */ public function onExtensionAfterInstall($installer, $eid ) { if ($eid) { $this->installer = $installer; $this->eid = $eid; // After an install we only need to do update sites $this->processUpdateSites(); } } /** * Handle extension uninstall * * @param JInstaller $installer Installer instance * @param integer $eid Extension id * @param integer $result Installation result * * @return void * * @since 1.6 */ public function onExtensionAfterUninstall($installer, $eid, $result) { if ($eid) { // Wipe out any update_sites_extensions links $db = JFactory::getDbo(); $query = $db->getQuery(true) ->delete('#__update_sites_extensions') ->where('extension_id = ' . $eid); $db->setQuery($query); $db->execute(); // Delete any unused update sites $query->clear() ->select('update_site_id') ->from('#__update_sites_extensions'); $db->setQuery($query); $results = $db->loadColumn(); if (is_array($results)) { // So we need to delete the update sites and their associated updates $updatesite_delete = $db->getQuery(true); $updatesite_delete->delete('#__update_sites'); $updatesite_query = $db->getQuery(true); $updatesite_query->select('update_site_id') ->from('#__update_sites'); // If we get results back then we can exclude them if (count($results)) { $updatesite_query->where('update_site_id NOT IN (' . implode(',', $results) . ')'); $updatesite_delete->where('update_site_id NOT IN (' . implode(',', $results) . ')'); } // So let's find what update sites we're about to nuke and remove their associated extensions $db->setQuery($updatesite_query); $update_sites_pending_delete = $db->loadColumn(); if (is_array($update_sites_pending_delete) && count($update_sites_pending_delete)) { // Nuke any pending updates with this site before we delete it // TODO: investigate alternative of using a query after the delete below with a query and not in like above $query->clear() ->delete('#__updates') ->where('update_site_id IN (' . implode(',', $update_sites_pending_delete) . ')'); $db->setQuery($query); $db->execute(); } // Note: this might wipe out the entire table if there are no extensions linked $db->setQuery($updatesite_delete); $db->execute(); } // Last but not least we wipe out any pending updates for the extension $query->clear() ->delete('#__updates') ->where('extension_id = '. $eid); $db->setQuery($query); $db->execute(); } } /** * After update of an extension * * @param JInstaller $installer Installer object * @param integer $eid Extension identifier * * @return void * * @since 1.6 */ public function onExtensionAfterUpdate($installer, $eid) { if ($eid) { $this->installer = $installer; $this->eid = $eid; // handle any update sites $this->processUpdateSites(); } } /** * Processes the list of update sites for an extension. * * @return void * * @since 1.6 */ private function processUpdateSites() { $manifest = $this->installer->getManifest(); $updateservers = $manifest->updateservers; if ($updateservers) { $children = $updateservers->children(); } else { $children = array(); } if (count($children)) { foreach ($children as $child) { $attrs = $child->attributes(); $this->addUpdateSite($attrs['name'], $attrs['type'], $child, true); } } else { $data = (string) $updateservers; if (strlen($data)) { // We have a single entry in the update server line, let us presume this is an extension line $this->addUpdateSite(JText::_('PLG_EXTENSION_JOOMLA_UNKNOWN_SITE'), 'extension', $data, true); } } } }