fix(installer): gate update() on schema + use enqueueMessage for success
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
RC Revert / Rename rc/ back to dev/ (pull_request) Has been skipped
Branch Cleanup / Delete merged branch (pull_request) Failing after 1s
Universal: PR Check / Validate PR (pull_request) Failing after 5s
Universal: PR Check / Secret Scan (pull_request) Successful in 8s
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Failing after 9s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Failing after 5s
Generic: Project CI / Lint & Validate (pull_request) Successful in 27s
Generic: Project CI / Tests (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
RC Revert / Rename rc/ back to dev/ (pull_request) Has been skipped
Branch Cleanup / Delete merged branch (pull_request) Failing after 1s
Universal: PR Check / Validate PR (pull_request) Failing after 5s
Universal: PR Check / Secret Scan (pull_request) Successful in 8s
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Failing after 9s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Failing after 5s
Generic: Project CI / Lint & Validate (pull_request) Successful in 27s
Generic: Project CI / Tests (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Mirrors the install() smart-check on update() and replaces echo with a proper Joomla message for consistency. Claude-Session: https://claude.ai/code/session_01MrxXW9iyuDda5yDZrjZMbF
This commit is contained in:
@@ -1,102 +1,119 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteOpenGraph
|
||||
* @subpackage com_mokoog
|
||||
* @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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Installer\InstallerAdapter;
|
||||
|
||||
class Com_MokoOGInstallerScript
|
||||
{
|
||||
/**
|
||||
* Called after install.
|
||||
*
|
||||
* @param InstallerAdapter $parent Installer adapter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function install(InstallerAdapter $parent): void
|
||||
{
|
||||
// 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 showing "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>MokoSuiteOpenGraph did not install correctly.</strong> ' . $detail
|
||||
. ' — review the errors above, then reinstall.',
|
||||
'error'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<p>MokoSuiteOpenGraph component installed successfully.</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after update.
|
||||
*
|
||||
* @param InstallerAdapter $parent Installer adapter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update(InstallerAdapter $parent): void
|
||||
{
|
||||
echo '<p>MokoSuiteOpenGraph component updated successfully.</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_mokoog/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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteOpenGraph
|
||||
* @subpackage com_mokoog
|
||||
* @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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Installer\InstallerAdapter;
|
||||
|
||||
class Com_MokoOGInstallerScript
|
||||
{
|
||||
/**
|
||||
* Called after install.
|
||||
*
|
||||
* @param InstallerAdapter $parent Installer adapter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function install(InstallerAdapter $parent): void
|
||||
{
|
||||
// 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 showing "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>MokoSuiteOpenGraph did not install correctly.</strong> ' . $detail
|
||||
. ' — review the errors above, then reinstall.',
|
||||
'error'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Factory::getApplication()->enqueueMessage('<h4>MokoSuiteOpenGraph installed successfully!</h4>', 'info');
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after update.
|
||||
*
|
||||
* @param InstallerAdapter $parent Installer adapter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update(InstallerAdapter $parent): void
|
||||
{
|
||||
// Same smart check on update: only report success if the schema is intact.
|
||||
$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>MokoSuiteOpenGraph did not update correctly.</strong> ' . $detail
|
||||
. ' — review the errors above.',
|
||||
'error'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Factory::getApplication()->enqueueMessage('MokoSuiteOpenGraph updated successfully.', '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_mokoog/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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user