sidebarMigrations.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. BlazeComponent.extendComponent({
  4. onCreated() {
  5. this.migrationStatuses = new ReactiveVar({});
  6. this.loadMigrationStatuses();
  7. },
  8. loadMigrationStatuses() {
  9. const boardId = Session.get('currentBoard');
  10. if (!boardId) return;
  11. // Check comprehensive migration
  12. Meteor.call('comprehensiveBoardMigration.needsMigration', boardId, (err, res) => {
  13. if (!err) {
  14. const statuses = this.migrationStatuses.get();
  15. statuses.comprehensive = res;
  16. this.migrationStatuses.set(statuses);
  17. }
  18. });
  19. // Check fix missing lists migration
  20. Meteor.call('fixMissingListsMigration.needsMigration', boardId, (err, res) => {
  21. if (!err) {
  22. const statuses = this.migrationStatuses.get();
  23. statuses.fixMissingLists = res;
  24. this.migrationStatuses.set(statuses);
  25. }
  26. });
  27. // Check fix avatar URLs migration (global)
  28. Meteor.call('fixAvatarUrls.needsMigration', (err, res) => {
  29. if (!err) {
  30. const statuses = this.migrationStatuses.get();
  31. statuses.fixAvatarUrls = res;
  32. this.migrationStatuses.set(statuses);
  33. }
  34. });
  35. // Check fix all file URLs migration (global)
  36. Meteor.call('fixAllFileUrls.needsMigration', (err, res) => {
  37. if (!err) {
  38. const statuses = this.migrationStatuses.get();
  39. statuses.fixAllFileUrls = res;
  40. this.migrationStatuses.set(statuses);
  41. }
  42. });
  43. },
  44. comprehensiveMigrationNeeded() {
  45. return this.migrationStatuses.get().comprehensive === true;
  46. },
  47. fixMissingListsNeeded() {
  48. return this.migrationStatuses.get().fixMissingLists === true;
  49. },
  50. fixAvatarUrlsNeeded() {
  51. return this.migrationStatuses.get().fixAvatarUrls === true;
  52. },
  53. fixAllFileUrlsNeeded() {
  54. return this.migrationStatuses.get().fixAllFileUrls === true;
  55. },
  56. runMigration(migrationType) {
  57. const boardId = Session.get('currentBoard');
  58. let methodName;
  59. let methodArgs = [];
  60. switch (migrationType) {
  61. case 'comprehensive':
  62. methodName = 'comprehensiveBoardMigration.execute';
  63. methodArgs = [boardId];
  64. break;
  65. case 'fixMissingLists':
  66. methodName = 'fixMissingListsMigration.execute';
  67. methodArgs = [boardId];
  68. break;
  69. case 'fixAvatarUrls':
  70. methodName = 'fixAvatarUrls.execute';
  71. break;
  72. case 'fixAllFileUrls':
  73. methodName = 'fixAllFileUrls.execute';
  74. break;
  75. }
  76. if (methodName) {
  77. Meteor.call(methodName, ...methodArgs, (err, result) => {
  78. if (err) {
  79. console.error('Migration failed:', err);
  80. // Show error notification
  81. Alert.error(TAPi18n.__('migration-failed') + ': ' + (err.message || err.reason));
  82. } else {
  83. console.log('Migration completed:', result);
  84. // Show success notification
  85. Alert.success(TAPi18n.__('migration-successful'));
  86. // Reload migration statuses
  87. Meteor.setTimeout(() => {
  88. this.loadMigrationStatuses();
  89. }, 1000);
  90. }
  91. });
  92. }
  93. },
  94. events() {
  95. return [
  96. {
  97. 'click .js-run-migration[data-migration="comprehensive"]': Popup.afterConfirm('runComprehensiveMigration', function() {
  98. const component = BlazeComponent.getComponentForElement(this);
  99. if (component) {
  100. component.runMigration('comprehensive');
  101. }
  102. }),
  103. 'click .js-run-migration[data-migration="fixMissingLists"]': Popup.afterConfirm('runFixMissingListsMigration', function() {
  104. const component = BlazeComponent.getComponentForElement(this);
  105. if (component) {
  106. component.runMigration('fixMissingLists');
  107. }
  108. }),
  109. 'click .js-run-migration[data-migration="fixAvatarUrls"]': Popup.afterConfirm('runFixAvatarUrlsMigration', function() {
  110. const component = BlazeComponent.getComponentForElement(this);
  111. if (component) {
  112. component.runMigration('fixAvatarUrls');
  113. }
  114. }),
  115. 'click .js-run-migration[data-migration="fixAllFileUrls"]': Popup.afterConfirm('runFixAllFileUrlsMigration', function() {
  116. const component = BlazeComponent.getComponentForElement(this);
  117. if (component) {
  118. component.runMigration('fixAllFileUrls');
  119. }
  120. }),
  121. },
  122. ];
  123. },
  124. }).register('migrationsSidebar');