| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- /**
- * Post-update hook for the manage client (MANAGE_UPDATE_POST_HOOK).
- *
- * Runs after every successful deployment, after the release migrations in
- * migrations/ and only if those succeeded. At this point the new files are
- * already in place — there is no rollback — so this does housekeeping that is
- * safe to repeat and never anything that could fail a working installation.
- *
- * Deliberately not done here: the per-gallery data migration from
- * app/migrate.php. It touches every gallery file and stays an operator
- * decision, announced on the dashboard and run from admin/migrate.php.
- */
- declare(strict_types=1);
- /**
- * @param array $context app_root, instance, from_version, to_version,
- * backup_dir, run_id, migrations
- */
- function after_update_hook(array $context): void
- {
- $root = (string)$context['app_root'];
- // 1. Directories a fresh checkout does not have and an update never
- // creates by copying, because the release package carries no data.
- foreach ([$root . '/data', $root . '/data/galleries', $root . '/media'] as $dir) {
- if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
- throw new RuntimeException('Could not create directory: ' . $dir);
- }
- }
- // 2. The archive worker's lock. If the update landed while a gallery ZIP
- // was being built, that PHP process is gone but its lock file is not,
- // and every later run would refuse to start. The queue itself is left
- // alone — the next visitor kicks it (see app/archive.php).
- $lock = $root . '/data/archive.lock';
- if (is_file($lock) && time() - (int)@filemtime($lock) > 300) {
- @unlink($lock);
- }
- // 3. Discard compiled bytecode of the files just replaced, for hosts where
- // OPcache would otherwise keep serving the old code until it restarts.
- if (function_exists('opcache_reset') && ini_get('opcache.enable')) {
- @opcache_reset();
- }
- // 4. A line per update, so "when did this installation change" is
- // answerable without the manage server.
- @file_put_contents(
- $root . '/data/update-history.log',
- sprintf(
- "%s %s -> %s (migrations: %s)\n",
- date(DATE_ATOM),
- $context['from_version'] !== '' ? $context['from_version'] : 'unknown',
- $context['to_version'],
- $context['migrations'] === [] ? 'none' : implode(', ', $context['migrations']),
- ),
- FILE_APPEND | LOCK_EX,
- );
- }
|