Plugin Directory

Changeset 3454796


Ignore:
Timestamp:
02/05/2026 04:14:29 PM (2 weeks ago)
Author:
shift8
Message:

Removed async loopback

Location:
shift8-integration-for-gravity-forms-and-sap-business-one/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • shift8-integration-for-gravity-forms-and-sap-business-one/trunk/readme.txt

    r3454757 r3454796  
    55* Requires at least: 5.0
    66* Tested up to: 6.8
    7 * Stable tag: 1.4.6
     7* Stable tag: 1.4.8
    88* Requires PHP: 7.4
    99* License: GPLv3
     
    131131
    132132== Changelog ==
     133
     134= 1.4.8 =
     135* **CHANGED**: Switched to synchronous processing (standard GF add-on approach)
     136* **REMOVED**: Async loopback processing - was unreliable on many hosting environments
     137* **IMPROVED**: Now works reliably on ALL hosting environments
     138* **SIMPLIFIED**: Removed unnecessary complexity - follows GF best practices
     139
     140= 1.4.7 =
     141* Synchronous Processing option (superseded by 1.4.8)
    133142
    134143= 1.4.6 =
  • shift8-integration-for-gravity-forms-and-sap-business-one/trunk/shift8-gravitysap.php

    r3454757 r3454796  
    44 * Plugin URI: https://github.com/stardothosting/shift8-gravitysap
    55 * Description: Integrates Gravity Forms with SAP Business One, automatically creating Business Partners from form submissions.
    6  * Version: 1.4.6
     6 * Version: 1.4.8
    77 * Author: Shift8 Web
    88 * Author URI: https://shift8web.ca
     
    2323
    2424// Plugin constants
    25 define('SHIFT8_GRAVITYSAP_VERSION', '1.4.6');
     25define('SHIFT8_GRAVITYSAP_VERSION', '1.4.8');
    2626define('SHIFT8_GRAVITYSAP_PLUGIN_FILE', __FILE__);
    2727define('SHIFT8_GRAVITYSAP_PLUGIN_DIR', plugin_dir_path(__FILE__));
     
    245245        add_action('wp_ajax_load_itemcodes', array($this, 'ajax_load_itemcodes'));
    246246        add_action('admin_footer', array($this, 'add_retry_button_script'));
    247        
    248         // Async SAP processing endpoint (accessible without login for loopback requests)
    249         add_action('wp_ajax_shift8_gravitysap_async_process', array($this, 'ajax_async_sap_process'));
    250         add_action('wp_ajax_nopriv_shift8_gravitysap_async_process', array($this, 'ajax_async_sap_process'));
    251247       
    252248       
     
    16991695        shift8_gravitysap_debug_log('✅ SAP connection settings are complete');
    17001696       
    1701         // Set initial status to pending (will be processed async)
    1702         $this->update_entry_sap_status($entry['id'], 'pending', '', '');
    1703         shift8_gravitysap_debug_log('STEP 3: Entry status set to PENDING');
    1704        
    1705         // Generate a secure token for async processing
    1706         $async_token = wp_generate_password(32, false);
    1707         gform_update_meta($entry['id'], 'sap_async_token', wp_hash($async_token));
    1708         shift8_gravitysap_debug_log('STEP 4: Generated async security token');
    1709        
    1710         // Fire non-blocking loopback request to process SAP integration asynchronously
    1711         shift8_gravitysap_debug_log('STEP 5: About to fire async loopback request', array(
    1712             'ajax_url' => admin_url('admin-ajax.php'),
    1713             'entry_id' => $entry['id'],
    1714             'form_id' => $form['id']
    1715         ));
    1716        
    1717         $this->fire_async_sap_process($entry['id'], $form['id'], $async_token);
    1718        
    1719         shift8_gravitysap_debug_log('🚀 STEP 6: Async loopback request FIRED - form submission handler complete', array(
    1720             'entry_id' => $entry['id'],
    1721             'form_id' => $form['id'],
    1722             'note' => 'If you do not see ASYNC SAP PROCESSING STARTED below, the loopback request failed'
    1723         ));
    1724     }
    1725    
    1726     /**
    1727      * Fire non-blocking loopback request for async SAP processing
    1728      *
    1729      * @since 1.4.0
    1730      * @param int    $entry_id    Entry ID
    1731      * @param int    $form_id     Form ID
    1732      * @param string $async_token Security token for verification
    1733      */
    1734     private function fire_async_sap_process($entry_id, $form_id, $async_token) {
    1735         $ajax_url = admin_url('admin-ajax.php');
    1736        
    1737         $args = array(
    1738             'timeout'   => 0.01, // Essentially non-blocking
    1739             'blocking'  => false, // Don't wait for response
    1740             'sslverify' => apply_filters('https_local_ssl_verify', false),
    1741             'body'      => array(
    1742                 'action'      => 'shift8_gravitysap_async_process',
    1743                 'entry_id'    => $entry_id,
    1744                 'form_id'     => $form_id,
    1745                 'async_token' => $async_token,
    1746             ),
    1747         );
    1748        
    1749         shift8_gravitysap_debug_log('🔄 Sending async loopback request', array(
    1750             'ajax_url' => $ajax_url,
    1751             'timeout' => $args['timeout'],
    1752             'blocking' => $args['blocking'],
    1753             'action' => $args['body']['action']
    1754         ));
    1755        
    1756         $response = wp_remote_post($ajax_url, $args);
    1757        
    1758         // Log if there's an error with the request itself
    1759         if (is_wp_error($response)) {
    1760             shift8_gravitysap_debug_log('⚠️ Loopback request returned WP_Error (this may be normal for non-blocking)', array(
    1761                 'error_message' => $response->get_error_message(),
    1762                 'error_code' => $response->get_error_code()
    1763             ));
    1764         } else {
    1765             shift8_gravitysap_debug_log('✅ Loopback request dispatched (non-blocking, so response may be incomplete)');
    1766         }
    1767     }
    1768    
    1769     /**
    1770      * AJAX handler for async SAP processing
    1771      *
    1772      * Processes the SAP integration asynchronously via loopback request.
    1773      * This is called by fire_async_sap_process() and runs in a separate PHP process.
    1774      *
    1775      * @since 1.4.0
    1776      */
    1777     public function ajax_async_sap_process() {
    1778         // Log immediately on handler entry - this confirms the loopback request reached the server
    1779         shift8_gravitysap_debug_log('========== ASYNC HANDLER ENTRY ==========', array(
    1780             'received_post_data' => array(
    1781                 'has_entry_id' => isset($_POST['entry_id']) ? 'yes' : 'no',
    1782                 'has_form_id' => isset($_POST['form_id']) ? 'yes' : 'no',
    1783                 'has_async_token' => isset($_POST['async_token']) ? 'yes' : 'no',
    1784                 'action' => isset($_POST['action']) ? sanitize_text_field(wp_unslash($_POST['action'])) : 'not set'
    1785             )
    1786         ));
    1787        
    1788         // Verify request parameters
    1789         $entry_id = isset($_POST['entry_id']) ? absint(wp_unslash($_POST['entry_id'])) : 0;
    1790         $form_id = isset($_POST['form_id']) ? absint(wp_unslash($_POST['form_id'])) : 0;
    1791         $async_token = isset($_POST['async_token']) ? sanitize_text_field(wp_unslash($_POST['async_token'])) : '';
    1792        
    1793         shift8_gravitysap_debug_log('Parsed request parameters', array(
    1794             'entry_id' => $entry_id,
    1795             'form_id' => $form_id,
    1796             'async_token_length' => strlen($async_token)
    1797         ));
    1798        
    1799         if (empty($entry_id) || empty($form_id) || empty($async_token)) {
    1800             shift8_gravitysap_debug_log('❌ Async SAP process: Missing required parameters - aborting', array(
    1801                 'entry_id_empty' => empty($entry_id),
    1802                 'form_id_empty' => empty($form_id),
    1803                 'async_token_empty' => empty($async_token)
    1804             ));
    1805             wp_die();
    1806         }
    1807        
    1808         // Verify the async token
    1809         $stored_token_hash = gform_get_meta($entry_id, 'sap_async_token');
    1810         shift8_gravitysap_debug_log('Token verification', array(
    1811             'has_stored_token' => !empty($stored_token_hash) ? 'yes' : 'no'
    1812         ));
    1813        
    1814         if (empty($stored_token_hash) || !hash_equals($stored_token_hash, wp_hash($async_token))) {
    1815             shift8_gravitysap_debug_log('❌ Async SAP process: Invalid or missing token - aborting', array(
    1816                 'entry_id' => $entry_id,
    1817                 'stored_token_empty' => empty($stored_token_hash),
    1818                 'hash_mismatch' => !empty($stored_token_hash) ? 'yes' : 'n/a'
    1819             ));
    1820             wp_die();
    1821         }
    1822        
    1823         // Clear the token (single use)
    1824         gform_delete_meta($entry_id, 'sap_async_token');
    1825         shift8_gravitysap_debug_log('✅ Token verified and cleared');
    1826        
    1827         shift8_gravitysap_debug_log('========== ASYNC SAP PROCESSING STARTED ==========', array(
    1828             'entry_id' => $entry_id,
    1829             'form_id' => $form_id
    1830         ));
    1831        
    1832         // Get entry and form data
    1833         $entry = GFAPI::get_entry($entry_id);
    1834         $form = GFAPI::get_form($form_id);
    1835        
    1836         if (is_wp_error($entry) || !$form) {
    1837             shift8_gravitysap_debug_log('❌ Async SAP process: Failed to load entry or form', array(
    1838                 'entry_id' => $entry_id,
    1839                 'form_id' => $form_id
    1840             ));
    1841             wp_die();
    1842         }
    1843        
    1844         // Process the SAP integration synchronously (we're now in async context)
     1697        // Set status to processing
     1698        $this->update_entry_sap_status($entry['id'], 'processing', '', '');
     1699        shift8_gravitysap_debug_log('STEP 3: Entry status set to PROCESSING');
     1700       
     1701        // Process SAP integration synchronously (standard approach used by most GF add-ons)
     1702        shift8_gravitysap_debug_log('STEP 4: Starting SAP integration processing');
    18451703        $this->process_sap_integration_sync($entry, $form);
    18461704       
    1847         wp_die();
    1848     }
    1849    
    1850     /**
    1851      * Synchronous SAP integration processing
     1705        shift8_gravitysap_debug_log('✅ SAP integration processing complete');
     1706    }
     1707   
     1708    /**
     1709     * SAP integration processing
    18521710     *
    18531711     * This is the actual SAP processing logic, called either by async handler
Note: See TracChangeset for help on using the changeset viewer.