Public Access
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
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.
132 lines
3.4 KiB
PHP
132 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Recovery Manager - High-level manager for recovery operations
|
|
*
|
|
* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
* DEFGROUP: MokoPlatform.Enterprise.Recovery
|
|
* INGROUP: MokoPlatform.Enterprise
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
|
* PATH: /lib/Enterprise/RecoveryManager.php
|
|
* BRIEF: Recovery manager for failed operations
|
|
*
|
|
* @package MokoPlatform\Enterprise
|
|
* @version 04.00.04
|
|
* @author mokoplatform Team
|
|
* @license GPL-3.0-or-later
|
|
*/
|
|
|
|
namespace MokoEnterprise;
|
|
|
|
use DateTime;
|
|
use DateTimeZone;
|
|
|
|
/**
|
|
* High-level manager for recovery operations.
|
|
*
|
|
* Features:
|
|
* - Check recovery availability
|
|
* - Recover operations from checkpoints
|
|
* - Track recovery history
|
|
* - Cleanup old checkpoints
|
|
*
|
|
* Example:
|
|
* ```php
|
|
* $manager = new RecoveryManager();
|
|
*
|
|
* if ($manager->canRecover('my_operation')) {
|
|
* $state = $manager->recoverOperation('my_operation');
|
|
* // Resume from saved state
|
|
* }
|
|
* ```
|
|
*/
|
|
class RecoveryManager
|
|
{
|
|
private CheckpointManager $checkpointManager;
|
|
/** @var array<array<string, mixed>> */
|
|
private array $recoveryLog = [];
|
|
|
|
/**
|
|
* Initialize recovery manager.
|
|
*
|
|
* @param string $checkpointDir Directory for checkpoints
|
|
*/
|
|
public function __construct(string $checkpointDir = '.checkpoints')
|
|
{
|
|
$this->checkpointManager = new CheckpointManager($checkpointDir);
|
|
}
|
|
|
|
/**
|
|
* Check if an operation can be recovered.
|
|
*
|
|
* @param string $operationName Name of the operation
|
|
* @return bool True if recovery checkpoint exists
|
|
*/
|
|
public function canRecover(string $operationName): bool
|
|
{
|
|
$checkpoints = $this->checkpointManager->listCheckpoints($operationName);
|
|
return count($checkpoints) > 0;
|
|
}
|
|
|
|
/**
|
|
* Recover an operation from checkpoint.
|
|
*
|
|
* @param string $operationName Name of the operation to recover
|
|
* @return array<string, mixed>|null Recovered state or null
|
|
*/
|
|
public function recoverOperation(string $operationName): ?array
|
|
{
|
|
error_log("Attempting to recover operation: {$operationName}");
|
|
$state = $this->checkpointManager->loadCheckpoint($operationName);
|
|
|
|
if ($state !== null) {
|
|
$this->recoveryLog[] = [
|
|
'operation' => $operationName,
|
|
'recovered_at' => (new DateTime('now', new DateTimeZone('UTC')))->format('c'),
|
|
'state' => $state,
|
|
];
|
|
error_log("Successfully recovered operation: {$operationName}");
|
|
} else {
|
|
error_log("No checkpoint found for operation: {$operationName}");
|
|
}
|
|
|
|
return $state;
|
|
}
|
|
|
|
/**
|
|
* Get recovery log.
|
|
*
|
|
* @return array<array<string, mixed>> List of recovery operations
|
|
*/
|
|
public function getRecoveryLog(): array
|
|
{
|
|
return $this->recoveryLog;
|
|
}
|
|
|
|
/**
|
|
* Clean up old checkpoints.
|
|
*
|
|
* @param int $keepLatest Number of latest checkpoints to keep per operation
|
|
*/
|
|
public function cleanupOldCheckpoints(int $keepLatest = 5): void
|
|
{
|
|
$this->checkpointManager->cleanupCheckpoints(null, $keepLatest);
|
|
}
|
|
|
|
/**
|
|
* Get checkpoint manager instance.
|
|
*
|
|
* @return CheckpointManager
|
|
*/
|
|
public function getCheckpointManager(): CheckpointManager
|
|
{
|
|
return $this->checkpointManager;
|
|
}
|
|
}
|