Skip to content

Commit

Permalink
Merge pull request #7 from GatherPress/add-datetime-meta
Browse files Browse the repository at this point in the history
Added datetime meta to old events.
  • Loading branch information
mauteri authored Sep 13, 2024
2 parents 0409a94 + 3d4e673 commit ea6fd27
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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() );
}
}

0 comments on commit ea6fd27

Please sign in to comment.