2026-06-28 18:57:48 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2026-07-06 10:46:00 -05:00
|
|
|
* MokoSuite Library Package Install Script
|
|
|
|
|
*
|
|
|
|
|
* @package MokoSuite Library
|
2026-06-28 18:57:48 +00:00
|
|
|
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
2026-07-06 10:46:00 -05:00
|
|
|
* @license GPL-3.0-or-later
|
2026-06-28 18:57:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
|
use Joomla\CMS\Installer\InstallerAdapter;
|
2026-07-06 10:46:00 -05:00
|
|
|
use Joomla\Database\DatabaseInterface;
|
2026-06-28 18:57:48 +00:00
|
|
|
|
|
|
|
|
class Pkg_MokoSuiteLibraryInstallerScript
|
|
|
|
|
{
|
|
|
|
|
public function postflight(string $type, InstallerAdapter $adapter): void
|
|
|
|
|
{
|
2026-07-05 22:32:48 -05:00
|
|
|
if ($type === 'install')
|
|
|
|
|
{
|
2026-07-06 10:46:00 -05:00
|
|
|
$missing = $this->verifyChildren($adapter);
|
2026-07-05 22:32:48 -05:00
|
|
|
|
|
|
|
|
if (!empty($missing))
|
|
|
|
|
{
|
|
|
|
|
Factory::getApplication()->enqueueMessage(
|
2026-07-06 10:46:00 -05:00
|
|
|
'<strong>MokoSuite Library — Incomplete Installation</strong><br>'
|
2026-07-05 22:32:48 -05:00
|
|
|
. 'The following extensions failed to install: '
|
|
|
|
|
. implode(', ', $missing)
|
|
|
|
|
. '.<br>Please check file permissions and server logs, then reinstall the package.',
|
|
|
|
|
'error'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-07-06 10:46:00 -05:00
|
|
|
|
|
|
|
|
$this->enablePlugin('system', 'mokosuitelibrary');
|
|
|
|
|
$this->enablePlugin('webservices', 'mokosuitelibrary');
|
2026-07-05 22:32:48 -05:00
|
|
|
}
|
|
|
|
|
|
2026-06-28 18:57:48 +00:00
|
|
|
$this->warnMissingLicenseKey();
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-06 10:46:00 -05:00
|
|
|
private function verifyChildren(InstallerAdapter $adapter): array
|
2026-07-05 22:32:48 -05:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-07-06 10:46:00 -05:00
|
|
|
$manifest = $adapter->getParent()->getManifest();
|
|
|
|
|
$files = $manifest->files->file ?? [];
|
2026-07-05 22:32:48 -05:00
|
|
|
|
2026-07-06 10:46:00 -05:00
|
|
|
if (!$files)
|
2026-07-05 22:32:48 -05:00
|
|
|
{
|
2026-07-06 10:46:00 -05:00
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$db = Factory::getContainer()->get(DatabaseInterface::class);
|
|
|
|
|
$missing = [];
|
|
|
|
|
|
|
|
|
|
foreach ($files as $file)
|
|
|
|
|
{
|
|
|
|
|
$type = (string) ($file['type'] ?? '');
|
|
|
|
|
$id = (string) ($file['id'] ?? '');
|
|
|
|
|
$group = (string) ($file['group'] ?? '');
|
|
|
|
|
|
|
|
|
|
if ($type === '' || $id === '')
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$element = ($type === 'plugin' && $group !== '')
|
|
|
|
|
? preg_replace('/^plg_' . preg_quote($group, '/') . '_/', '', $id)
|
|
|
|
|
: $id;
|
|
|
|
|
|
2026-07-05 22:32:48 -05:00
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->select('COUNT(*)')
|
|
|
|
|
->from($db->quoteName('#__extensions'))
|
2026-07-06 10:46:00 -05:00
|
|
|
->where($db->quoteName('element') . ' = ' . $db->quote($element))
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote($type));
|
2026-07-05 22:32:48 -05:00
|
|
|
|
2026-07-06 10:46:00 -05:00
|
|
|
if ($type === 'plugin' && $group !== '')
|
2026-07-05 22:32:48 -05:00
|
|
|
{
|
2026-07-06 10:46:00 -05:00
|
|
|
$query->where($db->quoteName('folder') . ' = ' . $db->quote($group));
|
2026-07-05 22:32:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
|
|
|
|
|
if ((int) $db->loadResult() === 0)
|
|
|
|
|
{
|
2026-07-06 10:46:00 -05:00
|
|
|
$missing[] = htmlspecialchars($type . ': ' . $id, ENT_QUOTES, 'UTF-8');
|
2026-07-05 22:32:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
2026-07-06 10:46:00 -05:00
|
|
|
|
|
|
|
|
return $missing;
|
2026-07-05 22:32:48 -05:00
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
2026-07-06 10:46:00 -05:00
|
|
|
return [];
|
2026-07-05 22:32:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-06 10:46:00 -05:00
|
|
|
private function enablePlugin(string $group, string $element): void
|
2026-07-05 22:32:48 -05:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-07-06 10:46:00 -05:00
|
|
|
$db = Factory::getContainer()->get(DatabaseInterface::class);
|
2026-07-05 22:32:48 -05:00
|
|
|
$db->setQuery(
|
|
|
|
|
$db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__extensions'))
|
2026-07-06 10:46:00 -05:00
|
|
|
->set($db->quoteName('enabled') . ' = 1')
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
|
|
|
|
|
->where($db->quoteName('folder') . ' = ' . $db->quote($group))
|
|
|
|
|
->where($db->quoteName('element') . ' = ' . $db->quote($element))
|
2026-07-05 22:32:48 -05:00
|
|
|
);
|
|
|
|
|
$db->execute();
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-28 18:57:48 +00:00
|
|
|
private function warnMissingLicenseKey(): void
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-07-06 10:46:00 -05:00
|
|
|
$db = Factory::getContainer()->get(DatabaseInterface::class);
|
2026-06-28 18:57:48 +00:00
|
|
|
$app = Factory::getApplication();
|
|
|
|
|
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->select([$db->quoteName('update_site_id'), $db->quoteName('extra_query')])
|
|
|
|
|
->from($db->quoteName('#__update_sites'))
|
|
|
|
|
->where('(' . $db->quoteName('name') . ' LIKE ' . $db->quote('%MokoSuiteLibrary%')
|
|
|
|
|
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoSuiteLibrary%') . ')')
|
|
|
|
|
->setLimit(1);
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$site = $db->loadObject();
|
|
|
|
|
|
|
|
|
|
if ($site)
|
|
|
|
|
{
|
|
|
|
|
$extraQuery = (string) ($site->extra_query ?? '');
|
|
|
|
|
|
|
|
|
|
if (!empty($extraQuery) && strpos($extraQuery, 'dlid=') !== false)
|
|
|
|
|
{
|
|
|
|
|
parse_str($extraQuery, $parsed);
|
|
|
|
|
|
|
|
|
|
if (!empty($parsed['dlid']))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$editUrl = 'index.php?option=com_installer&task=updatesite.edit&update_site_id=' . (int) $site->update_site_id;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$editUrl = 'index.php?option=com_installer&view=updatesites';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$app->enqueueMessage(
|
|
|
|
|
'<strong>Moko Consulting License Key Required</strong> — '
|
|
|
|
|
. 'No download key is configured. Updates will not be available until a valid license key is entered. '
|
|
|
|
|
. '<a href="' . $editUrl . '" class="btn btn-sm btn-warning ms-2">Enter License Key</a>',
|
|
|
|
|
'warning'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|