migrate.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Data migration page, part of the update procedure: upload the new files, then
  4. * open this once and press the button.
  5. *
  6. * Nothing runs by itself. The application keeps reading old gallery files
  7. * correctly whether or not this has been run — see app/migrate.php — so this is
  8. * a tidy-up the operator triggers, never a gate that can lock a site out of its
  9. * own data after an FTP upload.
  10. */
  11. require dirname(__DIR__) . '/app/bootstrap.php';
  12. auth_require();
  13. $results = null;
  14. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  15. csrf_verify();
  16. // Large installations touch every gallery file; the work itself is small,
  17. // but there is no reason to be caught by a low default time limit.
  18. @set_time_limit(0);
  19. $results = migrate_run();
  20. flash_set('Migration finished.');
  21. }
  22. $pending = migrate_pending();
  23. admin_header('Data migration');
  24. flash_render();
  25. ?>
  26. <h1>Data migration</h1>
  27. <div class="card">
  28. <p class="help" style="margin-top:0;margin-bottom:1rem">
  29. Run this once after updating the software. It brings every gallery's data
  30. file up to the current format — currently schema version
  31. <?= (int)SCHEMA_VERSION ?>. It is safe to run again at any time: each step
  32. is written so that repeating it changes nothing, and no images, archives
  33. or S3 objects are ever removed.
  34. </p>
  35. <?php if ($results !== null): ?>
  36. <h2 style="margin-top:0">Result</h2>
  37. <table style="margin-bottom:1rem">
  38. <tr><th>Gallery</th><th style="width:110px">Applied</th><th>Notes</th></tr>
  39. <?php foreach ($results as $row): ?>
  40. <tr>
  41. <td><a href="gallery-edit.php?g=<?= e(rawurlencode($row['slug'])) ?>"><?= e($row['title']) ?></a></td>
  42. <td>
  43. <?php if ($row['error'] !== null): ?>
  44. <span class="tag tag-expired">failed</span>
  45. <?php elseif ($row['applied'] === []): ?>
  46. <span class="tag">up to date</span>
  47. <?php else: ?>
  48. <span class="tag tag-lock">v<?= e(implode(', v', $row['applied'])) ?></span>
  49. <?php endif; ?>
  50. </td>
  51. <td class="help" style="margin:0">
  52. <?php if ($row['error'] !== null): ?>
  53. <?= e($row['error']) ?>
  54. <?php else: ?>
  55. <?= $row['notes'] === [] ? '—' : e(implode(' ', $row['notes'])) ?>
  56. <?php endif; ?>
  57. </td>
  58. </tr>
  59. <?php endforeach; ?>
  60. <?php if ($results === []): ?>
  61. <tr><td colspan="3" class="help">No galleries yet.</td></tr>
  62. <?php endif; ?>
  63. </table>
  64. <?php endif; ?>
  65. <?php if ($pending === []): ?>
  66. <p style="margin-bottom:1rem">Everything is up to date.</p>
  67. <?php else: ?>
  68. <h2 style="margin-top:0">Pending</h2>
  69. <table style="margin-bottom:1rem">
  70. <tr><th>Gallery</th><th style="width:140px">Missing steps</th></tr>
  71. <?php foreach ($pending as $slug => $info): ?>
  72. <tr>
  73. <td><a href="gallery-edit.php?g=<?= e(rawurlencode($slug)) ?>"><?= e($info['title']) ?></a></td>
  74. <td>v<?= e(implode(', v', $info['versions'])) ?></td>
  75. </tr>
  76. <?php endforeach; ?>
  77. </table>
  78. <?php endif; ?>
  79. <form method="post">
  80. <?= csrf_field() ?>
  81. <button type="submit" style="margin:0">
  82. <?= $pending === [] ? 'Run again' : 'Run migration' ?>
  83. </button>
  84. </form>
  85. </div>
  86. <div class="card">
  87. <h2 style="margin-top:0">What version <?= (int)SCHEMA_VERSION ?> does</h2>
  88. <p class="help" style="margin:0">
  89. <strong>Topics.</strong> Galleries can now be split into named sections.
  90. Existing galleries need no conversion — they simply have no topics and
  91. look exactly as before — so this step only normalises the new fields and
  92. clears any leftover reference to a topic that does not exist.
  93. One thing it cannot do: photos uploaded through a guest link before the
  94. update are indistinguishable from your own, because nothing recorded who
  95. uploaded them. They stay without a topic. Guest uploads made from now on
  96. land in "<?= e(GALLERY_GUEST_TOPIC_NAME) ?>" automatically.
  97. </p>
  98. </div>
  99. <?php admin_footer(); ?>