Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added datetime meta to old events. #7

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gatherpress-alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Powering Communities with WordPress.
* Author: The GatherPress Community
* Author URI: https://gatherpress.org/
* Version: 0.30.0
* Version: 0.31.0-alpha
* Requires PHP: 7.4
* Text Domain: gatherpress-alpha
* License: GPLv2 or later (license.txt)
Expand Down
54 changes: 54 additions & 0 deletions includes/classes/class-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

use GatherPress\Core\Event;
use GatherPress\Core\Rsvp;
use GatherPress\Core\Rsvp_Query;
use GatherPress\Core\Traits\Singleton;
use GatherPress\Core\Settings;
use GatherPress\Core\Utility;
use GatherPress_Alpha\Commands\Cli;
use WP_CLI;
use WP_Query;

/**
* Class Setup.
Expand Down Expand Up @@ -155,12 +157,14 @@ public function fix(): void {

$this->fix__0_29_0();
$this->fix__0_30_0();
$this->fix__0_31_0();

restore_current_blog();
}
} elseif ( $is_cli || current_user_can( 'manage_options' ) ) {
$this->fix__0_29_0();
$this->fix__0_30_0();
$this->fix__0_31_0();
} else {
wp_die( __( 'You do not have permission to perform this action.', 'gatherpress-alpha' ) );
}
Expand Down Expand Up @@ -418,4 +422,54 @@ private function fix__0_30_0(): void {

$wpdb->query( $sql );
}

/**
* Fixes specific data issues that changed in 0.30.0 of the plugin.
*
* @return void
*/
private function fix__0_31_0(): void {
// Add datetime meta and resave.
$batch_size = 100;
$paged = 1;

do {
$args = array(
'post_type' => 'gatherpress_event',
'posts_per_page' => $batch_size,
'paged' => $paged,
'fields' => 'ids',
);
$query = new WP_Query( $args );

if ( ! $query->have_posts() ) {
break;
}

foreach ( $query->posts as $post_id ) {
if ( get_post_meta( $post_id, 'gatherpress_datetime', true ) ) {
continue;
}

$event = new Event( $post_id );
$data = $event->get_datetime();
$meta = json_encode (
array(
'dateTimeStart' => $data['datetime_start'],
'dateTimeEnd' => $data['datetime_end'],
'timezone' => $data['timezone'],

)
);

update_post_meta( $post_id, 'gatherpress_datetime', $meta );

$event->save_datetimes( $data );
}

wp_reset_postdata();

$paged++;
} while ( $query->have_posts() );
}
}