60a9d81e22
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 30s
Gate the success/license path in both installer scripts so a partial install can no longer report success. - Package script (pkg_mokosuitecross): add missingChildExtensions(), which reads the package manifest via getParent()->getManifest() and verifies each declared <file> child is registered in #__extensions (matching element+type, plus folder=group for plugins). If any are missing, enqueue an error and return before warnMissingLicenseKey(). Housekeeping (download-key restore, core-plugin enable, PerfectPublisher migration detection) still runs unconditionally. - Component script (com_mokosuitecross): postflight was empty. Add missingTables(), which parses the installed sql/install.mysql.sql for every CREATE TABLE and verifies each exists (prefix-substituted, case-insensitive). On any missing tables, enqueue an error and return before the success message; otherwise show install-success/license notice. Both checks fail open (try/catch returning []/true) so a glitch never turns a good install into a false failure. Extension names are htmlspecialchars'd. Claude-Session: https://claude.ai/code/session_01MrxXW9iyuDda5yDZrjZMbF
100 lines
3.3 KiB
PHP
100 lines
3.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @package MokoSuiteCross
|
|
* @subpackage com_mokosuitecross
|
|
* @author Moko Consulting <hello@mokoconsulting.tech>
|
|
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
|
* @license GNU General Public License version 3 or later; see LICENSE
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\Factory;
|
|
use Joomla\CMS\Installer\InstallerAdapter;
|
|
|
|
class Com_MokoSuiteCrossInstallerScript
|
|
{
|
|
public function preflight(string $type, InstallerAdapter $parent): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function postflight(string $type, InstallerAdapter $parent): void
|
|
{
|
|
if ($type !== 'install') {
|
|
return;
|
|
}
|
|
|
|
// Be smart: verify EVERY table the component's own install SQL declares is
|
|
// actually present. If any are missing the install did not complete — say
|
|
// so instead of implying "installed successfully".
|
|
$missing = $this->missingTables();
|
|
|
|
if ($missing !== []) {
|
|
$detail = count($missing) > 6
|
|
? count($missing) . ' expected database tables are missing'
|
|
: 'missing tables: ' . htmlspecialchars(implode(', ', $missing), ENT_QUOTES, 'UTF-8');
|
|
|
|
Factory::getApplication()->enqueueMessage(
|
|
'<strong>MokoSuiteCross did not install correctly.</strong> ' . $detail
|
|
. ' — review the errors above, then reinstall.',
|
|
'error'
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
// Success path: schema installed correctly.
|
|
Factory::getApplication()->enqueueMessage(
|
|
'<h4>MokoSuiteCross installed successfully!</h4>'
|
|
. '<p>To enable automatic updates, enter your license key in the '
|
|
. '<a href="index.php?option=com_config&view=component&component=com_mokosuitecross">component configuration</a>.</p>',
|
|
'info'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Smart schema check: parse the component's own installed install SQL for every
|
|
* CREATE TABLE, then return the ones missing from the database. An empty array
|
|
* means the full schema installed. Fails open (returns []) if the SQL can't be
|
|
* read, so a good install is never flagged as failed.
|
|
*
|
|
* @return string[] Names (without the #__ prefix) of missing tables.
|
|
*/
|
|
private function missingTables(): array
|
|
{
|
|
try {
|
|
$sqlFile = JPATH_ADMINISTRATOR . '/components/com_mokosuitecross/sql/install.mysql.sql';
|
|
|
|
if (!is_file($sqlFile)) {
|
|
return [];
|
|
}
|
|
|
|
$sql = file_get_contents($sqlFile);
|
|
|
|
if ($sql === false
|
|
|| !preg_match_all('/CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"\']?(#__[A-Za-z0-9_]+)/i', $sql, $m)) {
|
|
return [];
|
|
}
|
|
|
|
$db = Factory::getDbo();
|
|
$prefix = strtolower($db->getPrefix());
|
|
$have = array_map('strtolower', $db->getTableList());
|
|
$missing = [];
|
|
|
|
foreach (array_unique($m[1]) as $decl) {
|
|
$bare = substr($decl, 3); // strip "#__"
|
|
if (!in_array($prefix . strtolower($bare), $have, true)) {
|
|
$missing[] = $bare;
|
|
}
|
|
}
|
|
|
|
return $missing;
|
|
} catch (\Throwable $e) {
|
|
return [];
|
|
}
|
|
}
|
|
}
|