Skip to content
Closed
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
11 changes: 10 additions & 1 deletion includes/ExternalVersionUpdate/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Exception;
use WC_Facebookcommerce_Utils;
use WooCommerce\Facebook\Utilities\Heartbeat;
use WooCommerce\Facebook\Framework\Logger;

/**
* Facebook for WooCommerce External Plugin Version Update.
Expand Down Expand Up @@ -90,7 +91,15 @@ public function send_new_version_to_facebook_server() {
}
return update_option( self::LATEST_VERSION_SENT, WC_Facebookcommerce_Utils::PLUGIN_VERSION );
} catch ( Exception $e ) {
WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( $e->getMessage() );
Logger::log(
$e->getMessage(),
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::ERROR,
)
);
// If the request fails, we should retry it in the next heartbeat.
return false;
}
Expand Down
82 changes: 73 additions & 9 deletions includes/Products/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ private function add_hooks() {
* @throws PluginException If the feed secret is invalid, file is not readable, or other errors occur.
*/
public function handle_feed_data_request() {
\WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Facebook is requesting the product feed.' );
Logger::log(
'Facebook is requesting the product feed.',
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::DEBUG,
)
);
facebook_for_woocommerce()->get_tracker()->track_feed_file_requested();

$feed_handler = new \WC_Facebook_Product_Feed();
Expand Down Expand Up @@ -120,15 +128,31 @@ public function handle_feed_data_request() {

// fpassthru might be disabled in some hosts (like Flywheel)
if ( $this->is_fpassthru_disabled() || ! @fpassthru( $file ) ) {
\WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'fpassthru is disabled: getting file contents' );
Logger::log(
'fpassthru is disabled: getting file contents',
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::DEBUG,
)
);
$contents = @stream_get_contents( $file );
if ( ! $contents ) {
throw new PluginException( 'Could not get feed file contents.', 500 );
}
echo $contents; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
} catch ( \Exception $exception ) {
\WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Could not serve product feed. ' . $exception->getMessage() . ' (' . $exception->getCode() . ')' );
Logger::log(
'Could not serve product feed. ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::ERROR,
)
);
status_header( $exception->getCode() );
}
exit;
Expand Down Expand Up @@ -189,7 +213,7 @@ public function schedule_feed_generation() {
array(
'should_send_log_to_meta' => true,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::DEBUG,
'woocommerce_log_level' => \WC_Log_Levels::WARNING,
)
);
return;
Expand Down Expand Up @@ -218,7 +242,15 @@ public function schedule_feed_generation() {
public function send_request_to_upload_feed() {
$feed_id = self::retrieve_or_create_integration_feed_id();
if ( empty( $feed_id ) ) {
WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Feed: integration feed ID is null or empty, feed will not be uploaded.' );
Logger::log(
'Feed: integration feed ID is null or empty, feed will not be uploaded.',
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::WARNING,
)
);
return;
}

Expand All @@ -245,15 +277,31 @@ public function retrieve_or_create_integration_feed_id() {
$feed_id = self::request_and_filter_integration_feed_id();
if ( $feed_id ) {
facebook_for_woocommerce()->get_integration()->update_feed_id( $feed_id );
WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Feed: feed_id = ' . $feed_id . ', queried and selected from Meta API.' );
Logger::log(
'Feed: feed_id = ' . $feed_id . ', queried and selected from Meta API.',
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::DEBUG,
)
);
return $feed_id;
}

// Attempt 2. Create a new feed
$feed_id = self::create_feed_id();
if ( $feed_id ) {
facebook_for_woocommerce()->get_integration()->update_feed_id( $feed_id );
WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Feed: feed_id = ' . $feed_id . ', created a new feed via Meta API.' );
Logger::log(
'Feed: feed_id = ' . $feed_id . ', created a new feed via Meta API.',
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::DEBUG,
)
);
return $feed_id;
}

Expand All @@ -278,7 +326,15 @@ private function request_and_filter_integration_feed_id() {
$feed_nodes = facebook_for_woocommerce()->get_api()->read_feeds( $catalog_id )->data;
} catch ( Exception $e ) {
$message = sprintf( 'There was an error trying to get feed nodes for catalog: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( $message );
Logger::log(
$message,
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::ERROR,
)
);
return '';
}

Expand All @@ -298,7 +354,15 @@ private function request_and_filter_integration_feed_id() {
$feed_metadata = facebook_for_woocommerce()->get_api()->read_feed( $feed['id'] );
} catch ( Exception $e ) {
$message = sprintf( 'There was an error trying to get feed metadata: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( $message );
Logger::log(
$message,
[],
array(
'should_send_log_to_meta' => false,
'should_save_log_in_woocommerce' => true,
'woocommerce_log_level' => \WC_Log_Levels::ERROR,
)
);
continue;
}

Expand Down