MANAGE_APP_ROOT . "/includes/after-update.php", // "callback" => "myProjectAfterUpdate", // ]); // // This file must be part of the release package, otherwise it's missing // after the first update. /** * @param array $context app_root, instance, from_version, to_version, * backup_dir, run_id, migrations, pdo if configured */ function myProjectAfterUpdate(array $context): void { // 1. Discard compiled templates and caches. foreach (glob($context["app_root"] . "/data/cache/*.php") ?: [] as $file) { @unlink($file); } // 2. Create directories a new release requires. $newDir = $context["app_root"] . "/data/exports"; if (!is_dir($newDir) && !mkdir($newDir, 02775, true) && !is_dir($newDir)) { throw new RuntimeException("Could not create directory: " . $newDir); } // 3. Log for traceability. @file_put_contents( $context["app_root"] . "/data/update-history.log", sprintf( "%s %s -> %s (migrations: %s)%s", date(DATE_ATOM), $context["from_version"] !== "" ? $context["from_version"] : "unknown", $context["to_version"], $context["migrations"] === [] ? "none" : implode(", ", $context["migrations"]), PHP_EOL, ), FILE_APPEND | LOCK_EX, ); // To report failure: throw an exception, return false, or // return ["success" => false, "error" => "…"]. }