Skip to content

Commit

Permalink
Identify old sites/pages by 10 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosSynetos committed Sep 21, 2023
1 parent c11b619 commit dac76a8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions includes/class-wc-calypso-bridge-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function woocommerce_create_pages_callback() {
$this->write_to_log( $operation, 'INITIALIZED' );

// Set the operation as completed if the store is active for more than 10 minutes.
if ( WCAdminHelper::is_wc_admin_active_for( 10 * MINUTE_IN_SECONDS ) ) {
if ( WCAdminHelper::is_wc_admin_active_for( 5 * MINUTE_IN_SECONDS ) ) {
update_option( $this->option_prefix . $operation, 'completed', 'no' );
$this->write_to_log( $operation, 'completed (10 minutes)' );

Expand Down Expand Up @@ -286,7 +286,7 @@ public function woocommerce_create_pages_callback() {
foreach ( $woocommerce_pages as $key => $page_slug ) {
$slugs = array( $page_slug, $page_slug . '-2' );
foreach ( $slugs as $slug ) {
$this->delete_page_by_slug( $slug, $operation );
$this->maybe_delete_page_by_slug( $slug, $operation );
}
}

Expand Down Expand Up @@ -321,7 +321,7 @@ public function woocommerce_create_pages_callback() {
foreach ( $headstart_slugs as $page_slug ) {
$slugs = array( $page_slug, $page_slug . '-2' );
foreach ( $slugs as $slug ) {
$this->delete_page_by_slug( $slug, $operation );
$this->maybe_delete_page_by_slug( $slug, $operation );
}
}

Expand Down Expand Up @@ -688,16 +688,17 @@ private function write_to_log( $operation, $message ) {
}

/**
* Delete page by slug
*
* @param string $slug Slug.
* @param string $operation Operation.
* Maybe delete page by slug.
* If the page is older than 10 minutes, it will be ignored.
*
* @since x.x.x
*
* @param string $operation Operation.
*
* @param string $slug Slug.
* @return void
*/
private function delete_page_by_slug( $slug, $operation ) {
private function maybe_delete_page_by_slug( $slug, $operation ) {

$page = get_page_by_path( $slug, ARRAY_A );

Expand All @@ -712,7 +713,7 @@ private function delete_page_by_slug( $slug, $operation ) {
$diff_ts = $current_time_gmt_ts - $page_gmt_ts;

if ( $diff_ts > 10 * MINUTE_IN_SECONDS ) {
$this->write_to_log( $operation, 'ignored page deletion (too old) ' . $slug . ' diff: ' . $diff_ts );
$this->write_to_log( $operation, 'ignored page deletion ' . $slug . ' diff: ' . $diff_ts / 60 . ' minutes (older than 10 minutes) ' );

return;
}
Expand Down

0 comments on commit dac76a8

Please sign in to comment.