Compare commits

..

2 Commits

Author SHA1 Message Date
jmiller f341c086a2 refactor(installer): replace hardcoded extension list with dynamic manifest verification
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
Universal: PR Check / Secret Scan (pull_request) Successful in 8s
Universal: PR Check / Validate PR (pull_request) Failing after 8s
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Successful in 36s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Read package manifest via $adapter->getParent()->getManifest() to discover
children dynamically instead of maintaining a hardcoded EXPECTED_EXTENSIONS
array. Fail-open pattern wraps verification in try/catch. Only the success
path (plugin enables, license warning) is gated; unconditional housekeeping
(DLID restore) runs regardless.

Claude-Session: https://claude.ai/code/session_01CwLGvFJPjoPTp9BEnSjtJf
2026-07-06 10:45:59 -05:00
jmiller 36cc6ee4b2 feat: add post-install verification to detect failed sub-extensions
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Universal: PR Check / Secret Scan (pull_request) Successful in 6s
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Successful in 12s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
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:21 -05:00
8 changed files with 134 additions and 67 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
# FILE INFORMATION # FILE INFORMATION
# DEFGROUP: Gitea.Workflow # DEFGROUP: Gitea.Workflow
# INGROUP: mokocli.Automation # INGROUP: mokocli.Automation
# VERSION: 06.00.24 # VERSION: 06.00.19
# BRIEF: Auto-create feature branch when an issue is opened # BRIEF: Auto-create feature branch when an issue is opened
name: "Universal: Issue Branch" name: "Universal: Issue Branch"
-3
View File
@@ -11,9 +11,6 @@
## [Unreleased] ## [Unreleased]
### Fixed
- **Honest install success** — the package installer no longer shows the license / next-steps message when a bundled child extension failed to install. A fail-open manifest verifier confirms every child extension landed in `#__extensions` and reports any that are missing.
### Added ### Added
- **Repository** -- initial repo creation with scaffolding - **Repository** -- initial repo creation with scaffolding
- **System Plugin** -- Extension class, service provider - **System Plugin** -- Extension class, service provider
@@ -3,7 +3,6 @@
; Authored-by: Moko Consulting ; Authored-by: Moko Consulting
COM_MOKOSUITEFIELD="MokoSuite Field" COM_MOKOSUITEFIELD="MokoSuite Field"
COM_MOKOSUITEFIELD_SHORT="Field"
COM_MOKOSUITEFIELD_DESCRIPTION="Field service management for contractors." COM_MOKOSUITEFIELD_DESCRIPTION="Field service management for contractors."
COM_MOKOSUITEFIELD_MENU_DASHBOARD="Dashboard" COM_MOKOSUITEFIELD_MENU_DASHBOARD="Dashboard"
COM_MOKOSUITEFIELD_MENU_WORKORDERS="Work Orders" COM_MOKOSUITEFIELD_MENU_WORKORDERS="Work Orders"
@@ -5,10 +5,10 @@
<creationDate>2026-06-27</creationDate> <creationDate>2026-06-27</creationDate>
<copyright>Copyright (C) 2026 Moko Consulting.</copyright> <copyright>Copyright (C) 2026 Moko Consulting.</copyright>
<license>GPL-3.0-or-later</license> <license>GPL-3.0-or-later</license>
<version>06.00.24</version> <version>06.00.19</version>
<namespace path="src">Moko\Component\MokoSuiteField</namespace> <namespace path="src">Moko\Component\MokoSuiteField</namespace>
<administration> <administration>
<files folder="admin"><folder>services</folder><folder>src</folder><folder>tmpl</folder></files> <files folder="admin"><folder>services</folder><folder>src</folder><folder>tmpl</folder></files>
<menu>COM_MOKOSUITEFIELD_SHORT</menu> <menu>COM_MOKOSUITEFIELD</menu>
</administration> </administration>
</extension> </extension>
@@ -8,7 +8,7 @@
<license>GPL-3.0-or-later</license> <license>GPL-3.0-or-later</license>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl> <authorUrl>https://mokoconsulting.tech</authorUrl>
<version>06.00.24</version> <version>06.00.19</version>
<php_minimum>8.3</php_minimum> <php_minimum>8.3</php_minimum>
<description>PLG_SYSTEM_MOKOSUITEFIELD_DESC</description> <description>PLG_SYSTEM_MOKOSUITEFIELD_DESC</description>
<namespace path="src">Moko\Plugin\System\MokoSuiteField</namespace> <namespace path="src">Moko\Plugin\System\MokoSuiteField</namespace>
@@ -3,7 +3,7 @@
<name>Web Services - MokoSuite Field</name> <name>Web Services - MokoSuite Field</name>
<element>mokosuitefield</element> <element>mokosuitefield</element>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<version>06.00.24</version> <version>06.00.19</version>
<license>GPL-3.0-or-later</license> <license>GPL-3.0-or-later</license>
<namespace path="src">Moko\Plugin\WebServices\MokoSuiteField</namespace> <namespace path="src">Moko\Plugin\WebServices\MokoSuiteField</namespace>
<files><folder>src</folder><folder>services</folder></files> <files><folder>src</folder><folder>services</folder></files>
+1 -1
View File
@@ -2,7 +2,7 @@
<extension type="package" method="upgrade"> <extension type="package" method="upgrade">
<name>Package - MokoSuite Field</name> <name>Package - MokoSuite Field</name>
<packagename>mokosuitefield</packagename> <packagename>mokosuitefield</packagename>
<version>06.00.24</version> <version>06.00.19</version>
<creationDate>2026-06-27</creationDate> <creationDate>2026-06-27</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
+121 -50
View File
@@ -1,9 +1,10 @@
<?php <?php
/** /**
* MokoSuite Field Package Install Script
*
* @package MokoSuite Field * @package MokoSuite Field
* @subpackage pkg_mokosuitefield
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved. * @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE * @license GPL-3.0-or-later
*/ */
defined('_JEXEC') or die; defined('_JEXEC') or die;
@@ -11,97 +12,99 @@ defined('_JEXEC') or die;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerAdapter; use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Log\Log; use Joomla\CMS\Log\Log;
use Joomla\Database\DatabaseInterface;
class Pkg_MokoSuiteFieldInstallerScript class Pkg_MokoSuiteFieldInstallerScript
{ {
private string $savedDlid = '';
public function preflight(string $type, InstallerAdapter $adapter): bool
{
if ($type === 'update')
{
$this->savedDlid = $this->getExistingDlid();
}
return true;
}
public function postflight(string $type, InstallerAdapter $adapter): void public function postflight(string $type, InstallerAdapter $adapter): void
{ {
// Be honest about success. Joomla's package installer only LOGS a failed child if ($this->savedDlid)
// sub-install but still runs this postflight, so don't show the license / {
// next-steps message if a bundled extension is actually missing. Fails open $this->restoreDlid($this->savedDlid);
// (see missingChildExtensions) so a query/IO glitch never fakes a failure. }
$missing = $this->missingChildExtensions($adapter);
if ($type === 'install')
{
$missing = $this->verifyChildren($adapter);
if (!empty($missing)) if (!empty($missing))
{ {
Factory::getApplication()->enqueueMessage( Factory::getApplication()->enqueueMessage(
'<h4>MokoSuiteField did not install correctly.</h4>' '<strong>MokoSuite Field — Incomplete Installation</strong><br>'
. '<p>The following bundled extensions are missing: ' . 'The following extensions failed to install: '
. htmlspecialchars(implode(', ', $missing), ENT_QUOTES) . '</p>' . implode(', ', $missing)
. '<p>Please uninstall MokoSuiteField and reinstall the full package.</p>', . '.<br>Please check file permissions and server logs, then reinstall the package.',
'error' 'error'
); );
return; return;
} }
$this->enablePlugin('system', 'mokosuitefield');
$this->enablePlugin('webservices', 'mokosuitefield');
}
$this->warnMissingLicenseKey(); $this->warnMissingLicenseKey();
} }
/** private function verifyChildren(InstallerAdapter $adapter): array
* Verify every child extension declared in the package manifest actually landed in
* #__extensions. Returns readable labels of any that are missing.
*
* Matching per Joomla's #__extensions uniqueness: type = <file> "type"; element =
* <file> "id" (for plugins, strip a leading plg_<group>_); plugins also match
* folder = <file> "group".
*
* FAILS OPEN: any error returns [] so a transient glitch never fakes a failure.
*/
private function missingChildExtensions($adapter): array
{ {
try try
{ {
$manifest = $adapter->getParent()->getManifest(); $manifest = $adapter->getParent()->getManifest();
$files = $manifest->files->file ?? [];
if (!$manifest || !isset($manifest->files) || !isset($manifest->files->file)) if (!$files)
{ {
return []; return [];
} }
$db = Factory::getDbo(); $db = Factory::getContainer()->get(DatabaseInterface::class);
$missing = []; $missing = [];
foreach ($manifest->files->file as $file) foreach ($files as $file)
{ {
$attrs = $file->attributes(); $type = (string) ($file['type'] ?? '');
$id = isset($attrs['id']) ? (string) $attrs['id'] : ''; $id = (string) ($file['id'] ?? '');
$exType = isset($attrs['type']) ? (string) $attrs['type'] : ''; $group = (string) ($file['group'] ?? '');
if ($id === '' || $exType === '') if ($type === '' || $id === '')
{ {
continue; continue;
} }
$group = isset($attrs['group']) ? (string) $attrs['group'] : ''; $element = ($type === 'plugin' && $group !== '')
$element = $id; ? preg_replace('/^plg_' . preg_quote($group, '/') . '_/', '', $id)
: $id;
// Plugin element in #__extensions is the id minus any leading plg_<group>_.
if ($exType === 'plugin' && $group !== '')
{
$prefix = 'plg_' . $group . '_';
if (strpos($element, $prefix) === 0)
{
$element = substr($element, \strlen($prefix));
}
}
$query = $db->getQuery(true) $query = $db->getQuery(true)
->select('COUNT(*)') ->select('COUNT(*)')
->from($db->quoteName('#__extensions')) ->from($db->quoteName('#__extensions'))
->where($db->quoteName('element') . ' = ' . $db->quote($element)) ->where($db->quoteName('element') . ' = ' . $db->quote($element))
->where($db->quoteName('type') . ' = ' . $db->quote($exType)); ->where($db->quoteName('type') . ' = ' . $db->quote($type));
if ($exType === 'plugin' && $group !== '') if ($type === 'plugin' && $group !== '')
{ {
$query->where($db->quoteName('folder') . ' = ' . $db->quote($group)); $query->where($db->quoteName('folder') . ' = ' . $db->quote($group));
} }
if ((int) $db->setQuery($query)->loadResult() === 0) $db->setQuery($query);
if ((int) $db->loadResult() === 0)
{ {
$label = trim((string) $file); $missing[] = htmlspecialchars($type . ': ' . $id, ENT_QUOTES, 'UTF-8');
$missing[] = $label !== '' ? preg_replace('/\.zip$/i', '', $label) : $id;
} }
} }
@@ -109,16 +112,85 @@ class Pkg_MokoSuiteFieldInstallerScript
} }
catch (\Throwable $e) catch (\Throwable $e)
{ {
// Fail open — never fake a failure on a glitch.
return []; return [];
} }
} }
private function getExistingDlid(): string
{
try
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery(
$db->getQuery(true)
->select($db->quoteName('extra_query'))
->from($db->quoteName('#__update_sites'))
->where('(' . $db->quoteName('name') . ' LIKE ' . $db->quote('%MokoSuiteField%')
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoSuiteField%') . ')')
->setLimit(1)
);
$extraQuery = $db->loadResult() ?? '';
if (preg_match('/dlid=([a-zA-Z0-9]+)/', $extraQuery, $matches))
{
return $matches[1];
}
}
catch (\Throwable $e)
{
Log::add('Field install: failed to read DLID — ' . $e->getMessage(), Log::WARNING, 'mokosuite.field');
}
return '';
}
private function restoreDlid(string $dlid): void
{
try
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__update_sites'))
->set($db->quoteName('extra_query') . ' = ' . $db->quote('dlid=' . $dlid))
->where('(' . $db->quoteName('name') . ' LIKE ' . $db->quote('%MokoSuiteField%')
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoSuiteField%') . ')')
);
$db->execute();
}
catch (\Throwable $e)
{
Log::add('Field install: failed to restore DLID — ' . $e->getMessage(), Log::WARNING, 'mokosuite.field');
}
}
private function enablePlugin(string $group, string $element): void
{
try
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__extensions'))
->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))
);
$db->execute();
}
catch (\Throwable $e)
{
Log::add('Field install: failed to enable ' . $group . '/' . $element . ' — ' . $e->getMessage(), Log::WARNING, 'mokosuite.field');
}
}
private function warnMissingLicenseKey(): void private function warnMissingLicenseKey(): void
{ {
try try
{ {
$db = Factory::getDbo(); $db = Factory::getContainer()->get(DatabaseInterface::class);
$app = Factory::getApplication(); $app = Factory::getApplication();
$query = $db->getQuery(true) $query = $db->getQuery(true)
@@ -160,7 +232,6 @@ class Pkg_MokoSuiteFieldInstallerScript
} }
catch (\Throwable $e) catch (\Throwable $e)
{ {
// Silent — avoid breaking install if update_sites query fails
} }
} }
} }