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

Listing status migration #1606

Merged
merged 64 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
4987a33
updated composer lock
obiPlabon Jul 27, 2022
6f4f103
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 1, 2022
77b8884
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 2, 2022
4f0d495
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 2, 2022
d020772
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 2, 2022
8fcd90b
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 3, 2022
86ba70a
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 8, 2022
d6e792c
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 18, 2022
4c2bb68
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 22, 2022
040527b
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 24, 2022
884ec5c
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 28, 2022
0364bef
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 30, 2022
9d271ca
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Sep 1, 2022
7b3e07b
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Sep 4, 2022
13b3545
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Oct 9, 2022
04648c1
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Nov 20, 2022
1483140
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Feb 8, 2023
9aef859
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Feb 19, 2023
40969d3
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Feb 22, 2023
5fcca17
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Feb 26, 2023
8d3ada0
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Mar 1, 2023
aad382d
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Mar 23, 2023
ab01506
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Mar 31, 2023
88112ca
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Apr 4, 2023
960ed08
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Apr 11, 2023
1af49d1
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Apr 12, 2023
19cefc5
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Apr 13, 2023
2c5b296
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon May 25, 2023
b90d3fe
Added listing status post meta to post status migration
obiPlabon May 29, 2023
7d90efe
Added expired post status
obiPlabon May 29, 2023
0fdf7eb
updated listing status related code
obiPlabon May 29, 2023
97bf15e
Updated expired status author listings query
obiPlabon May 29, 2023
a4280f7
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Jun 7, 2023
261bfb3
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Jun 15, 2023
5751877
Updated listing status meta to post status column
obiPlabon Jun 26, 2023
0f5ec3d
Migrated renewal post status from meta to post_status column
obiPlabon Jun 26, 2023
a6b1009
Updated status related cron functions
obiPlabon Jun 26, 2023
d14358c
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Jun 26, 2023
b65187f
Added renewal migration
obiPlabon Jun 27, 2023
0724b94
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Jul 27, 2023
0951cf7
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Jul 27, 2023
78389ed
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 2, 2023
49e1956
Fixed merge conflict
obiPlabon Aug 2, 2023
87ef739
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 6, 2023
e9fd9fb
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 6, 2023
b284029
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 20, 2023
ad0c37d
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Aug 24, 2023
4098ca6
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Sep 11, 2023
ef54569
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Sep 20, 2023
810f3f0
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Sep 25, 2023
725c4c0
Merge branch 'alpha' of github.com:sovware/directorist into alpha
obiPlabon Sep 26, 2023
fdc8bcc
Resolved conflict
obiPlabon Sep 26, 2023
e1a0f75
Updated migration function version
obiPlabon Sep 26, 2023
dc59a10
Merge branch 'alpha' into listing-status-migration
vairafiq Dec 14, 2023
4541ec4
Resolved conflict
obiPlabon Apr 4, 2024
4b63ef6
Updated migration function version
obiPlabon Apr 4, 2024
3561cb5
Resolved conflict
obiPlabon Apr 4, 2024
2ff2b25
Resolved conflict
obiPlabon Apr 4, 2024
8a14190
Merge conflict resolved with alpha
obiPlabon May 8, 2024
822e4e2
Cleanup never expire meta migration todo
obiPlabon May 8, 2024
77f3f2e
Refactored renewal listings
obiPlabon May 8, 2024
92e6717
Updated and fixed listing status incompatibility issues
obiPlabon May 10, 2024
3d3ed2d
Fixed backward compatibility with _listing_status CRUD operation
obiPlabon May 12, 2024
aa26262
Fixed meta get issue
obiPlabon May 12, 2024
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
9 changes: 6 additions & 3 deletions includes/classes/class-add-listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,10 @@ private function renew_listing( $listing_id ) {

$directory_type = get_post_meta( $listing_id, '_directory_type', true );
// Update the post_meta into the database
$old_status = get_post_meta( $listing_id, '_listing_status', true );
if ( 'expired' == $old_status ) {
// TODO: Status has been migrated, remove related code.
// $old_status = get_post_meta( $listing_id, '_listing_status', true );
$old_status = get_post_status( $listing_id );
if ( 'expired' === $old_status ) {
$expiry_date = calc_listing_expiry_date();
} else {
$old_expiry_date = get_post_meta( $listing_id, '_expiry_date', true );
Expand All @@ -968,7 +970,8 @@ private function renew_listing( $listing_id ) {

// update related post meta_data
update_post_meta( $listing_id, '_expiry_date', $expiry_date );
update_post_meta( $listing_id, '_listing_status', 'post_status' );
// TODO: Status has been migrated, remove related code.
// update_post_meta( $listing_id, '_listing_status', 'post_status' );

$exp_days = get_term_meta( $directory_type, 'default_expiration', true );
if ( $exp_days <= 0 ) {
Expand Down
209 changes: 133 additions & 76 deletions includes/classes/class-cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,10 @@ private function featured_listing_followup() {
$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
'post_status' => 'public',
'post_status' => 'publish',
'cache_results' => false,
'nopaging' => true,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_listing_status',
'value' => 'post_status',
),
array(
'key' => '_featured',
'value' => 1,
Expand Down Expand Up @@ -136,7 +133,7 @@ private function get_order_by_listing( $listing_id ) {
$args = array(
'post_type' => ATBDP_ORDER_POST_TYPE,
'posts_per_page' => 1,
'post_status' => 'public',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
Expand Down Expand Up @@ -176,12 +173,10 @@ private function update_renewal_status() {
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
'post_status' => 'publish',
'cache_results' => false,
'nopaging' => true,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_listing_status',
'value' => 'post_status',
),
array(
'key' => '_expiry_date',
'value' => $renew_email_threshold_date,
Expand All @@ -207,9 +202,19 @@ private function update_renewal_status() {
$listings = new WP_Query( $args ); // get all the post that has post_status only and update their status and fire an email
if ( $listings->found_posts ) {
foreach ( $listings->posts as $listing ) {
update_post_meta( $listing->ID, '_listing_status', 'renewal' );
// TODO: Status has been migrated, remove related code.
// update_post_meta( $listing->ID, '_listing_status', 'renewal' );
$renewal_listing_id = wp_update_post( array(
'ID' => $listing->ID,
'post_status' => 'renewal',
) );

if ( is_wp_error( $renewal_listing_id ) ) {
continue;
}

// hook for dev.
do_action( 'atbdp_status_updated_to_renewal', $listing->ID );
do_action( 'atbdp_status_updated_to_renewal', $renewal_listing_id );
}
}
}
Expand All @@ -234,6 +239,8 @@ private function update_expired_status() {
$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
'cache_results' => false,
'nopaging' => true,
'post_status' => 'publish', // get expired post with published status
'meta_query' => array(
'relation' => 'AND',
Expand Down Expand Up @@ -262,29 +269,34 @@ private function update_expired_status() {
if ( $listings->found_posts ) {
foreach ( $listings->posts as $listing ) {
// prepare the post meta data
$metas = array(
'_listing_status' => 'expired',
$meta_input = array(
// TODO: Status has been migrated, remove related code.
// '_listing_status' => 'expired',
'_featured' => 0,
'_renewal_reminder_sent' => 0,
);

// delete expired listings?
if ( $del_exp_l ) {
// if deletion threshold is set then add deletion date
if ( $delete_threshold > 0 ) {
$metas['_deletion_date'] = date( 'Y-m-d H:i:s', strtotime( '+' . $delete_threshold . ' days' ) );
$meta_input['_deletion_date'] = date( 'Y-m-d H:i:s', strtotime( '+' . $delete_threshold . ' days' ) );
} else {
$metas['_deletion_date'] = date( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
$meta_input['_deletion_date'] = date( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
}
}
wp_update_post(
array(
'ID' => $listing->ID,
'post_status' => 'private', // update the status to private so that we do not run this func a second time
'meta_input' => $metas, // insert all meta data once to reduce update meta query
)
);
// Hook for developers
do_action( 'atbdp_listing_expired', $listing->ID );

$expired_listing_id = wp_update_post( array(
'ID' => $listing->ID,
'post_status' => 'expired',
'meta_input' => $meta_input,
) );

if ( is_wp_error( $expired_listing_id ) ) {
continue;
}

do_action( 'atbdp_listing_expired', $expired_listing_id );
}
}
}
Expand All @@ -296,50 +308,89 @@ private function update_expired_status() {
* @access private
*/
private function update_expired_listing_status() {
// Define the query
$args = array(
// TODO: Status has been migrated, remove related code.
// // Define the query
// $args = array(
// 'post_type' => ATBDP_POST_TYPE,
// 'posts_per_page' => -1,
// 'post_status' => 'publish', // get expired post with published status
// );
// $meta = array();
// $meta['renewed_by_admin'] = array(
// 'relation' => 'OR',
// array(
// 'key' => '_expiry_date',
// 'value' => current_time( 'mysql' ),
// 'compare' => '>', // eg. expire date 6 <= current date 7 will return the post
// 'type' => 'DATETIME',
// ),
// array(
// 'key' => '_never_expire',
// 'value' => 1,
// ),
// );
// $meta['get_expired'] = array(
// 'key' => '_listing_status',
// 'value' => 'expired',
// 'compare' => '=',
// );

// $args['meta_query'] = array_merge( array( 'relation' => 'AND' ), $meta );
// $listings = new WP_Query( $args );
// if ( $listings->found_posts ) {
// foreach ( $listings->posts as $listing ) {
// // prepare the post meta data
// $metas = array(
// '_listing_status' => 'post_status',
// '_renewal_reminder_sent' => 0,
// );
// wp_update_post(
// array(
// 'ID' => $listing->ID,
// 'post_status' => 'publish', // update the status to private so that we do not run this func a second time
// 'meta_input' => $metas, // insert all meta data once to reduce update meta query
// )
// );
// }
// }

$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
'post_status' => 'publish', // get expired post with published status
'post_status' => 'expired',
'cache_results' => false,
'nopaging' => true,
'meta_query' => array(
'relation' => 'AND',
'renewed_by_admin' => array(
'relation' => 'OR',
array(
'key' => '_expiry_date',
'value' => current_time( 'mysql' ),
'compare' => '>', // eg. expire date 6 <= current date 7 will return the post
'type' => 'DATETIME',
),
array(
'key' => '_never_expire',
'value' => 1,
),
)
)
);
$meta = array();
$meta['renewed_by_admin'] = array(
'relation' => 'OR',
array(
'key' => '_expiry_date',
'value' => current_time( 'mysql' ),
'compare' => '>', // eg. expire date 6 <= current date 7 will return the post
'type' => 'DATETIME',
),
array(
'key' => '_never_expire',
'value' => 1,
),
);
$meta['get_expired'] = array(
'key' => '_listing_status',
'value' => 'expired',
'compare' => '=',
);

$args['meta_query'] = array_merge( array( 'relation' => 'AND' ), $meta );
$listings = new WP_Query( $args );
if ( $listings->found_posts ) {
foreach ( $listings->posts as $listing ) {
// prepare the post meta data
$metas = array(
'_listing_status' => 'post_status',
'_renewal_reminder_sent' => 0,
);
wp_update_post(
array(
'ID' => $listing->ID,
'post_status' => 'publish', // update the status to private so that we do not run this func a second time
'meta_input' => $metas, // insert all meta data once to reduce update meta query
)
);
}
}
$listings = new WP_Query( $args );

if ( $listings->found_posts ) {
foreach ( $listings->posts as $listing ) {
wp_update_post( array(
'ID' => $listing->ID,
'post_status' => 'publish',
'meta_input' => array(
'_renewal_reminder_sent' => 0,
),
) );
}
}
}

/**
Expand All @@ -357,13 +408,16 @@ private function send_renewal_reminders() {
$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
'post_status' => 'private',
'cache_results' => false,
'nopaging' => true,
'post_status' => 'expired',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_listing_status',
'value' => 'expired',
),
// TODO: Status has been migrated, remove related code.
// array(
// 'key' => '_listing_status',
// 'value' => 'expired',
// ),
array(
'key' => '_renewal_reminder_sent',
'value' => 0,
Expand Down Expand Up @@ -421,13 +475,16 @@ private function delete_expired_listings() {
$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
'post_status' => 'private',
'cache_results' => false,
'nopaging' => true,
'post_status' => 'expired',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_listing_status',
'value' => 'expired',
),
// TODO: Status has been migrated, remove related code.
// array(
// 'key' => '_listing_status',
// 'value' => 'expired',
// ),
array(
'key' => '_deletion_date',
'value' => current_time( 'mysql' ),
Expand Down
38 changes: 36 additions & 2 deletions includes/classes/class-custom-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,38 @@ public function __construct() {
}

add_action( 'admin_footer', array( $this, 'quick_edit_scripts' ) );

add_action( 'init', array( $this, 'register_post_status' ) );
}

public function register_post_status() {
register_post_status(
'expired',
array(
'label' => _x( 'Expired', 'post status', 'directorist' ),
'protected' => true,
/* translators: %s: Number of expired listings. */
'label_count' => _n_noop(
'Expired <span class="count">(%s)</span>',
'Expired <span class="count">(%s)</span>',
'directorist'
),
)
);

register_post_status(
'renewal',
array(
'label' => _x( 'Renewal', 'post status', 'directorist' ),
'protected' => true,
/* translators: %s: Number of renewal listings. */
'label_count' => _n_noop(
'Renewal <span class="count">(%s)</span>',
'Renewal <span class="count">(%s)</span>',
'directorist'
),
)
);
}

public function quick_edit_scripts() {
Expand Down Expand Up @@ -377,8 +409,10 @@ public function manage_listing_columns( $column_name, $post_id ) {
break;

case 'atbdp_status':
$status = get_post_meta( $post_id, '_listing_status', true );
$status = ( $status !== 'post_status' ? $status : get_post_status( $post_id ) );
// TODO: Status has been migrated, remove related code.
// $status = get_post_meta( $post_id, '_listing_status', true );
// $status = ( $status !== 'post_status' ? $status : get_post_status( $post_id ) );
$status = get_post_status( $post_id );
echo esc_html( ucfirst( $status ) );
break;

Expand Down
7 changes: 7 additions & 0 deletions includes/classes/class-installation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class ATBDP_Installation {
* @var array
*/
private static $db_updates = array(
'7.10.0' => [
'directorist_7100_migrate_expired_meta_to_expired_status',
'directorist_7100_migrate_renewal_meta_to_renewal_status',
// 'directorist_7100_clean_listing_status_expired_meta',
// 'directorist_7100_clean_listing_status_renewal_meta',
'directorist_7100_update_db_version',
],
'7.1.0' => [
'directorist_710_migrate_reviews_table_to_comments_table',
'directorist_710_migrate_posts_table_to_comments_table',
Expand Down
Loading