2

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;
}
1
  • Inside your postflight function, what happens if you add var_dump($extensionId); var_dump($updateSiteId); exit;? You should get some data dumped either on the page or in your browser console.
    – Lodder
    Commented Jan 18, 2017 at 11:49

1 Answer 1

1

The update server definition is not loaded to the database until the onExtensionAfterInstall event is dispatched, and this depends on the "Extension - Joomla" plugin being enabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.