Skip to content

Instantly share code, notes, and snippets.

@Septdir
Created February 28, 2020 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Septdir/08c23ead6b025dc84b63c75804dce11e to your computer and use it in GitHub Desktop.
Save Septdir/08c23ead6b025dc84b63c75804dce11e to your computer and use it in GitHub Desktop.
Install jYProExtra in insall script
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;
class type_nameInstallerScript
{
/**
* Runs right after any installation action.
*
* @param string $type Type of PostFlight action.
* @param InstallerAdapter $parent Parent object calling object.
*
* @throws Exception
*
* @return boolean True on success, false on failure.
*
* @since __DEPLOY_VERSION__
*/
function postflight($type, $parent)
{
// Install jYProExtra
if (!$this->installJYProExtra())
{
Factory::getApplication()->enqueueMessage(Text::_('ERROR_TEXT'), 'error');
return false;
}
return true;
}
/**
*
* Method to check jYProExtra plugin and install if need.
*
* @throws Exception
*
* @return boolean True on success, false on failure.
*
* @since __DEPLOY_VERSION__
*/
protected function installJYProExtra()
{
if (!PluginHelper::getPlugin('system', 'jyproextra'))
{
// Download the package at the URL given
if (!$p_file = InstallerHelper::downloadPackage(
'https://www.septdir.com/solutions/download?element=plg_system_jyproextra'))
{
return false;
}
// Unpack the downloaded package file
if (!$package = InstallerHelper::unpack(Factory::getConfig()->get('tmp_path') . '/' . $p_file, true))
{
return false;
}
// Check type
if (!$package['type'])
{
InstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
return false;
}
// Get an installer instance
$installer = Installer::getInstance();
$installer->setPath('source', $package['dir']);
if (!$installer->findManifest())
{
InstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
return false;
}
// Install the package
if (!$installer->install($package['dir']))
{
InstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
return false;
}
// CleanUp install
InstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment