input->getMethod() !== 'POST') { $this->sendJson(405, ['error' => 'POST required']); return; } $user = $app->getIdentity(); if (!$user->authorise('core.manage', 'com_installer')) { $this->sendJson(403, ['error' => 'Not authorized']); return; } try { $db = Factory::getDbo(); $db->setQuery($db->getQuery(true)->delete($db->quoteName('#__updates'))); $db->execute(); \Joomla\CMS\Updater\Updater::getInstance()->findUpdates(); $db->setQuery( $db->getQuery(true) ->select('COUNT(*)') ->from($db->quoteName('#__updates')) ->where($db->quoteName('extension_id') . ' != 0') ); $count = (int) $db->loadResult(); $this->sendJson(200, [ 'status' => 'ok', 'updates_found' => $count, 'message' => $count . ' update(s) available', ]); } catch (\Throwable $e) { $this->sendJson(500, [ 'error' => 'Update check failed', 'message' => $e->getMessage(), ]); } } /** * @param int $code HTTP status code * @param array $payload Response data * @return void */ private function sendJson(int $code, array $payload): void { $app = Factory::getApplication(); $app->setHeader('Content-Type', 'application/json', true); $app->setHeader('Status', (string) $code, true); echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); $app->close(); } }