feat: add post-install verification to detect failed sub-extensions
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
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
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
This commit is contained in:
@@ -17,11 +17,100 @@ use Joomla\CMS\Log\Log;
|
||||
*/
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user