Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b5c8a1ff5 | ||
|
|
2ace78b669 | ||
|
|
c3db26ecf9 |
@@ -43,3 +43,5 @@ Use `GET /events` to list records, `POST /events` to create one, and `PATCH /eve
|
|||||||
Sync a named club or sub-club with `PUT /burnworks/workspaces/{workspace_id}/clubs/{club_id}`. Send events to `PUT /burnworks/workspaces/{workspace_id}/events/{event_id}` with the burnWorks `club_id`. An event stores its workspace and club identity in a hidden field. In Elementor, use **Club or sub-club** on **Event Calendar** and **Event List** to show a whole workspace or one club.
|
Sync a named club or sub-club with `PUT /burnworks/workspaces/{workspace_id}/clubs/{club_id}`. Send events to `PUT /burnworks/workspaces/{workspace_id}/events/{event_id}` with the burnWorks `club_id`. An event stores its workspace and club identity in a hidden field. In Elementor, use **Club or sub-club** on **Event Calendar** and **Event List** to show a whole workspace or one club.
|
||||||
|
|
||||||
See the [API reference](docs/API.md) for routes, payloads, and errors, and the [burnWorks handoff](docs/BURNWORKS-INTEGRATION.md) for field mapping and publishing rules. The [feature and settings audit](docs/PARITY-AUDIT.md) records the current coverage against the reference packages.
|
See the [API reference](docs/API.md) for routes, payloads, and errors, and the [burnWorks handoff](docs/BURNWORKS-INTEGRATION.md) for field mapping and publishing rules. The [feature and settings audit](docs/PARITY-AUDIT.md) records the current coverage against the reference packages.
|
||||||
|
|
||||||
|
For events created in WordPress, use **Event Details → Sub-club** to select a club from the synced burnWorks directory. Events created in burnWorks keep their assignment from that system.
|
||||||
|
|||||||
@@ -1,38 +1,81 @@
|
|||||||
(() => {
|
(() => {
|
||||||
const form = document.querySelector('[data-be-migrate]');
|
const form = document.querySelector('[data-be-migrate]');
|
||||||
if (!form) return;
|
if (!form) return;
|
||||||
|
// The hidden WordPress action input shadows the form.action property.
|
||||||
|
const endpoint = form.getAttribute('action');
|
||||||
|
|
||||||
const {__, sprintf} = wp.i18n;
|
const {__, sprintf} = wp.i18n;
|
||||||
const button = form.querySelector('button[type="submit"]');
|
const button = form.querySelector('button[type="submit"]');
|
||||||
const status = form.querySelector('[data-be-migrate-status]');
|
const status = form.querySelector('[data-be-migrate-status]');
|
||||||
const errors = form.querySelector('[data-be-migrate-errors]');
|
const errors = form.querySelector('[data-be-migrate-errors]');
|
||||||
button.disabled = false;
|
const retryableStatuses = new Set([408, 429, 502, 503, 504]);
|
||||||
|
|
||||||
form.addEventListener('submit', async event => {
|
|
||||||
event.preventDefault();
|
|
||||||
button.disabled = true;
|
|
||||||
errors.replaceChildren();
|
|
||||||
status.textContent = __('Copying events…', 'burn-events');
|
|
||||||
const body = new FormData(form);
|
|
||||||
let copied = 0;
|
let copied = 0;
|
||||||
let skipped = 0;
|
let skipped = 0;
|
||||||
let after = 0;
|
let after = 0;
|
||||||
|
button.disabled = false;
|
||||||
|
|
||||||
|
async function requestBatch(body) {
|
||||||
|
for (let attempt = 0; ; attempt++) {
|
||||||
|
const response = await fetch(endpoint, {
|
||||||
|
method: 'POST', body, credentials: 'same-origin', headers: {Accept: 'application/json'},
|
||||||
|
}).catch(() => null);
|
||||||
|
if (response && (attempt === 2 || !retryableStatuses.has(response.status))) return response;
|
||||||
|
if (attempt === 2) throw new Error(__('Could not reach WordPress. Try the migration again when the connection is available.', 'burn-events'));
|
||||||
|
|
||||||
|
const retryAfter = response?.headers.get('Retry-After');
|
||||||
|
let delay = (attempt + 1) * 1500;
|
||||||
|
if (retryAfter) {
|
||||||
|
const requestedDelay = /^\d+$/.test(retryAfter) ? Number(retryAfter) * 1000 : Date.parse(retryAfter) - Date.now();
|
||||||
|
if (requestedDelay > 10000) return response;
|
||||||
|
if (requestedDelay > delay) delay = requestedDelay;
|
||||||
|
}
|
||||||
|
status.textContent = __('Waiting to retry the last migration batch…', 'burn-events');
|
||||||
|
await new Promise(resolve => setTimeout(resolve, delay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readBatch(response) {
|
||||||
|
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];
|
||||||
|
if (counts.every(value => Number.isSafeInteger(value) && value >= 0)
|
||||||
|
&& (batch.next === 0 || batch.next > after) && Array.isArray(batch.errors)) return batch;
|
||||||
|
}
|
||||||
|
if (result?.success === false && typeof result.data === 'string' && result.data) throw new Error(result.data);
|
||||||
|
if (response.status === 401 || (response.redirected && new URL(response.url).pathname.endsWith('/wp-login.php'))) {
|
||||||
|
throw new Error(__('Your WordPress session has ended. Sign in again and reopen the migration page.', 'burn-events'));
|
||||||
|
}
|
||||||
|
throw new Error(sprintf(
|
||||||
|
response.ok ? __('WordPress returned an unexpected response (HTTP %d). Try the migration again.', 'burn-events')
|
||||||
|
: __('The migration request failed (HTTP %d). Try the migration again or check the host’s request log for this status.', 'burn-events'),
|
||||||
|
response.status
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
form.addEventListener('submit', async event => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (button.disabled) return;
|
||||||
|
button.disabled = true;
|
||||||
|
if (after === 0) {
|
||||||
|
copied = 0;
|
||||||
|
skipped = 0;
|
||||||
|
errors.replaceChildren();
|
||||||
|
}
|
||||||
|
status.textContent = __('Copying events…', 'burn-events');
|
||||||
|
const body = new URLSearchParams(new FormData(form));
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
body.set('after', String(after));
|
body.set('after', String(after));
|
||||||
const response = await fetch(form.action, {method: 'POST', body, credentials: 'same-origin'});
|
const batch = await readBatch(await requestBatch(body));
|
||||||
const result = await response.json();
|
copied += batch.copied;
|
||||||
if (!response.ok || !result.success) {
|
skipped += batch.skipped;
|
||||||
throw new Error(typeof result.data === 'string' ? result.data : '');
|
for (const error of batch.errors) {
|
||||||
}
|
|
||||||
copied += result.data.copied;
|
|
||||||
skipped += result.data.skipped;
|
|
||||||
for (const error of result.data.errors) {
|
|
||||||
const item = document.createElement('li');
|
const item = document.createElement('li');
|
||||||
item.textContent = error;
|
item.textContent = error;
|
||||||
errors.append(item);
|
errors.append(item);
|
||||||
}
|
}
|
||||||
after = result.data.next;
|
after = batch.next;
|
||||||
status.textContent = sprintf(
|
status.textContent = sprintf(
|
||||||
after ? __('Copying events. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events')
|
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'),
|
: __('Migration finished. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
|
||||||
@@ -40,7 +83,9 @@
|
|||||||
);
|
);
|
||||||
} while (after);
|
} while (after);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
status.textContent = error.message || __('Migration stopped. Run it again to continue with events that still need copying.', 'burn-events');
|
status.textContent = sprintf(
|
||||||
|
__('Migration paused. %1$d copied, %2$d already copied. %3$s', 'burn-events'), copied, skipped, error.message
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Plugin Name: eventLabs
|
* Plugin Name: eventLabs
|
||||||
* Plugin URI: https://git.labs.casa/josh/eventLabs
|
* Plugin URI: https://git.labs.casa/josh/eventLabs
|
||||||
* Description: Calendars, recurring events, community submissions, and a Single Event template builder for Elementor.
|
* Description: Calendars, recurring events, community submissions, and a Single Event template builder for Elementor.
|
||||||
* Version: 0.5.2
|
* Version: 0.5.5
|
||||||
* Requires at least: 6.9
|
* Requires at least: 6.9
|
||||||
* Requires PHP: 8.1
|
* Requires PHP: 8.1
|
||||||
* Author: hostLabs
|
* Author: hostLabs
|
||||||
@@ -16,7 +16,7 @@ declare(strict_types=1);
|
|||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
define( 'BURN_EVENTS_FILE', __FILE__ );
|
define( 'BURN_EVENTS_FILE', __FILE__ );
|
||||||
define( 'BURN_EVENTS_VERSION', '0.5.2' );
|
define( 'BURN_EVENTS_VERSION', '0.5.5' );
|
||||||
|
|
||||||
foreach ( [ 'schedule', 'maps', 'events', 'admin', 'map-view', 'calendar-grid', 'calendar', 'community', 'transfer', 'single-event-templates', 'api', 'burnworks', 'clubs', 'legacy-migration', 'updates', 'platform' ] as $module ) {
|
foreach ( [ 'schedule', 'maps', 'events', 'admin', 'map-view', 'calendar-grid', 'calendar', 'community', 'transfer', 'single-event-templates', 'api', 'burnworks', 'clubs', 'legacy-migration', 'updates', 'platform' ] as $module ) {
|
||||||
require_once __DIR__ . '/includes/class-' . $module . '.php';
|
require_once __DIR__ . '/includes/class-' . $module . '.php';
|
||||||
|
|||||||
@@ -177,6 +177,30 @@ final class Admin {
|
|||||||
$data['organizer'] = array_filter( [ $options['organizer'] ] );
|
$data['organizer'] = array_filter( [ $options['organizer'] ] );
|
||||||
}
|
}
|
||||||
self::event_fields( $data );
|
self::event_fields( $data );
|
||||||
|
$scope = (string) get_post_meta( $post->ID, Clubs::EVENT_META, true );
|
||||||
|
$options = Clubs::editor_options();
|
||||||
|
?>
|
||||||
|
<p><label for="burn-event-sub-club"><strong><?php esc_html_e( 'Sub-club', 'burn-events' ); ?></strong></label><br>
|
||||||
|
<select id="burn-event-sub-club" name="be_sub_club" aria-describedby="burn-event-sub-club-help" <?php disabled( (bool) BurnWorks::snapshot( $post->ID ) ); ?>>
|
||||||
|
<option value=""><?php esc_html_e( 'No sub-club (organization calendar)', 'burn-events' ); ?></option>
|
||||||
|
<?php if ( $scope && ! isset( $options[ $scope ] ) ) : ?>
|
||||||
|
<option value="<?php echo esc_attr( $scope ); ?>" selected><?php esc_html_e( 'Current assignment (unavailable)', 'burn-events' ); ?></option>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php foreach ( $options as $value => $label ) : ?>
|
||||||
|
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $scope, $value ); ?>><?php echo esc_html( $label ); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select></p>
|
||||||
|
<p class="description" id="burn-event-sub-club-help"><?php
|
||||||
|
if ( BurnWorks::snapshot( $post->ID ) ) {
|
||||||
|
esc_html_e( 'This assignment is managed in burnWorks.', 'burn-events' );
|
||||||
|
} elseif ( ! $options ) {
|
||||||
|
esc_html_e( 'Connect burnWorks and sync its club directory to populate this list.', 'burn-events' );
|
||||||
|
} else {
|
||||||
|
esc_html_e( 'This determines which CRM sub-club receives the event.', 'burn-events' );
|
||||||
|
}
|
||||||
|
?></p>
|
||||||
|
<?php
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function event_fields( array $data, bool $public = false ): void {
|
public static function event_fields( array $data, bool $public = false ): void {
|
||||||
@@ -424,7 +448,15 @@ final class Admin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
$current = (string) get_post_meta( $id, Clubs::EVENT_META, true );
|
||||||
|
$scope = ! BurnWorks::snapshot( $id ) && is_string( $_POST['be_sub_club'] ?? null ) ? wp_unslash( $_POST['be_sub_club'] ) : $current;
|
||||||
|
if ( $scope !== $current && '' !== $scope && ! isset( Clubs::editor_options()[ $scope ] ) ) {
|
||||||
|
throw new \InvalidArgumentException( __( 'Select an available sub-club.', 'burn-events' ) );
|
||||||
|
}
|
||||||
Events::save( $id, Events::validate_event( wp_unslash( $_POST['be'] ) ) );
|
Events::save( $id, Events::validate_event( wp_unslash( $_POST['be'] ) ) );
|
||||||
|
if ( $scope !== $current ) {
|
||||||
|
Clubs::assign( $id, $scope );
|
||||||
|
}
|
||||||
} catch ( \Throwable $error ) {
|
} catch ( \Throwable $error ) {
|
||||||
set_transient( 'burn_events_error_' . get_current_user_id(), $error->getMessage(), MINUTE_IN_SECONDS );
|
set_transient( 'burn_events_error_' . get_current_user_id(), $error->getMessage(), MINUTE_IN_SECONDS );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,6 +151,18 @@ final class Clubs {
|
|||||||
return [ '' => __( 'All events', 'burn-events' ) ] + $workspaces + $clubs;
|
return [ '' => __( 'All events', 'burn-events' ) ] + $workspaces + $clubs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function editor_options(): array {
|
||||||
|
$options = [];
|
||||||
|
foreach ( self::directory() as $club ) {
|
||||||
|
if ( 'archived' !== $club['status'] ) {
|
||||||
|
$prefix = $club['workspace_name'] ?: sprintf( __( 'Workspace %s', 'burn-events' ), substr( $club['workspace_id'], 0, 8 ) );
|
||||||
|
$options[ $club['scope'] ] = $prefix . ' / ' . $club['name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
natcasesort( $options );
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
public static function condition( string $scope ): string {
|
public static function condition( string $scope ): string {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$scope = strtolower( $scope );
|
$scope = strtolower( $scope );
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ final class Legacy_Migration {
|
|||||||
public static function register(): void {
|
public static function register(): void {
|
||||||
add_action( 'admin_notices', [ self::class, 'notice' ] );
|
add_action( 'admin_notices', [ self::class, 'notice' ] );
|
||||||
add_action( 'wp_ajax_' . self::ACTION, [ self::class, 'ajax' ] );
|
add_action( 'wp_ajax_' . self::ACTION, [ self::class, 'ajax' ] );
|
||||||
|
add_action( 'wp_ajax_nopriv_' . self::ACTION, [ self::class, 'ajax' ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function notice(): void {
|
public static function notice(): void {
|
||||||
@@ -63,7 +64,7 @@ final class Legacy_Migration {
|
|||||||
<p><?php printf( esc_html( _n( '%s source event found.', '%s source events found.', $count, 'burn-events' ) ), esc_html( number_format_i18n( $count ) ) ); ?></p>
|
<p><?php printf( esc_html( _n( '%s source event found.', '%s source events found.', $count, 'burn-events' ) ), esc_html( number_format_i18n( $count ) ) ); ?></p>
|
||||||
<p><?php esc_html_e( 'Copy events as drafts with their saved dates, linked venues, organizers and series, categories, tags, and featured images. The source events stay available for review.', 'burn-events' ); ?></p>
|
<p><?php esc_html_e( 'Copy events as drafts with their saved dates, linked venues, organizers and series, categories, tags, and featured images. The source events stay available for review.', 'burn-events' ); ?></p>
|
||||||
<p><?php esc_html_e( 'Imported recurring events use the dates already saved in the source calendar. Set a new repeat rule to generate new dates.', 'burn-events' ); ?></p>
|
<p><?php esc_html_e( 'Imported recurring events use the dates already saved in the source calendar. Set a new repeat rule to generate new dates.', 'burn-events' ); ?></p>
|
||||||
<form data-be-migrate action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
|
<form data-be-migrate action="<?php echo esc_url( admin_url( 'admin-ajax.php', 'relative' ) ); ?>" method="post">
|
||||||
<input type="hidden" name="action" value="<?php echo esc_attr( self::ACTION ); ?>">
|
<input type="hidden" name="action" value="<?php echo esc_attr( self::ACTION ); ?>">
|
||||||
<?php wp_nonce_field( self::ACTION ); ?>
|
<?php wp_nonce_field( self::ACTION ); ?>
|
||||||
<button type="submit" class="button button-primary" disabled><?php esc_html_e( 'Copy events as drafts', 'burn-events' ); ?></button>
|
<button type="submit" class="button button-primary" disabled><?php esc_html_e( 'Copy events as drafts', 'burn-events' ); ?></button>
|
||||||
@@ -77,15 +78,27 @@ final class Legacy_Migration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function ajax(): void {
|
public static function ajax(): void {
|
||||||
if ( ! current_user_can( 'manage_options' ) || ! check_ajax_referer( self::ACTION, '_wpnonce', false ) ) {
|
$signed_in = is_user_logged_in();
|
||||||
wp_send_json_error( __( 'Refresh the migration page and sign in as an administrator.', 'burn-events' ), 403 );
|
if ( ! $signed_in || ! current_user_can( 'manage_options' ) || ! check_ajax_referer( self::ACTION, '_wpnonce', false ) ) {
|
||||||
|
wp_send_json_error( __( 'Refresh the migration page and sign in as an administrator.', 'burn-events' ), $signed_in ? 403 : 401 );
|
||||||
}
|
}
|
||||||
$after = is_scalar( $_POST['after'] ?? null ) ? absint( $_POST['after'] ) : 0;
|
$after = is_scalar( $_POST['after'] ?? null ) ? absint( $_POST['after'] ) : 0;
|
||||||
|
// Other plugins may print during post creation. Keep that output out of the JSON response.
|
||||||
|
$buffer_level = ob_get_level();
|
||||||
|
ob_start();
|
||||||
try {
|
try {
|
||||||
wp_send_json_success( self::batch( $after ) );
|
$result = self::batch( $after );
|
||||||
} catch ( \Throwable $error ) {
|
} catch ( \Throwable ) {
|
||||||
|
$result = null;
|
||||||
|
} finally {
|
||||||
|
while ( ob_get_level() > $buffer_level && ob_end_clean() ) {
|
||||||
|
// Close only buffers opened while copying this batch.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( null === $result ) {
|
||||||
wp_send_json_error( __( 'The source calendar could not be read. You can retry the migration.', 'burn-events' ), 500 );
|
wp_send_json_error( __( 'The source calendar could not be read. You can retry the migration.', 'burn-events' ), 500 );
|
||||||
}
|
}
|
||||||
|
wp_send_json_success( $result );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function batch( int $after ): array {
|
public static function batch( int $after ): array {
|
||||||
|
|||||||
Reference in New Issue
Block a user