Files
MokoSuiteConstruction/source/script.php
T
jmiller 96d6491cb6
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Universal: PR Check / Secret Scan (pull_request) Successful in 5s
Universal: PR Check / Validate PR (pull_request) Failing after 4s
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Successful in 11s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
feat: add post-install verification to detect failed sub-extensions
Checks that all expected component and plugins registered in
#__extensions after install. Disables the package entry and shows
an error if any sub-extension failed to install.

Claude-Session: https://claude.ai/code/session_01CwLGvFJPjoPTp9BEnSjtJf
2026-07-05 22:32:01 -05:00

164 lines
4.4 KiB
PHP

<?php
/**
* @package MokoSuiteConstruction
* @subpackage pkg_mokosuiteconstruction
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Log\Log;
/**
* Package installation script for MokoSuiteConstruction.
*/
class Pkg_MokoSuiteConstructionInstallerScript
{
private const EXPECTED_EXTENSIONS = [
['type' => 'component', 'element' => 'com_mokosuiteconstruction'],
['type' => 'plugin', 'element' => 'mokosuiteconstruction', 'folder' => 'system'],
['type' => 'plugin', 'element' => 'mokosuiteconstruction', 'folder' => 'webservices'],
];
private const PACKAGE_ELEMENT = 'pkg_mokosuiteconstruction';
private const PACKAGE_LABEL = 'MokoSuite Construction';
public function postflight(string $type, InstallerAdapter $adapter): void
{
if ($type === 'install')
{
$missing = $this->verifyInstallation();
if (!empty($missing))
{
Factory::getApplication()->enqueueMessage(
'<strong>' . self::PACKAGE_LABEL . ' — Incomplete Installation</strong><br>'
. 'The following extensions failed to install: '
. implode(', ', $missing)
. '.<br>Please check file permissions and server logs, then reinstall the package.',
'error'
);
$this->setPackageEnabled(false);
return;
}
}
$this->warnMissingLicenseKey();
}
private function verifyInstallation(): array
{
$missing = [];
try
{
$db = Factory::getDbo();
foreach (self::EXPECTED_EXTENSIONS as $ext)
{
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote($ext['type']))
->where($db->quoteName('element') . ' = ' . $db->quote($ext['element']));
if (isset($ext['folder']))
{
$query->where($db->quoteName('folder') . ' = ' . $db->quote($ext['folder']));
}
$db->setQuery($query);
if ((int) $db->loadResult() === 0)
{
$label = isset($ext['folder'])
? $ext['type'] . ':' . $ext['folder'] . '/' . $ext['element']
: $ext['type'] . ':' . $ext['element'];
$missing[] = $label;
}
}
}
catch (\Throwable $e)
{
Log::add(self::PACKAGE_LABEL . ' install verification failed: ' . $e->getMessage(), Log::ERROR, 'mokosuite');
$missing[] = 'verification query failed';
}
return $missing;
}
private function setPackageEnabled(bool $enabled): void
{
try
{
$db = Factory::getDbo();
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('enabled') . ' = ' . ($enabled ? 1 : 0))
->where($db->quoteName('type') . ' = ' . $db->quote('package'))
->where($db->quoteName('element') . ' = ' . $db->quote(self::PACKAGE_ELEMENT))
);
$db->execute();
}
catch (\Throwable $e)
{
Log::add(self::PACKAGE_LABEL . ' failed to toggle package state: ' . $e->getMessage(), Log::ERROR, 'mokosuite');
}
}
private function warnMissingLicenseKey(): void
{
try
{
$db = Factory::getDbo();
$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('%MokoSuiteConstruction%')
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoSuiteConstruction%') . ')')
->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)
{
// Silent — avoid breaking install if update_sites query fails
}
}
}