Choose an Elementor event template during or after migration
All checks were successful
WordPress release / release (push) Successful in 7s
All checks were successful
WordPress release / release (push) Successful in 7s
This commit is contained in:
@@ -317,7 +317,13 @@
|
||||
padding: clamp(30px, 5vw, 60px);
|
||||
background: radial-gradient(ellipse at 15% 100%, #323b80, transparent 75%);
|
||||
}
|
||||
.be-single-layout .be-event-title { color: #fff; font-size: clamp(2.2rem, 5vw, 4.05rem); line-height: 1.02; text-wrap: pretty; }
|
||||
.be-single-layout .be-event-title {
|
||||
color: #fff;
|
||||
font: 700 clamp(2.2rem, 5vw, 4.05rem)/1.06 Inter, system-ui, sans-serif;
|
||||
letter-spacing: -.045em;
|
||||
overflow-wrap: anywhere;
|
||||
text-wrap: pretty;
|
||||
}
|
||||
.be-single-layout .be-single-date { color: #dce4ff; font-size: clamp(.92rem, 1.7vw, 1.06rem); line-height: 1.5; }
|
||||
.be-single-layout .be-layout-title .be-status { margin: 0; border-radius: 999px; padding: .3em .8em; background: #dedfff; color: #272d65; }
|
||||
.be-single-layout .be-layout-photo.e-con { position: relative; min-height: clamp(265px, 33vw, 390px); padding: 0; }
|
||||
|
||||
@@ -5,14 +5,44 @@
|
||||
const endpoint = form.getAttribute('action');
|
||||
|
||||
const {__, sprintf} = wp.i18n;
|
||||
const button = form.querySelector('button[type="submit"]');
|
||||
const buttons = Array.from(form.querySelectorAll('[data-be-operation]'));
|
||||
const template = form.querySelector('[name="template_id"]');
|
||||
const status = form.querySelector('[data-be-migrate-status]');
|
||||
const errors = form.querySelector('[data-be-migrate-errors]');
|
||||
const retryableStatuses = new Set([408, 429, 502, 503, 504]);
|
||||
let copied = 0;
|
||||
const messages = {
|
||||
copy: {
|
||||
count: 'copied',
|
||||
starting: __('Copying events…', 'burn-events'),
|
||||
progress: __('Copying events. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
|
||||
finished: __('Migration finished. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
|
||||
paused: __('Migration paused. %1$d copied, %2$d already copied. %3$s', 'burn-events'),
|
||||
},
|
||||
apply: {
|
||||
count: 'applied',
|
||||
starting: __('Applying the template…', 'burn-events'),
|
||||
progress: __('Applying the template. %1$d applied, %2$d already assigned, %3$d need review.', 'burn-events'),
|
||||
finished: __('Template assignment finished. %1$d applied, %2$d already assigned, %3$d need review.', 'burn-events'),
|
||||
paused: __('Template assignment paused. %1$d applied, %2$d already assigned. %3$s', 'burn-events'),
|
||||
},
|
||||
};
|
||||
let operation = '';
|
||||
let templateId = '0';
|
||||
let hasCopies = form.dataset.hasCopies === '1';
|
||||
let processed = 0;
|
||||
let skipped = 0;
|
||||
let after = 0;
|
||||
button.disabled = false;
|
||||
|
||||
function updateControls(busy) {
|
||||
if (template) template.disabled = busy;
|
||||
for (const button of buttons) {
|
||||
const canApply = hasCopies && template && template.value !== '0';
|
||||
button.disabled = busy || (button.value === 'apply' && !canApply);
|
||||
}
|
||||
}
|
||||
|
||||
template?.addEventListener('change', () => updateControls(false));
|
||||
updateControls(false);
|
||||
|
||||
async function requestBatch(body) {
|
||||
for (let attempt = 0; ; attempt++) {
|
||||
@@ -29,16 +59,16 @@
|
||||
if (requestedDelay > 10000) return response;
|
||||
if (requestedDelay > delay) delay = requestedDelay;
|
||||
}
|
||||
status.textContent = __('Waiting to retry the last migration batch…', 'burn-events');
|
||||
status.textContent = __('Waiting to retry the last batch…', 'burn-events');
|
||||
await new Promise(resolve => setTimeout(resolve, delay));
|
||||
}
|
||||
}
|
||||
|
||||
async function readBatch(response) {
|
||||
async function readBatch(response, count) {
|
||||
const result = await response.json().catch(() => null);
|
||||
if (response.ok && result?.success === true) {
|
||||
const batch = result.data;
|
||||
const counts = [batch?.copied, batch?.skipped, batch?.next];
|
||||
const counts = [batch?.[count], batch?.skipped, batch?.next];
|
||||
if (counts.every(value => Number.isSafeInteger(value) && value >= 0)
|
||||
&& (batch.next === 0 || batch.next > after) && Array.isArray(batch.errors)) return batch;
|
||||
}
|
||||
@@ -55,39 +85,41 @@
|
||||
|
||||
form.addEventListener('submit', async event => {
|
||||
event.preventDefault();
|
||||
if (button.disabled) return;
|
||||
button.disabled = true;
|
||||
if (after === 0) {
|
||||
copied = 0;
|
||||
const button = event.submitter ?? buttons.find(control => !control.disabled);
|
||||
if (!button || button.disabled) return;
|
||||
const selectedTemplate = template?.value ?? '0';
|
||||
if (after === 0 || operation !== button.value || templateId !== selectedTemplate) {
|
||||
after = 0;
|
||||
processed = 0;
|
||||
skipped = 0;
|
||||
errors.replaceChildren();
|
||||
}
|
||||
status.textContent = __('Copying events…', 'burn-events');
|
||||
operation = button.value;
|
||||
templateId = selectedTemplate;
|
||||
const labels = messages[operation];
|
||||
const body = new URLSearchParams(new FormData(form));
|
||||
body.set('operation', operation);
|
||||
updateControls(true);
|
||||
status.textContent = labels.starting;
|
||||
try {
|
||||
do {
|
||||
body.set('after', String(after));
|
||||
const batch = await readBatch(await requestBatch(body));
|
||||
copied += batch.copied;
|
||||
const batch = await readBatch(await requestBatch(body), labels.count);
|
||||
processed += batch[labels.count];
|
||||
skipped += batch.skipped;
|
||||
if (operation === 'copy' && (processed || skipped)) hasCopies = true;
|
||||
for (const error of batch.errors) {
|
||||
const item = document.createElement('li');
|
||||
item.textContent = error;
|
||||
errors.append(item);
|
||||
}
|
||||
after = batch.next;
|
||||
status.textContent = sprintf(
|
||||
after ? __('Copying events. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events')
|
||||
: __('Migration finished. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
|
||||
copied, skipped, errors.childElementCount
|
||||
);
|
||||
status.textContent = sprintf(after ? labels.progress : labels.finished, processed, skipped, errors.childElementCount);
|
||||
} while (after);
|
||||
} catch (error) {
|
||||
status.textContent = sprintf(
|
||||
__('Migration paused. %1$d copied, %2$d already copied. %3$s', 'burn-events'), copied, skipped, error.message
|
||||
);
|
||||
status.textContent = sprintf(labels.paused, processed, skipped, error.message);
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
updateControls(false);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user