Skip to content

Commit

Permalink
Merge commit '3d8593c' into 4.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed May 2, 2021
2 parents 6bfdcb2 + 3d8593c commit 9c3371f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
Expand Up @@ -361,7 +361,15 @@ public function update($uids, $minimumStability = Updater::STABILITY_STABLE)
}

$update->loadFromXml($instance->detailsurl, $minimumStability);
$update->set('extra_query', $instance->extra_query);

// Find and use extra_query from update_site if available
$updateSiteInstance = JTable::getInstance('Updatesite');
$updateSiteInstance->load($instance->update_site_id);

if ($updateSiteInstance->extra_query)
{
$update->set('extra_query', $updateSiteInstance->extra_query);
}

$this->preparePreUpdate($update, $instance);

Expand Down
Expand Up @@ -322,6 +322,13 @@ public function rebuild(): void
// Gets Joomla core update sites Ids.
$joomlaUpdateSitesIds = $this->getJoomlaUpdateSitesIds(0);

// First backup any custom extra_query for the sites
$query = $db->getQuery(true)
->select('TRIM(' . $db->quoteName('location') . ') AS ' . $db->quoteName('location') . ', ' . $db->quoteName('extra_query'))
->from($db->quoteName('#__update_sites'));
$db->setQuery($query);
$backupExtraQuerys = $db->loadAssocList('location');

// Delete from all tables (except joomla core update sites).
$query = $db->getQuery(true)
->delete($db->quoteName('#__update_sites'))
Expand Down Expand Up @@ -406,6 +413,16 @@ public function rebuild(): void
$tmpInstaller->manifest = $manifest;
$tmpInstaller->setPath('manifest', $file);

// Remove last extra_query as we are in a foreach
$tmpInstaller->extraQuery = '';

if ($tmpInstaller->manifest->updateservers
&& $tmpInstaller->manifest->updateservers->server
&& isset($backupExtraQuerys[trim((string) $tmpInstaller->manifest->updateservers->server)]))
{
$tmpInstaller->extraQuery = $backupExtraQuerys[trim((string) $tmpInstaller->manifest->updateservers->server)]['extra_query'];
}

// Load the extension plugin (if not loaded yet).
PluginHelper::importPlugin('extension', 'joomla');

Expand Down
Expand Up @@ -105,6 +105,9 @@
<br>
<span class="small break-word">
<a href="<?php echo $item->location; ?>" target="_blank" rel="noopener noreferrer"><?php echo $this->escape($item->location); ?></a>
<?php if ($item->extra_query): ?>
<br/><pre><?php echo $item->extra_query; ?></pre>
<?php endif; ?>
</span>
<br>
<span class="small break-word">
Expand Down
8 changes: 8 additions & 0 deletions libraries/src/Installer/Installer.php
Expand Up @@ -121,6 +121,14 @@ class Installer extends Adapter
*/
protected $packageUninstall = false;

/**
* Backup extra_query during update_sites rebuild
*
* @var string
* @since __DEPLOY_VERSION__
*/
public $extraQuery = '';

/**
* JInstaller instances container.
*
Expand Down
20 changes: 11 additions & 9 deletions plugins/extension/joomla/joomla.php
Expand Up @@ -52,16 +52,17 @@ class PlgExtensionJoomla extends CMSPlugin
/**
* Adds an update site to the table if it doesn't exist.
*
* @param string $name The friendly name of the site
* @param string $type The type of site (e.g. collection or extension)
* @param string $location The URI for the site
* @param boolean $enabled If this site is enabled
* @param string $name The friendly name of the site
* @param string $type The type of site (e.g. collection or extension)
* @param string $location The URI for the site
* @param boolean $enabled If this site is enabled
* @param string $extraQuery Any additional request query to use when updating
*
* @return void
*
* @since 1.6
*/
private function addUpdateSite($name, $type, $location, $enabled)
private function addUpdateSite($name, $type, $location, $enabled, $extraQuery = '')
{
// Look if the location is used already; doesn't matter what type you can't have two types at the same address, doesn't make sense
$db = $this->db;
Expand All @@ -82,12 +83,13 @@ private function addUpdateSite($name, $type, $location, $enabled)
$enabled = (int) $enabled;
$query->clear()
->insert($db->quoteName('#__update_sites'))
->columns($db->quoteName(['name', 'type', 'location', 'enabled']))
->values(':name, :type, :location, :enabled')
->columns($db->quoteName(['name', 'type', 'location', 'enabled', 'extra_query']))
->values(':name, :type, :location, :enabled, :extra_query')
->bind(':name', $name)
->bind(':type', $type)
->bind(':location', $location)
->bind(':enabled', $enabled, ParameterType::INTEGER);
->bind(':enabled', $enabled, ParameterType::INTEGER)
->bind(':extra_query', $extraQuery);

$db->setQuery($query);

Expand Down Expand Up @@ -289,7 +291,7 @@ private function processUpdateSites()
foreach ($children as $child)
{
$attrs = $child->attributes();
$this->addUpdateSite($attrs['name'], $attrs['type'], trim($child), true);
$this->addUpdateSite($attrs['name'], $attrs['type'], trim($child), true, $this->installer->extraQuery);
}
}
else
Expand Down

0 comments on commit 9c3371f

Please sign in to comment.