after-update.php 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. // Post-update callback, wired up in manage-client/config.php as
  3. // MANAGE_UPDATE_POST_HOOK. It runs after a release has been deployed and after
  4. // the release's migrations have succeeded.
  5. //
  6. // The context is documented in the client package under
  7. // docs/07_POST_UPDATE_HOOKS.md: app_root, instance, from_version, to_version,
  8. // backup_dir, run_id and the migrations applied in this run.
  9. function psaAfterUpdate(array $context): void
  10. {
  11. $appRoot = rtrim((string) $context["app_root"], "/\\");
  12. // A release ships no data/ directory, so a new installation - or a release
  13. // that starts writing somewhere new - needs the writable directories to
  14. // exist before the first request hits them.
  15. foreach (["data", "data/uploads", "data/logs"] as $relative) {
  16. $directory = $appRoot . "/" . $relative;
  17. if (!is_dir($directory) && !mkdir($directory, 02775, true) && !is_dir($directory)) {
  18. throw new RuntimeException("Verzeichnis konnte nicht angelegt werden: " . $relative);
  19. }
  20. }
  21. // The deployment replaced PHP files underneath a running opcache. Resetting
  22. // it here only helps when the update was triggered from the admin panel;
  23. // from the CLI it is a no-op, because the web server runs its own cache.
  24. if (function_exists("opcache_reset") && ini_get("opcache.enable")) {
  25. @opcache_reset();
  26. }
  27. }