after-update.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // Post-update callback, wired through MANAGE_UPDATE_POST_HOOK in config.php.
  3. //
  4. // Runs after the release files are in place and after all pending migrations
  5. // have succeeded. Migrations handle data changes; this handles the two things
  6. // that have to happen on every single deploy regardless of what changed.
  7. declare(strict_types=1);
  8. /**
  9. * @param array $context app_root, instance, from_version, to_version,
  10. * backup_dir, run_id, migrations
  11. *
  12. * @return array{success: bool, error?: string}
  13. */
  14. function shopAfterUpdate(array $context): array
  15. {
  16. $notes = [];
  17. // 1. The release package excludes data/, so a fresh install or a release
  18. // that adds a new working directory needs them recreated here.
  19. foreach ([MANAGE_DIR, MANAGE_BACKUP_DIR, MANAGE_WORK_DIR, MANAGE_UPDATE_BACKUP_DIR] as $dir) {
  20. try {
  21. manageEnsureDir((string) $dir);
  22. } catch (Throwable $exception) {
  23. return [
  24. 'success' => false,
  25. 'error' => 'Arbeitsverzeichnis konnte nicht angelegt werden: ' . $exception->getMessage(),
  26. ];
  27. }
  28. }
  29. // 2. OPcache caches compiled bytecode keyed by path and mtime. The deploy
  30. // just replaced PHP files underneath a running process, so without this
  31. // the shop can keep serving the previous release until the cache expires
  32. // on its own.
  33. if (function_exists('opcache_reset') && ini_get('opcache.enable')) {
  34. $notes[] = opcache_reset() ? 'opcache_reset' : 'opcache_reset_failed';
  35. }
  36. manageClientLog('INFO', 'shopAfterUpdate finished', [
  37. 'from_version' => (string) ($context['from_version'] ?? ''),
  38. 'to_version' => (string) ($context['to_version'] ?? ''),
  39. 'notes' => $notes,
  40. ]);
  41. return ['success' => true];
  42. }