Skip to content

Commit

Permalink
Merge pull request #280 from globeandmail/revert-253-feature/save-sop…
Browse files Browse the repository at this point in the history
…hi-responses-as-meta-fields-sit-2708

Revert "SIT-2708:Update to save the response as a post meta field"
  • Loading branch information
jeffpaul authored May 18, 2022
2 parents ed24874 + f773cee commit 543df44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 61 deletions.
33 changes: 5 additions & 28 deletions includes/classes/SiteAutomation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ class Request {
*/
private $status;

/**
* Post ID for Site Automation request.
*
* @var string $post_id
*/
protected $post_id;

/**
* Class constructor.
*
Expand Down Expand Up @@ -85,7 +78,6 @@ public function get( $page, $widget, $timeout = 3 ) {
$this->page = $page;
$this->widget = $widget;
$this->api_url = $this->set_api_url( $page, $widget );
$this->post_id = get_the_ID();

$this->status = $this->get_status();
$site_automation_data = false;
Expand All @@ -105,7 +97,7 @@ public function get( $page, $widget, $timeout = 3 ) {
$bypass_cache = apply_filters( 'sophi_bypass_get_cache', false, $page, $widget );

if ( ! $bypass_cache ) {
$site_automation_data = get_post_meta( $this->post_id, "_sophi_site_automation_data_{$this->page}_{$this->widget}", true );
$site_automation_data = get_option( "sophi_site_automation_data_{$page}_{$widget}" );
}

if ( $site_automation_data && ! empty( $this->status['success'] ) ) {
Expand Down Expand Up @@ -165,7 +157,7 @@ public function do_cron( $page, $widget ) {
* @return array
*/
public function get_status() {
return get_transient( "sophi_site_automation_status_{$this->post_id}_{$this->page}_{$this->widget}" );
return get_transient( "sophi_site_automation_status_{$this->page}_{$this->widget}" );
}

/**
Expand All @@ -190,10 +182,7 @@ private function set_status( $data ) {
}

$this->status = $data;

if ( ! empty( $this->post_id ) ) {
set_transient( "sophi_site_automation_status_{$this->post_id}_{$this->page}_{$this->widget}", $data, $this->get_cache_duration() );
}
set_transient( "sophi_site_automation_status_{$this->page}_{$this->widget}", $data, $this->get_cache_duration() );
}

/**
Expand Down Expand Up @@ -275,21 +264,9 @@ private function process( $response, $bypass_cache ) {
return [];
}


$post = get_post();

if ( ! $post || wp_is_post_revision( $post ) ) {
return $response;
}

$meta_key = "_sophi_site_automation_data_{$this->page}_{$this->widget}";
$created_at = date_create( 'now', wp_timezone() );

if ( $created_at && ! $bypass_cache ) {
update_post_meta( $post->ID, $meta_key, $response );
update_post_meta( $post->ID, $meta_key . '_created_at', $created_at->getTimestamp() );
if ( ! $bypass_cache ) {
update_option( "sophi_site_automation_data_{$this->page}_{$this->widget}", $response );
}

return $response;
}

Expand Down
33 changes: 0 additions & 33 deletions sophi.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,36 +122,3 @@ function sophi_setup_notice() {
<?php

}

/**
* Upgrader function for version 1.1.0
* Deletes sophi_site_automation like options in favor of new post_meta approach.
*
* @param $installed string The version installed.
*/
function sophi_upgrade_1_1_0( $installed ) {
global $wpdb;
if ( $installed && version_compare( $installed, '1.1.0', '<' ) ) {

$options = $wpdb->get_results( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE'%s' LIMIT 1000", '%sophi_site_automation_data%' ) );

foreach ( $options as $option ) {
delete_option( $option->option_name );
}
}
}

add_action( 'sophi_upgrade', 'sophi_upgrade_1_1_0' );

$installed = get_option( 'sophi_version' );

if ( ! $installed || version_compare( $installed, SOPHI_WP_VERSION, '<' ) ) {
/**
* Upgrader hook to
*
* @param string $installed The previous version reference installed.
*/
do_action( 'sophi_upgrade', $installed );

update_option( 'sophi_version', SOPHI_WP_VERSION, false );
}

0 comments on commit 543df44

Please sign in to comment.