Files
Jonathan Miller b73c1eba25
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Generic: Project CI / Tests (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: mokoplatform CI / CI Summary (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
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Generic: Repo Health / Site Health (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Has been cancelled
Generic: Repo Health / Access control (pull_request) Has been cancelled
Universal: Build & Release / Promote to RC (pull_request) Has been cancelled
RC Revert / Rename rc/ back to dev/ (pull_request) Has been cancelled
Universal: Security Audit / Dependency Audit (pull_request) Has been cancelled
Branch Cleanup / Delete merged branch (pull_request) Has been cancelled
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Has been cancelled
Universal: PR Check / Validate PR (pull_request) Has been cancelled
Universal: Build & Release / Build & Release Pipeline (pull_request) Has been cancelled
Generic: Project CI / Lint & Validate (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 1: Code Quality (pull_request) Has been cancelled
feat: add manifest_detect.php CLI tool for auto-detecting manifest fields
Scans source files to detect platform, name, version, element_name,
package_type, language, entry_point, description, and license_spdx.
Supports Joomla, Dolibarr, Go, MCP/Node, and generic platforms.

Includes --diff and --update modes for comparing against and pushing
to the Gitea manifest API. Warns on missing core fields.

Also removes deprecated mcp/servers/mokowaas_api (consolidated to
separate repo) and syncs dev branch changes.
2026-06-07 15:37:24 -05:00

168 lines
5.0 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
/**
* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
*
* This file is part of a Moko Consulting project.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* FILE INFORMATION
* DEFGROUP: MokoPlatform.Scripts.Maintenance
* INGROUP: MokoPlatform
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
* PATH: /maintenance/update_sha_hashes.php
* BRIEF: Update SHA-256 hashes in script registry
*/
declare(strict_types=1);
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
use MokoEnterprise\CliFramework;
class UpdateShaHashesCli extends CliFramework
{
private const REGISTRY_PATH = '.script-registry.json';
private array $changes = [];
protected function configure(): void
{
$this->setDescription('Update SHA-256 hashes for all scripts in the registry');
}
protected function run(): int
{
$this->logForced("SHA-256 Hash Update Tool");
$this->logForced(str_repeat("=", 50));
if ($this->dryRun) {
$this->logForced("Mode: DRY RUN (no changes will be made)");
}
// Load registry
$registry = $this->loadRegistry();
// Update hashes
$updatedRegistry = $this->updateHashes($registry);
// Save if not dry run and there are changes
if (!$this->dryRun && !empty($this->changes)) {
$this->saveRegistry($updatedRegistry);
$this->logForced("\nRegistry updated successfully");
} elseif (empty($this->changes)) {
$this->logForced("\nNo changes needed - all hashes are current");
} else {
$this->logForced("\nDry run complete - changes detected but not applied");
}
return 0;
}
private function loadRegistry(): array
{
if (!file_exists(self::REGISTRY_PATH)) {
throw new \Exception("Registry file not found: " . self::REGISTRY_PATH);
}
$content = file_get_contents(self::REGISTRY_PATH);
$registry = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Exception("Failed to parse registry JSON: " . json_last_error_msg());
}
$this->logVerbose("Registry loaded: " . count($registry['scripts']) . " scripts tracked");
return $registry;
}
private function updateHashes(array $registry): array
{
$this->logVerbose("\nChecking scripts for changes...\n");
foreach ($registry['scripts'] as $index => &$script) {
$path = $script['path'];
if (!file_exists($path)) {
$this->logForced("Skipping missing file: {$path}");
continue;
}
// Calculate current hash
$currentHash = hash_file('sha256', $path);
$currentSize = filesize($path);
// Check if changed
if ($currentHash !== $script['sha256']) {
$this->changes[] = [
'path' => $path,
'old_hash' => $script['sha256'],
'new_hash' => $currentHash,
];
$this->logForced("Hash updated: {$path}");
if ($this->verbose) {
$this->logVerbose(" Old: {$script['sha256']}");
$this->logVerbose(" New: {$currentHash}");
}
// Update in registry
$script['sha256'] = $currentHash;
$script['size_bytes'] = $currentSize;
} else {
$this->logVerbose("No change: {$path}");
}
}
// Update metadata timestamp if there are changes
if (!empty($this->changes)) {
$microtime = microtime(true);
$dt = \DateTime::createFromFormat('U.u', sprintf('%.6f', $microtime), new \DateTimeZone('UTC'));
if ($dt === false) {
throw new \Exception("Failed to create DateTime from microtime");
}
$registry['metadata']['generated_at'] = $dt->format('Y-m-d\TH:i:s.u\Z');
}
$this->logForced("\nSummary:");
$this->logForced(" Total scripts: " . count($registry['scripts']));
$this->logForced(" Changed: " . count($this->changes));
return $registry;
}
private function saveRegistry(array $registry): void
{
$json = json_encode($registry, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
if ($json === false) {
throw new \Exception("Failed to encode registry JSON: " . json_last_error_msg());
}
if (file_put_contents(self::REGISTRY_PATH, $json) === false) {
throw new \Exception("Failed to write registry file");
}
$this->logVerbose("Registry saved: " . self::REGISTRY_PATH);
}
private function logForced(string $message): void
{
echo $message . "\n";
}
private function logVerbose(string $message): void
{
if ($this->verbose) {
echo $message . "\n";
}
}
}
$app = new UpdateShaHashesCli();
exit($app->execute());