When I install myplugin the very first time, it should update the location
column in #__update_sites
table with updated string which includes the API key.
I'm unable to update at first install as I my query doesnt get the update_site_id
from #__update_sites_extensions
.
I wonder why? Due to this I'm unable to update the string. Only following installation can.
Can anyone advise, at which stage joomla actually updates the #__update_sites_extensions
with the location/ url
?
Also is there a way to prevent Joomla inserting into this table the url
on every installation?
in xml file:
<updateservers>
<server type="extension" name="myplugin Update Site">https://test.com/jupdates/manifest/myplugin</server>
</updateservers>
In script.php
public function postflight()
{
$extensionId = $this->getExtensionId();
$updateSiteId = $this->updateSiteId($extensionId);
$defaultLocation = 'https://test.com/jupdates/manifest/myplugin';
$location = $defaultLocation . '?apikey=' . APIKEY;
update the location string with api key
$db = JFactory::getDBO();
$query = array();
$query = 'UPDATE '. $db->quoteName('#__update_sites')
. ' SET ' . $db->quoteName('location') . ' = ' . $db->Quote($location)
. ' WHERE ' . $db->quoteName('update_site_id') . ' = ' . $db->Quote($updateSiteId);
$db->setQuery($query);
$db->query();
}
functions:
public function getExtensionId()
{
$db = JFactory::getDBO();
$query = array();
$query[] = 'SELECT ' . $db->quoteName('extension_id') . ' FROM ' . $db->quoteName('#__extensions');
$query[] = 'WHERE ' . $db->quoteName('element') . '=' . $db->Quote('myplugin');
$query[] = 'AND ' . $db->quoteName('type') . '=' . $db->Quote('plugin');
$query = implode(' ', $query);
$db->setQuery($query);
$extensionId = $db->loadResult();
return $extensionId;
}
public function updateSiteId($extensionId)
{
$db = JFactory::getDBO();
$query = array();
$query[] = 'SELECT ' . $db->quoteName('update_site_id') . ' FROM ' . $db->quoteName('#__update_sites_extensions');
$query[] = 'WHERE ' . $db->quoteName('extension_id') . '=' . $db->Quote($extensionId);
$query = implode(' ', $query);
$db->setQuery($query);
$updateSiteId = $db->loadResult();
return $updateSiteId;
}
postflight
function, what happens if you addvar_dump($extensionId); var_dump($updateSiteId); exit;
? You should get some data dumped either on the page or in your browser console.