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
5 changes: 3 additions & 2 deletions class-wc-facebookcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,16 @@ public function add_wordpress_integration() {
* @since 2.3.3
* @param string $message error or message to save to log
* @param string $log_id optional log id to segment the files by, defaults to plugin id
* @param string $level optional log level represents log's tag
*/
public function log( $message, $log_id = null ) {
public function log( $message, $log_id = null, $level = null ) {
// Bail if site is connected and user has disabled logging.
// If site is disconnected, force-enable logging so merchant can diagnose connection issues.
if ( ( ! $this->get_integration() || ! $this->get_integration()->is_debug_mode_enabled() ) && $this->get_connection_handler()->is_connected() ) {
return;
}

parent::log( $message, $log_id );
parent::log( $message, $log_id, $level );
}

/**
Expand Down
58 changes: 29 additions & 29 deletions facebook-commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ private function find_variation_product_item_ids( string $product_group_id ): ar
} while ( $response = $this->facebook_for_woocommerce->get_api()->next( $response, 2 ) );
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to find the IDs for Product Items in the Product Group %s: %s', $product_group_id, $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}

return $product_item_ids;
Expand Down Expand Up @@ -1367,7 +1367,7 @@ public function create_product_group( WC_Facebook_Product $woo_product, string $
}
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to create the product group: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}

return null;
Expand All @@ -1392,7 +1392,7 @@ public function update_product_group( WC_Facebook_Product $woo_product ) {
$variants = $woo_product->prepare_variants_for_group();

if ( ! $variants ) {
WC_Facebookcommerce_Utils::log(
WC_Facebookcommerce_Utils::logWithDebugModeEnabled(
sprintf(
/* translators: %1$s is referring to facebook product group id. */
__(
Expand Down Expand Up @@ -1434,7 +1434,7 @@ public function update_product_group( WC_Facebook_Product $woo_product ) {
}
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to update Product Group %s: %s', $fb_product_group_id, $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
}

Expand Down Expand Up @@ -1462,7 +1462,7 @@ public function create_product_item_batch_api( $woo_product, $retailer_id, $prod
}
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to create a product item: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}

return '';
Expand Down Expand Up @@ -1492,7 +1492,7 @@ public function create_product_item( $woo_product, $retailer_id, $product_group_
}
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to create a product item: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}

return '';
Expand Down Expand Up @@ -1626,7 +1626,7 @@ public function update_product_item_batch_api( WC_Facebook_Product $woo_product,
}
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to update a product item: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
}

Expand Down Expand Up @@ -1660,7 +1660,7 @@ public function update_product_item( WC_Facebook_Product $woo_product, string $f
}
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to update a product item: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
}

Expand Down Expand Up @@ -1694,7 +1694,7 @@ public function create_or_update_product_set_item( $product_set_data, $product_s
}
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to create/update a product set: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
}

Expand All @@ -1713,7 +1713,7 @@ public function delete_product_set_item( string $fb_product_set_id ) {
$this->facebook_for_woocommerce->get_api()->delete_product_set_item( $fb_product_set_id, $allow_live_deletion );
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to delete a product set item: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
}

Expand Down Expand Up @@ -1909,7 +1909,7 @@ public function remove_resync_message() {
* @return void
*/
public function display_error_message( string $msg ): void {
WC_Facebookcommerce_Utils::log( $msg );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $msg );
set_transient( 'facebook_plugin_api_error', $msg, self::FB_MESSAGE_DISPLAY_TIME );
}

Expand Down Expand Up @@ -2072,7 +2072,7 @@ public function delete_post_meta_loop( array $products ) {
**/
public function reset_all_products() {
if ( ! is_admin() ) {
WC_Facebookcommerce_Utils::log(
WC_Facebookcommerce_Utils::logWithDebugModeEnabled(
'Not resetting any FBIDs from products,
must call reset from admin context.'
);
Expand All @@ -2081,7 +2081,7 @@ public function reset_all_products() {
}

// Include draft products (omit 'post_status' => 'publish')
WC_Facebookcommerce_Utils::log( 'Removing FBIDs from all products' );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Removing FBIDs from all products' );

$post_ids = get_posts(
[
Expand All @@ -2108,7 +2108,7 @@ public function reset_all_products() {
$post_ids = array_merge( $post_ids, $children );
$this->delete_post_meta_loop( $post_ids );

WC_Facebookcommerce_Utils::log( 'Product FBIDs deleted' );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Product FBIDs deleted' );

return true;
}
Expand All @@ -2127,7 +2127,7 @@ public function reset_single_product( int $wp_id ) {

$this->delete_post_meta_loop( $products );

WC_Facebookcommerce_Utils::log( 'Deleted FB Metadata for product ' . $wp_id );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Deleted FB Metadata for product ' . $wp_id );
}

/**
Expand Down Expand Up @@ -2236,12 +2236,12 @@ private function sync_facebook_products() {
*/
private function sync_facebook_products_using_background_processor() {
if ( ! $this->is_product_sync_enabled() ) {
WC_Facebookcommerce_Utils::log( 'Sync to Facebook is disabled' );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Sync to Facebook is disabled' );
throw new PluginException( __( 'Product sync is disabled.', 'facebook-for-woocommerce' ) );
}

if ( ! $this->is_configured() || ! $this->get_product_catalog_id() ) {
WC_Facebookcommerce_Utils::log( sprintf( 'Not syncing, the plugin is not configured or the Catalog ID is missing' ) );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( sprintf( 'Not syncing, the plugin is not configured or the Catalog ID is missing' ) );
throw new PluginException( __( 'The plugin is not configured or the Catalog ID is missing.', 'facebook-for-woocommerce' ) );
}

Expand All @@ -2256,7 +2256,7 @@ private function sync_facebook_products_using_background_processor() {
}

if ( $currently_syncing ) {
WC_Facebookcommerce_Utils::log( 'Not syncing again, sync already in progress' );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Not syncing again, sync already in progress' );
WC_Facebookcommerce_Utils::fblog(
'Tried to sync during an in-progress sync!',
[],
Expand All @@ -2269,10 +2269,10 @@ private function sync_facebook_products_using_background_processor() {
$catalog = $this->facebook_for_woocommerce->get_api()->get_catalog( $this->get_product_catalog_id() );
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to delete a product set item: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
if ( $catalog->id ) {
WC_Facebookcommerce_Utils::log( 'Not syncing, invalid product catalog!' );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Not syncing, invalid product catalog!' );
WC_Facebookcommerce_Utils::fblog(
'Tried to sync with an invalid product catalog!',
[],
Expand Down Expand Up @@ -2306,9 +2306,9 @@ private function sync_facebook_products_using_background_processor() {
set_transient( self::FB_SYNC_IN_PROGRESS, true, self::FB_SYNC_TIMEOUT );
set_transient( self::FB_SYNC_REMAINING, (int) $total );
$this->display_info_message( $starting_message );
WC_Facebookcommerce_Utils::log( $starting_message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $starting_message );
foreach ( $post_ids as $post_id ) {
WC_Facebookcommerce_Utils::log( 'Pushing post to queue: ' . $post_id );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Pushing post to queue: ' . $post_id );
$this->background_processor->push_to_queue( $post_id );
}

Expand Down Expand Up @@ -2338,7 +2338,7 @@ private function sync_facebook_products_using_background_processor() {
$this->on_product_publish( $post_id );
++$count;
}
WC_Facebookcommerce_Utils::log( 'Synced ' . $count . ' products' );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Synced ' . $count . ' products' );
$this->remove_sticky_message();
$this->display_info_message( 'Facebook product sync complete!' );
delete_transient( self::FB_SYNC_IN_PROGRESS );
Expand Down Expand Up @@ -2962,10 +2962,10 @@ public function delete_product_item( int $wp_id ): void {
if ( $fb_product_item_id ) {
try {
$pi_result = $this->facebook_for_woocommerce->get_api()->delete_product_item( $fb_product_item_id );
WC_Facebookcommerce_Utils::log( $pi_result );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $pi_result );
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to delete a product set item: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
}
}
Expand All @@ -2984,10 +2984,10 @@ public function delete_product_group( int $product_id ) {
// TODO: replace with a call to API::delete_product_group() {WV 2020-05-26}
try {
$pg_result = $this->facebook_for_woocommerce->get_api()->delete_product_group( $product_group_id );
WC_Facebookcommerce_Utils::log( $pg_result );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $pg_result );
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to delete a product group: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
}
}
Expand Down Expand Up @@ -3060,7 +3060,7 @@ public function update_fb_visibility( $product_id, $visibility ) {
}
} catch ( ApiException $e ) {
$message = sprintf( 'There was an error trying to update product item: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
}
}
}
Expand Down Expand Up @@ -3131,7 +3131,7 @@ public function get_product_fbid( string $fbid_type, int $wp_id, $woo_product =
}
} catch ( Exception $e ) {
/* @TODO: Log exception. */
WC_Facebookcommerce_Utils::log( $e->getMessage() );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $e->getMessage() );
$this->display_error_message(
sprintf(
/* translators: Placeholders %1$s - original error message from Facebook API */
Expand Down
2 changes: 1 addition & 1 deletion includes/ExternalVersionUpdate/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ 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( $e->getMessage() );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $e->getMessage() );
// If the request fails, we should retry it in the next heartbeat.
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions includes/Feed/AbstractFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function get_feed_secret(): string {
*/
public function handle_feed_data_request(): void {
$name = static::get_data_stream_name();
\WC_Facebookcommerce_Utils::log( "{$name} feed: Meta is requesting feed file." );
\WC_Facebookcommerce_Utils::logWithDebugModeEnabled( "{$name} feed: Meta is requesting feed file." );

$file_path = $this->feed_writer->get_file_path();

Expand Down Expand Up @@ -271,7 +271,7 @@ public function handle_feed_data_request(): void {
// fpassthru might be disabled in some hosts (like Flywheel).
// phpcs:ignore
if ( \WC_Facebookcommerce_Utils::is_fpassthru_disabled() || ! @fpassthru( $file ) ) {
\WC_Facebookcommerce_Utils::log( "{$name} feed: fpassthru is disabled: getting file contents." );
\WC_Facebookcommerce_Utils::logWithDebugModeEnabled( "{$name} feed: fpassthru is disabled: getting file contents." );
//phpcs:ignore
$contents = @stream_get_contents( $file );
if ( ! $contents ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/Feed/FeedConfigurationDetection.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function get_data_source_feed_tracker_info() {
$metadata = $this->get_feed_metadata( $feed['id'] );
} catch ( Exception $e ) {
$message = sprintf( 'There was an error trying to get feed metadata: %s', $e->getMessage() );
WC_Facebookcommerce_Utils::log( $message );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( $message );
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions includes/Framework/ErrorLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public function process_error_log( $raw_context ) {
try {
$response = facebook_for_woocommerce()->get_api()->log_to_meta( $context );
if ( $response->success ) {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error log: ' . wp_json_encode( $context ) );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error log: ' . wp_json_encode( $context ), \WC_Log_Levels::ERROR );
} else {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Bad response from log_to_meta request' );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Bad response from log_to_meta request', \WC_Log_Levels::ERROR );
}
} catch ( \Exception $e ) {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error persisting error logs: ' . $e->getMessage() );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error persisting error logs: ' . $e->getMessage(), \WC_Log_Levels::ERROR );
}
}

Expand Down
14 changes: 12 additions & 2 deletions includes/Framework/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,15 +528,25 @@ public function add_system_status_php_information( $rows ) {
* @since 2.0.0
* @param string $message error or message to save to log
* @param string $log_id optional log id to segment the files by, defaults to plugin id
* @param string $level optional log level represents log's tag, defaults to notice
*/
public function log( $message, $log_id = null ) {
public function log( $message, $log_id = null, $level = null ) {
if ( is_null( $log_id ) ) {
$log_id = $this->get_id();
}
if ( is_null( $level ) ) {
$level = \WC_Log_Levels::NOTICE;
}
if ( ! is_object( $this->logger ) ) {
$this->logger = new \WC_Logger();
}
$this->logger->add( $log_id, $message );
$this->logger->log(
$level,
$message,
array(
'source' => $log_id,
)
);
}


Expand Down
Loading