Plugin Directory

Changeset 2378844


Ignore:
Timestamp:
09/10/2020 03:57:26 PM (6 years ago)
Author:
highways
Message:

Version 1.0.6

Location:
highways-sync-for-intercom
Files:
1 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • highways-sync-for-intercom/.idea/workspace.xml

    r2261884 r2378844  
    33  <component name="ChangeListManager">
    44    <list default="true" id="75bfd89f-af77-46a3-ba15-a576098cd96d" name="Default Changelist" comment="">
    5       <change afterPath="$PROJECT_DIR$/../../infusionsoft/infusionsoft-php" afterDir="false" />
    6       <change beforePath="$PROJECT_DIR$/trunk/includes/webhooks.php" beforeDir="false" afterPath="$PROJECT_DIR$/trunk/includes/webhooks.php" afterDir="false" />
     5      <change afterPath="$PROJECT_DIR$/../../thinkific-video/app/Http/Middleware/SSLRedirect.php" afterDir="false" />
     6      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
     7      <change beforePath="$PROJECT_DIR$/tags/1.0.1" beforeDir="true" />
     8      <change beforePath="$PROJECT_DIR$/trunk/highways-sync-for-intercom.php" beforeDir="false" afterPath="$PROJECT_DIR$/trunk/highways-sync-for-intercom.php" afterDir="false" />
     9      <change beforePath="$PROJECT_DIR$/trunk/includes/intercom.php" beforeDir="false" afterPath="$PROJECT_DIR$/trunk/includes/intercom.php" afterDir="false" />
     10      <change beforePath="$PROJECT_DIR$/trunk/readme.txt" beforeDir="false" afterPath="$PROJECT_DIR$/trunk/readme.txt" afterDir="false" />
     11      <change beforePath="$PROJECT_DIR$/../../drone-mapper/.idea/drone-mapper.iml" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/.idea/drone-mapper.iml" afterDir="false" />
     12      <change beforePath="$PROJECT_DIR$/../../drone-mapper/.idea/php.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/.idea/php.xml" afterDir="false" />
     13      <change beforePath="$PROJECT_DIR$/../../drone-mapper/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/.idea/vcs.xml" afterDir="false" />
     14      <change beforePath="$PROJECT_DIR$/../../drone-mapper/.vagrant/machines/drone-mapper/virtualbox/action_set_name" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/.vagrant/machines/drone-mapper/virtualbox/action_set_name" afterDir="false" />
     15      <change beforePath="$PROJECT_DIR$/../../drone-mapper/app/Drone.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/app/Drone.php" afterDir="false" />
     16      <change beforePath="$PROJECT_DIR$/../../drone-mapper/app/Flight.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/app/Flight.php" afterDir="false" />
     17      <change beforePath="$PROJECT_DIR$/../../drone-mapper/app/Http/Controllers/MapController.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/app/Http/Controllers/MapController.php" afterDir="false" />
     18      <change beforePath="$PROJECT_DIR$/../../drone-mapper/app/Pilot.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/app/Pilot.php" afterDir="false" />
     19      <change beforePath="$PROJECT_DIR$/../../drone-mapper/app/Point.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/app/Point.php" afterDir="false" />
     20      <change beforePath="$PROJECT_DIR$/../../drone-mapper/app/PointMeta.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/app/PointMeta.php" afterDir="false" />
     21      <change beforePath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_08_174416_create_points_table.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_08_174416_create_points_table.php" afterDir="false" />
     22      <change beforePath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_08_174852_create_point_metas_table.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_08_174852_create_point_metas_table.php" afterDir="false" />
     23      <change beforePath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_10_123314_create_flights_table.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_10_123314_create_flights_table.php" afterDir="false" />
     24      <change beforePath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_10_123328_create_drones_table.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_10_123328_create_drones_table.php" afterDir="false" />
     25      <change beforePath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_10_123340_create_pilots_table.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/database/migrations/2020_07_10_123340_create_pilots_table.php" afterDir="false" />
     26      <change beforePath="$PROJECT_DIR$/../../drone-mapper/database/seeds/IrishAirspaceSeeder.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/database/seeds/IrishAirspaceSeeder.php" afterDir="false" />
     27      <change beforePath="$PROJECT_DIR$/../../drone-mapper/resources/views/map.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../drone-mapper/resources/views/map.blade.php" afterDir="false" />
     28      <change beforePath="$PROJECT_DIR$/../../highways-saas/app/Http/Controllers/Services/ThinkificController.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../highways-saas/app/Http/Controllers/Services/ThinkificController.php" afterDir="false" />
     29      <change beforePath="$PROJECT_DIR$/../../highways-sync/app/Http/Auth/LoginController.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../highways-sync/app/Http/Auth/LoginController.php" afterDir="false" />
     30      <change beforePath="$PROJECT_DIR$/../../highways-sync/app/Http/Controllers/V2/SyncController.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../highways-sync/app/Http/Controllers/V2/SyncController.php" afterDir="false" />
     31      <change beforePath="$PROJECT_DIR$/../../highways-sync/app/Rules/ReCaptcha.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../highways-sync/app/Rules/ReCaptcha.php" afterDir="false" />
     32      <change beforePath="$PROJECT_DIR$/../../highways-sync/resources/js/components/LogChart.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../../highways-sync/resources/js/components/LogChart.vue" afterDir="false" />
     33      <change beforePath="$PROJECT_DIR$/../../highways-sync/resources/js/components/SyncOverview.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../../highways-sync/resources/js/components/SyncOverview.vue" afterDir="false" />
     34      <change beforePath="$PROJECT_DIR$/../../highways-sync/resources/views/vendor/spark/modals/sync-delete.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../highways-sync/resources/views/vendor/spark/modals/sync-delete.blade.php" afterDir="false" />
     35      <change beforePath="$PROJECT_DIR$/../../infusionsoft/infusionsoft-php" beforeDir="false" afterPath="$PROJECT_DIR$/../../infusionsoft/infusionsoft-php" afterDir="false" />
     36      <change beforePath="$PROJECT_DIR$/../../nimble-php/.gitignore" beforeDir="false" />
     37      <change beforePath="$PROJECT_DIR$/../../nimble-php/README.md" beforeDir="false" />
     38      <change beforePath="$PROJECT_DIR$/../../nimble-php/composer.json" beforeDir="false" />
     39      <change beforePath="$PROJECT_DIR$/../../nimble-php/src/NimbleClient.php" beforeDir="false" />
     40      <change beforePath="$PROJECT_DIR$/../../nimble-php/src/NimbleContacts.php" beforeDir="false" />
     41      <change beforePath="$PROJECT_DIR$/../../nimble-php/src/NimbleResource.php" beforeDir="false" />
     42      <change beforePath="$PROJECT_DIR$/../../nimble-php/src/NimbleUser.php" beforeDir="false" />
     43      <change beforePath="$PROJECT_DIR$/../../thinkific-video/.idea/php.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/.idea/php.xml" afterDir="false" />
     44      <change beforePath="$PROJECT_DIR$/../../thinkific-video/.idea/thinkific-video.iml" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/.idea/thinkific-video.iml" afterDir="false" />
     45      <change beforePath="$PROJECT_DIR$/../../thinkific-video/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/.idea/vcs.xml" afterDir="false" />
     46      <change beforePath="$PROJECT_DIR$/../../thinkific-video/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/.idea/workspace.xml" afterDir="false" />
     47      <change beforePath="$PROJECT_DIR$/../../thinkific-video/app/Assignment.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/app/Assignment.php" afterDir="false" />
     48      <change beforePath="$PROJECT_DIR$/../../thinkific-video/app/Http/Auth/LoginController.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/app/Http/Auth/LoginController.php" afterDir="false" />
     49      <change beforePath="$PROJECT_DIR$/../../thinkific-video/app/Http/Controllers/EmbedController.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/app/Http/Controllers/EmbedController.php" afterDir="false" />
     50      <change beforePath="$PROJECT_DIR$/../../thinkific-video/app/Http/Kernel.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/app/Http/Kernel.php" afterDir="false" />
     51      <change beforePath="$PROJECT_DIR$/../../thinkific-video/app/Http/Middleware/TrustProxies.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/app/Http/Middleware/TrustProxies.php" afterDir="false" />
     52      <change beforePath="$PROJECT_DIR$/../../thinkific-video/app/Providers/SparkServiceProvider.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/app/Providers/SparkServiceProvider.php" afterDir="false" />
     53      <change beforePath="$PROJECT_DIR$/../../thinkific-video/app/Student.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/app/Student.php" afterDir="false" />
     54      <change beforePath="$PROJECT_DIR$/../../thinkific-video/app/Submission.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/app/Submission.php" afterDir="false" />
     55      <change beforePath="$PROJECT_DIR$/../../thinkific-video/composer.json" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/composer.json" afterDir="false" />
     56      <change beforePath="$PROJECT_DIR$/../../thinkific-video/composer.lock" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/composer.lock" afterDir="false" />
     57      <change beforePath="$PROJECT_DIR$/../../thinkific-video/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/package.json" afterDir="false" />
     58      <change beforePath="$PROJECT_DIR$/../../thinkific-video/public/js/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/public/js/app.js" afterDir="false" />
     59      <change beforePath="$PROJECT_DIR$/../../thinkific-video/resources/js/components/public/pComments.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/resources/js/components/public/pComments.vue" afterDir="false" />
     60      <change beforePath="$PROJECT_DIR$/../../thinkific-video/resources/js/components/public/pPasscode.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/resources/js/components/public/pPasscode.vue" afterDir="false" />
     61      <change beforePath="$PROJECT_DIR$/../../thinkific-video/resources/js/components/public/pSubmissionViewer.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../../thinkific-video/resources/js/components/public/pSubmissionViewer.vue" afterDir="false" />
    762    </list>
    863    <option name="SHOW_DIALOG" value="false" />
     
    1267  </component>
    1368  <component name="ComposerSettings">
    14     <execution>
    15       <executable />
    16     </execution>
     69    <execution />
    1770  </component>
    1871  <component name="Git.Settings">
     
    2376  <component name="ProjectViewState">
    2477    <option name="hideEmptyMiddlePackages" value="true" />
    25     <option name="showExcludedFiles" value="true" />
    2678    <option name="showLibraryContents" value="true" />
    2779  </component>
     
    3284    <property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
    3385  </component>
     86  <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
    3487  <component name="SvnConfiguration" cleanupOnStartRun="true">
    3588    <configuration>$USER_HOME$/.subversion</configuration>
     89    <supportedVersion>125</supportedVersion>
    3690  </component>
    3791  <component name="SvnFileUrlMappingImpl">
     
    61115      <updated>1583673047784</updated>
    62116      <workItem from="1583673049069" duration="640000" />
     117      <workItem from="1587651197430" duration="3000" />
     118      <workItem from="1599750767017" duration="1718000" />
    63119    </task>
    64120    <servers />
    65121  </component>
    66122  <component name="TypeScriptGeneratedFilesManager">
    67     <option name="version" value="1" />
     123    <option name="version" value="3" />
    68124  </component>
    69125  <component name="WindowStateProjectService">
  • highways-sync-for-intercom/trunk/highways-sync-for-intercom.php

    r2285958 r2378844  
    44 * Plugin URI:  https://www.highways.io/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
    55 * Description: A complete WordPress to Intercom Sync Plugin
    6  * Version: 1.0.5
     6 * Version: 1.0.6
    77 * Author: Highways.io
    88 * Author URI: https://www.highways.io/?utm_source=wp-plugins&utm_campaign=intercom-wp&utm_medium=wp-dash
     
    2222if ( ! defined( 'ABSPATH' ) ) exit;
    2323
    24 define( 'INTERCOM_WP_VERSION', '1.0.5' );
    25 define( 'INTERCOM_WP_PREVIOUS_STABLE_VERSION', '1.0.4' );
     24define( 'INTERCOM_WP_VERSION', '1.0.6' );
     25define( 'INTERCOM_WP_PREVIOUS_STABLE_VERSION', '1.0.5' );
    2626define( 'INTERCOM_WP_NAME', 'Highways Sync for Intercom' );
    2727define( 'INTERCOM_WP__FILE__', __FILE__ );
  • highways-sync-for-intercom/trunk/includes/intercom.php

    r2261884 r2378844  
    55use Intercom\IntercomClient;
    66
    7 if ( ! defined( 'ABSPATH' ) ) exit;
    8 
    9 class Intercom {
    10        
     7if (!defined('ABSPATH')) exit;
     8
     9class Intercom
     10{
     11
    1112    const API_KEY_OPTION = 'intercom_wp_intercom_api_key';
    12    
     13
    1314    public $user_id, $wp_user, $client, $options;
    14    
     15
    1516    public function __construct($user_id = false)
    1617    {
    17         $this->includes(); 
    18        
     18        $this->includes();
     19
    1920        $this->user_id = $user_id;
    20        
    21         if($this->user_id) {
    22        
    23             $this->wp_user = get_user_by( 'id', $this->user_id );
    24            
    25         }
    26          
     21
     22        if ($this->user_id) {
     23
     24            $this->wp_user = get_user_by('id', $this->user_id);
     25
     26        }
     27
    2728        $this->client = self::intercom_client();
    28        
     29
    2930        $this->options = [];
    30        
     31
    3132        /* Intercom Hook */
    3233        add_action('iwp_send_to_intercom', [$this, 'iwp_send_to_intercom']);
    3334    }
    34    
     35
    3536    public function includes()
    3637    {
    3738        /* Intercom PHP SDK */
    38        
    39         require INTERCOM_WP_PATH . '/includes/lib/intercom-php/vendor/autoload.php';
    40        
    41     }
    42    
    43     private function intercom_client() {
    44        
    45         $this->options = get_option('intercom_wp_settings');
    46        
    47         if(empty($this->options)) {
    48            
    49             $this->options = [];
    50            
    51         }
    52        
    53         if(isset($this->options[self::API_KEY_OPTION])) {
    54            
    55             $api_key = $this->options[self::API_KEY_OPTION];
    56         }
    57        
    58         else $api_key = false;
    59        
    60         if(empty($api_key)) return false;
    61        
     39
     40        require INTERCOM_WP_PATH . '/includes/lib/intercom-php/vendor/autoload.php';
     41
     42    }
     43
     44    public function logMe($message)
     45    {
     46        if(!is_string($message)) $message = print_r($message);
     47
     48        if (function_exists('wc_get_logger')) {
     49
     50            $logger = wc_get_logger();
     51
     52            $logger->info($message, array('source' => 'highways-sync-for-intercom'));
     53        } else error_log($message);
     54    }
     55
     56    private function intercom_client()
     57    {
     58
    6259        try {
    63    
     60
     61            $this->options = get_option('intercom_wp_settings');
     62
     63            if (empty($this->options)) {
     64
     65                $this->options = [];
     66
     67            }
     68
     69            if (isset($this->options[self::API_KEY_OPTION])) {
     70
     71                $api_key = $this->options[self::API_KEY_OPTION];
     72            } else $api_key = false;
     73
     74            if (empty($api_key)) throw new \Exception('Intercom API key is missing. Please reconnect Intercom or check your API Key is entered correctly.');
     75
    6476            return new IntercomClient($api_key, null, ['Intercom-Version' => apply_filters('iwp_api_version', 1.4)]);
    65            
    66         }
    67        
    68         catch (\Exception $e) {
    69            
    70             error_log($e->getMessage());
    71         }
    72        
    73     }
    74    
    75     public function iwp_send_to_intercom($key) {
    76        
     77
     78        } catch (\Exception $e) {
     79
     80            $this->logMe($e->getMessage());
     81        }
     82
     83    }
     84
     85    public function iwp_send_to_intercom($key)
     86    {
     87
    7788        $payload = get_transient($key);
    78    
    79         if(is_array($payload) && $this->client) {
    80            
     89
     90        if (is_array($payload) && $this->client) {
     91
    8192            delete_transient($key);
    82            
     93
    8394            $intercom = new Intercom;
    84            
     95
    8596            $type = $payload['type'];
    86            
     97
    8798            unset($payload['type']);
    88            
    89             $method =  $payload['method'];
    90            
     99
     100            $method = $payload['method'];
     101
    91102            unset($payload['method']);
    92              
     103
    93104            try {
    94                    
     105
    95106                $response = $this->client->{$type}->{$method}($payload);
    96                
    97             }
    98            
    99             catch(\Http\Client\Exception $e) {
    100                
    101                 error_log('Intercom Response Exception:: '.$e->getMessage());
    102             }
    103            
    104             catch(\Exception $e) {
    105                
    106                 error_log('Intercom Response Exception::'.$e->getMessage());
    107             }
    108            
    109         }
    110     }
    111    
    112     public function schedule_intercom_call($payload) {
    113        
     107
     108            } catch (\Http\Client\Exception $e) {
     109
     110                $this->logMe('Intercom Response Exception:: ' . $e->getMessage());
     111            } catch (\Exception $e) {
     112
     113                $this->logMe('Intercom Response Exception:: ' . $e->getMessage());
     114            }
     115
     116        }
     117    }
     118
     119    public function schedule_intercom_call($payload)
     120    {
     121
    114122        $key = self::create_transient_id($payload);
    115        
     123
    116124        $sync = isset($this->options['enable_sync_calls']) ? $this->options['enable_sync_calls'] : false;
    117            
    118         if(set_transient($key, $payload, DAY_IN_SECONDS)) {
    119            
    120             if($sync) $this->iwp_send_to_intercom($key);
    121                
    122             else as_schedule_single_action( time() + 5, 'iwp_send_to_intercom', array($key) );
    123         }
    124        
    125     }
    126        
    127     public function create_user() {
    128        
    129         $disabled = isset($this->options['disable_user_creation']) ? $this->options['disable_user_creation'] : false;
    130        
    131         if($disabled) return;
    132        
    133         if(self::API_VERSION > 1.4) {
    134            
     125
     126        if (set_transient($key, $payload, DAY_IN_SECONDS)) {
     127
     128            if ($sync) $this->iwp_send_to_intercom($key);
     129
     130            else {
     131
     132                if (function_exists('as_schedule_single_action')) {
     133
     134                    as_schedule_single_action(time() + 5, 'iwp_send_to_intercom', array($key));
     135
     136                } else wp_schedule_single_event(time() + 5, 'iwp_send_to_intercom', array($key));
     137
     138
     139            }
     140        }
     141
     142    }
     143
     144    public function create_user()
     145    {
     146
     147        $disabled = isset($this->options['disable_user_creation']) ? $this->options['disable_user_creation'] : false;
     148
     149        if ($disabled) return;
     150
     151        if (self::API_VERSION > 1.4) {
     152
    135153            $this->create_contact();
    136            
     154
    137155            return;
    138156        }
    139        
     157
    140158        $payload = array(
    141                 'method' => 'update',
    142                 'type' => 'users',
    143                 'name' => $this->wp_user->user_firstname.' '.$this->wp_user->user_lastname,
    144                 'last_request_at' => time()
    145             );
    146        
     159            'method' => 'update',
     160            'type' => 'users',
     161            'name' => $this->wp_user->user_firstname . ' ' . $this->wp_user->user_lastname,
     162            'last_request_at' => time()
     163        );
     164
    147165        $payload = apply_filters('iwp_create_user', $payload, $this->user_id);
    148        
     166
    149167        $payload = self::add_user_data($payload);
    150        
     168
    151169        $this->schedule_intercom_call($payload);
    152        
    153     }
    154    
    155     public function create_lead() {
    156        
    157         $disabled = isset($this->options['disable_lead_creation']) ? $this->options['disable_lead_creation'] : false;
    158        
    159         if($disabled) return;
    160        
    161         if(self::API_VERSION > 1.4) {
    162            
     170
     171    }
     172
     173    public function create_lead()
     174    {
     175
     176        $disabled = isset($this->options['disable_lead_creation']) ? $this->options['disable_lead_creation'] : false;
     177
     178        if ($disabled) return;
     179
     180        if (self::API_VERSION > 1.4) {
     181
    163182            $this->create_contact();
    164            
     183
    165184            return;
    166185        }
    167        
     186
    168187        $payload = array(
    169                 'method' => 'update',
    170                 'type' => 'leads',
    171                 'name' => $this->wp_user->user_firstname.' '.$this->wp_user->user_lastname,
    172                 'last_request_at' => time()
    173             );
    174        
     188            'method' => 'update',
     189            'type' => 'leads',
     190            'name' => $this->wp_user->user_firstname . ' ' . $this->wp_user->user_lastname,
     191            'last_request_at' => time()
     192        );
     193
    175194        $payload = apply_filters('iwp_create_lead', $payload, $this->user_id);
    176        
     195
    177196        $payload = self::add_user_data($payload);
    178        
     197
    179198        $this->schedule_intercom_call($payload);
    180        
    181     }
    182    
    183     public function create_contact() {
    184        
     199
     200    }
     201
     202    public function create_contact()
     203    {
     204
    185205        $payload = array(
    186                 'method' => 'create',
    187                 'type' => 'contacts',
    188                 'name' => $this->wp_user->user_firstname.' '.$this->wp_user->user_lastname,
    189                 'role' => apply_filters('iwp_create_contact_role', 'user', $this->user_id),
    190                 'last_request_at' => time()
    191             );
    192        
     206            'method' => 'create',
     207            'type' => 'contacts',
     208            'name' => $this->wp_user->user_firstname . ' ' . $this->wp_user->user_lastname,
     209            'role' => apply_filters('iwp_create_contact_role', 'user', $this->user_id),
     210            'last_request_at' => time()
     211        );
     212
    193213        $payload = apply_filters('iwp_create_contact', $payload, $this->user_id);
    194        
     214
    195215        $payload = self::add_user_data($payload);
    196        
     216
    197217        $this->schedule_intercom_call($payload);
    198218    }
    199    
    200     public function update_user($update = []) {
    201              
    202         $disabled = isset($this->options['disable_intercom_updates']) ? $this->options['disable_intercom_updates'] : false;
    203        
    204         if($disabled) return;
    205        
     219
     220    public function update_user($update = [])
     221    {
     222
     223        $disabled = isset($this->options['disable_intercom_updates']) ? $this->options['disable_intercom_updates'] : false;
     224
     225        if ($disabled) return;
     226
    206227        $type = apply_filters('iwp_update_type', 'users', $this->user_id);
    207        
     228
    208229        $payload = array(
    209                 'method' => 'update',
    210                 'type' => $type,
    211                 'last_request_at' => time()
     230            'method' => 'update',
     231            'type' => $type,
     232            'last_request_at' => time()
    212233        );
    213        
     234
    214235        $payload = self::add_user_data($payload);
    215        
     236
    216237        $payload = array_merge($payload, $update);
    217        
     238
    218239        $this->schedule_intercom_call($payload);
    219        
    220     }
    221    
    222     public function create_event($event, $metadata = []) {
    223        
    224         $disabled = isset($this->options['disable_events']) ? $this->options['disable_events'] : false;
    225        
    226         if($disabled) return;
    227        
    228         if(self::is_event_permitted($event)) {
    229            
     240
     241    }
     242
     243    public function create_event($event, $metadata = [])
     244    {
     245
     246        $disabled = isset($this->options['disable_events']) ? $this->options['disable_events'] : false;
     247
     248        if ($disabled) return;
     249
     250        if (self::is_event_permitted($event)) {
     251
    230252            $prefix = apply_filters('iwp_event_prefix', 'wp_');
    231            
    232             $event = $prefix.$event;
    233            
     253
     254            $event = $prefix . $event;
     255
    234256            $payload = array(
    235                 'event_name' => $event, 
     257                'event_name' => $event,
    236258                'created_at' => time(),
    237259                'method' => 'create',
    238260                'type' => 'events',
    239261            );
    240            
    241             if(!empty($metadata)) {
    242                
     262
     263            if (!empty($metadata)) {
     264
    243265                $payload['metadata'] = $metadata;
    244266            }
    245            
     267
    246268            $payload = self::add_user_data($payload);
    247            
     269
    248270            $this->schedule_intercom_call($payload);
    249271        }
    250        
    251     }
    252    
    253     public function add_tag($tags) {
    254        
    255         $disabled = isset($this->options['disable_tags']) ? $this->options['disable_tags'] : false;
    256        
    257         if($disabled) return;
    258        
     272
     273    }
     274
     275    public function add_tag($tags)
     276    {
     277
     278        $disabled = isset($this->options['disable_tags']) ? $this->options['disable_tags'] : false;
     279
     280        if ($disabled) return;
     281
    259282        $tags = apply_filters('iwp_add_tag', $tags, $this->user_id);
    260        
    261         if(is_array($tags)) {
    262            
    263             foreach($tags as $tag) {
    264                
     283
     284        if (is_array($tags)) {
     285
     286            foreach ($tags as $tag) {
     287
    265288                $payload = [];
    266289                $payload['name'] = $tag;
    267290                $payload['method'] = 'tag';
    268                 $payload['type'] = 'tags';   
    269                  
     291                $payload['type'] = 'tags';
     292
    270293                $payload['user'][] = self::add_user_data([]);
    271                
     294
    272295                $this->schedule_intercom_call($payload);
    273                
    274             }
    275         }
    276        
    277         else {
    278            
     296
     297            }
     298        } else {
     299
    279300            $payload = [];
    280301            $payload['name'] = $tags;
     
    282303            $payload['type'] = 'tags';
    283304            $payload['user'][] = self::add_user_data([]);
    284            
     305
    285306            $this->schedule_intercom_call($payload);
    286              
    287         }
    288        
    289     }
    290    
    291     private function create_transient_id($payload) {
    292        
    293         return 'iwp_transient_'.sha1(json_encode($payload));
    294     }
    295    
     307
     308        }
     309
     310    }
     311
     312    private function create_transient_id($payload)
     313    {
     314
     315        return 'iwp_transient_' . sha1(json_encode($payload));
     316    }
     317
    296318    //  Add the User ID or Email to Intercom Payload
    297319    //  Can assign by custom User ID or Email
    298320    //  Default is ['email' => 'john.smith@example.com']
    299    
    300     private function add_user_data($payload) {
    301        
     321
     322    private function add_user_data($payload)
     323    {
     324
    302325        $key = apply_filters('iwp_user_identifier_key', 'email', $this->user_id);
    303        
     326
    304327        $value = apply_filters('iwp_user_identifier_value', $this->wp_user->user_email, $this->user_id);
    305        
    306         $payload["".$key.""] = $value;
    307        
     328
     329        $payload["" . $key . ""] = $value;
     330
    308331        $payload = apply_filters('iwp_add_user_data_payload', $payload);
    309        
     332
    310333        return $payload;
    311        
    312     }
    313    
     334
     335    }
     336
    314337    //Allow users to fine tune event tracking
    315    
    316     private function is_event_permitted($event) {
    317        
    318       if(in_array($event, apply_filters( 'iwp_permitted_events', [] ))) {
    319          
    320           return true;
    321       }
    322        
     338
     339    private function is_event_permitted($event)
     340    {
     341
     342        if (in_array($event, apply_filters('iwp_permitted_events', []))) {
     343
     344            return true;
     345        }
     346
    323347        error_log("$event is not permitted!");
    324        
     348
    325349        return false;
    326350    }
    327    
     351
    328352}
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/action-scheduler.php

    r2261884 r2378844  
    66 * Author: Automattic
    77 * Author URI: https://automattic.com/
    8  * Version: 3.1.2
     8 * Version: 3.1.6
    99 * License: GPLv3
    1010 *
     
    2626 */
    2727
    28 if ( ! function_exists( 'action_scheduler_register_3_dot_1_dot_2' ) ) {
     28if ( ! function_exists( 'action_scheduler_register_3_dot_1_dot_6' ) ) {
    2929
    3030    if ( ! class_exists( 'ActionScheduler_Versions' ) ) {
     
    3333    }
    3434
    35     add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_1_dot_2', 0, 0 );
     35    add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_1_dot_6', 0, 0 );
    3636
    37     function action_scheduler_register_3_dot_1_dot_2() {
     37    function action_scheduler_register_3_dot_1_dot_6() {
    3838        $versions = ActionScheduler_Versions::instance();
    39         $versions->register( '3.1.2', 'action_scheduler_initialize_3_dot_1_dot_2' );
     39        $versions->register( '3.1.6', 'action_scheduler_initialize_3_dot_1_dot_6' );
    4040    }
    4141
    42     function action_scheduler_initialize_3_dot_1_dot_2() {
     42    function action_scheduler_initialize_3_dot_1_dot_6() {
    4343        require_once( 'classes/abstracts/ActionScheduler.php' );
    4444        ActionScheduler::init( __FILE__ );
     
    4747    // Support usage in themes - load this version if no plugin has loaded a version yet.
    4848    if ( did_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler' ) ) {
    49         action_scheduler_initialize_3_dot_1_dot_2();
     49        action_scheduler_initialize_3_dot_1_dot_6();
    5050        do_action( 'action_scheduler_pre_theme_init' );
    5151        ActionScheduler_Versions::initialize_latest_version();
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/ActionScheduler_ActionFactory.php

    r2248936 r2378844  
    2323            case ActionScheduler_Store::STATUS_CANCELED :
    2424                $action_class = 'ActionScheduler_CanceledAction';
    25                 if ( ! is_null( $schedule ) && ! is_a( $schedule, 'ActionScheduler_CanceledSchedule' ) ) {
     25                if ( ! is_null( $schedule ) && ! is_a( $schedule, 'ActionScheduler_CanceledSchedule' ) && ! is_a( $schedule, 'ActionScheduler_NullSchedule' ) ) {
    2626                    $schedule = new ActionScheduler_CanceledSchedule( $schedule->get_date() );
    2727                }
     
    6262     * @param string $group A group to put the action in
    6363     *
    64      * @return string The ID of the stored action
     64     * @return int The ID of the stored action
    6565     */
    6666    public function async( $hook, $args = array(), $group = '' ) {
     
    7676     * @param string $group A group to put the action in
    7777     *
    78      * @return string The ID of the stored action
     78     * @return int The ID of the stored action
    7979     */
    8080    public function single( $hook, $args = array(), $when = null, $group = '' ) {
     
    9494     * @param string $group A group to put the action in
    9595     *
    96      * @return string The ID of the stored action
     96     * @return int The ID of the stored action
    9797     */
    9898    public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) {
     
    117117     * @param string $group A group to put the action in
    118118     *
    119      * @return string The ID of the stored action
     119     * @return int The ID of the stored action
    120120     */
    121121    public function cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' ) {
     
    171171     * @param ActionScheduler_Action $action
    172172     *
    173      * @return string The ID of the stored action
     173     * @return int The ID of the stored action
    174174     */
    175175    protected function store( ActionScheduler_Action $action ) {
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/ActionScheduler_AdminView.php

    r2248936 r2378844  
    1010
    1111    private static $screen_id = 'tools_page_action-scheduler';
     12
     13    /** @var ActionScheduler_ListTable */
     14    protected $list_table;
    1215
    1316    /**
     
    8386     */
    8487    public function process_admin_ui() {
    85         $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
    86         $table->process_actions();
     88        $this->get_list_table();
    8789    }
    8890
     
    9193     */
    9294    public function render_admin_ui() {
    93         $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
     95        $table = $this->get_list_table();
    9496        $table->display_page();
     97    }
     98
     99    /**
     100     * Get the admin UI object and process any requested actions.
     101     *
     102     * @return ActionScheduler_ListTable
     103     */
     104    protected function get_list_table() {
     105        if ( null === $this->list_table ) {
     106            $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
     107            $this->list_table->process_actions();
     108        }
     109
     110        return $this->list_table;
    95111    }
    96112
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/ActionScheduler_DataController.php

    r2261884 r2378844  
    102102     */
    103103    public static function set_sleep_time( $sleep_time ) {
    104         self::$sleep_time = $sleep_time;
     104        self::$sleep_time = (int) $sleep_time;
    105105    }
    106106
     
    111111     */
    112112    public static function set_free_ticks( $free_ticks ) {
    113         self::$free_ticks = $free_ticks;
     113        self::$free_ticks = (int) $free_ticks;
    114114    }
    115115
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/ActionScheduler_ListTable.php

    r2248936 r2378844  
    308308     */
    309309    protected function maybe_render_actions( $row, $column_name ) {
    310         if ( 'pending' === strtolower( $row['status'] ) ) {
     310        if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) {
    311311            return parent::maybe_render_actions( $row, $column_name );
    312312        }
     
    319319     *
    320320     * Notifications:
    321      *  1. When the maximum number of tasks are being executed simultaneously
    322      *  2. Notifications when a task is manually executed
     321     *  1. When the maximum number of tasks are being executed simultaneously.
     322     *  2. Notifications when a task is manually executed.
     323     *  3. Tables are missing.
    323324     */
    324325    public function display_admin_notices() {
     326        global $wpdb;
     327
     328        if ( ( is_a( $this->store, 'ActionScheduler_HybridStore' ) || is_a( $this->store, 'ActionScheduler_DBStore' ) ) && apply_filters( 'action_scheduler_enable_recreate_data_store', true ) ) {
     329            $table_list = array(
     330                'actionscheduler_actions',
     331                'actionscheduler_logs',
     332                'actionscheduler_groups',
     333                'actionscheduler_claims',
     334            );
     335
     336            $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
     337            foreach ( $table_list as $table_name ) {
     338                if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) {
     339                    $this->admin_notices[] = array(
     340                        'class'   => 'error',
     341                        'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'action-scheduler' ),
     342                    );
     343                    $this->recreate_tables();
     344                    parent::display_admin_notices();
     345
     346                    return;
     347                }
     348            }
     349        }
     350
    325351        if ( $this->runner->has_maximum_concurrent_batches() ) {
    326352            $claim_count           = $this->store->get_claim_count();
     
    475501
    476502    /**
     503     * Force the data store schema updates.
     504     */
     505    protected function recreate_tables() {
     506        if ( is_a( $this->store, 'ActionScheduler_HybridStore' ) ) {
     507            $store = $this->store;
     508        } else {
     509            $store = new ActionScheduler_HybridStore();
     510        }
     511        add_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10, 2 );
     512
     513        $store_schema  = new ActionScheduler_StoreSchema();
     514        $logger_schema = new ActionScheduler_LoggerSchema();
     515        $store_schema->register_tables( true );
     516        $logger_schema->register_tables( true );
     517
     518        remove_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10 );
     519    }
     520    /**
    477521     * Implements the logic behind processing an action once an action link is clicked on the list table.
    478522     *
     
    528572                continue;
    529573            }
     574            if ( is_a( $action, 'ActionScheduler_NullAction' ) ) {
     575                continue;
     576            }
    530577            $this->items[ $action_id ] = array(
    531578                'ID'          => $action_id,
    532579                'hook'        => $action->get_hook(),
     580                'status_name' => $this->store->get_status( $action_id ),
    533581                'status'      => $status_labels[ $this->store->get_status( $action_id ) ],
    534582                'args'        => $action->get_args(),
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/ActionScheduler_QueueRunner.php

    r2248936 r2378844  
    5151        add_filter( 'cron_schedules', array( self::instance(), 'add_wp_cron_schedule' ) );
    5252
     53        // Check for and remove any WP Cron hook scheduled by Action Scheduler < 3.0.0, which didn't include the $context param
     54        $next_timestamp = wp_next_scheduled( self::WP_CRON_HOOK );
     55        if ( $next_timestamp ) {
     56            wp_unschedule_event( $next_timestamp, self::WP_CRON_HOOK );
     57        }
     58
    5359        $cron_context = array( 'WP Cron' );
    5460
    5561        if ( ! wp_next_scheduled( self::WP_CRON_HOOK, $cron_context ) ) {
    56 
    57             // Check for and remove any WP Cron hook scheduled by Action Scheduler < 3.0.0, which didn't include the $context param
    58             $next_timestamp = wp_next_scheduled( self::WP_CRON_HOOK );
    59             if ( $next_timestamp ) {
    60                 wp_unschedule_event( $next_timestamp, self::WP_CRON_HOOK );
    61             }
    62 
    6362            $schedule = apply_filters( 'action_scheduler_run_schedule', self::WP_CRON_SCHEDULE );
    6463            wp_schedule_event( time(), $schedule, self::WP_CRON_HOOK, $cron_context );
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php

    r2248936 r2378844  
    4949        $hooks   = array_filter( array_map( 'trim', $hooks ) );
    5050        $group   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' );
    51         $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', '' );
    52         $sleep   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', '' );
     51        $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', 50 );
     52        $sleep   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', 0 );
    5353        $force   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );
    5454
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/abstracts/ActionScheduler.php

    r2261884 r2378844  
    1212    /** @var ActionScheduler_ActionFactory */
    1313    private static $factory = NULL;
     14    /** @var bool */
     15    private static $data_store_initialized = false;
    1416
    1517    public static function factory() {
     
    138140        do_action( 'action_scheduler_pre_init' );
    139141
    140         require_once( self::plugin_path('functions.php') );
     142        require_once( self::plugin_path( 'functions.php' ) );
    141143        ActionScheduler_DataController::init();
    142144
    143         $store = self::store();
    144         add_action( 'init', array( $store, 'init' ), 1, 0 );
    145 
    146         $logger = self::logger();
    147         add_action( 'init', array( $logger, 'init' ), 1, 0 );
    148 
    149         $runner = self::runner();
    150         add_action( 'init', array( $runner, 'init' ), 1, 0 );
    151 
     145        $store      = self::store();
     146        $logger     = self::logger();
     147        $runner     = self::runner();
    152148        $admin_view = self::admin_view();
    153         add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init()
    154149
    155150        // Ensure initialization on plugin activation.
    156         if ( did_action( 'init' ) ) {
     151        if ( ! did_action( 'init' ) ) {
     152            add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init()
     153            add_action( 'init', array( $store, 'init' ), 1, 0 );
     154            add_action( 'init', array( $logger, 'init' ), 1, 0 );
     155            add_action( 'init', array( $runner, 'init' ), 1, 0 );
     156        } else {
     157            $admin_view->init();
    157158            $store->init();
    158159            $logger->init();
    159160            $runner->init();
    160             $admin_view->init();
    161161        }
    162162
    163163        if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) {
    164             require_once( self::plugin_path('deprecated/functions.php') );
     164            require_once( self::plugin_path( 'deprecated/functions.php' ) );
    165165        }
    166166
     
    173173        }
    174174
     175        self::$data_store_initialized = true;
     176
    175177        /**
    176178         * Handle WP comment cleanup after migration.
     
    181183
    182184        add_action( 'action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup' );
     185    }
     186
     187    /**
     188     * Check whether the AS data store has been initialized.
     189     *
     190     * @param string $function_name The name of the function being called. Optional. Default `null`.
     191     * @return bool
     192     */
     193    public static function is_initialized( $function_name = null ) {
     194        if ( ! self::$data_store_initialized && ! empty( $function_name ) ) {
     195            $message = sprintf( __( '%s() was called before the Action Scheduler data store was initialized', 'action-scheduler' ), esc_attr( $function_name ) );
     196            error_log( $message, E_WARNING );
     197        }
     198
     199        return self::$data_store_initialized;
    183200    }
    184201
     
    275292        return as_get_datetime_object( $when, $timezone );
    276293    }
     294
     295    /**
     296     * Issue deprecated warning if an Action Scheduler function is called in the shutdown hook.
     297     *
     298     * @param string $function_name The name of the function being called.
     299     * @deprecated 3.1.6.
     300     */
     301    public static function check_shutdown_hook( $function_name ) {
     302        _deprecated_function( __FUNCTION__, '3.1.6' );
     303    }
    277304}
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php

    r2248936 r2378844  
    141141        // Detect when a bulk action is being triggered.
    142142        $action = $this->current_action();
    143 
    144143        if ( ! $action ) {
    145144            return;
     
    162161
    163162    /**
    164      * Default code for deleting entries. We trust ids_sql because it is
     163     * Default code for deleting entries.
    165164     * validated already by process_bulk_action()
    166165     */
    167166    protected function bulk_delete( array $ids, $ids_sql ) {
    168         global $wpdb;
    169 
    170         $wpdb->query( "DELETE FROM {$this->table_name} WHERE {$this->ID} IN $ids_sql" );
     167        $store = ActionScheduler::store();
     168        foreach ( $ids as $action_id ) {
     169            $store->delete( $action_id );
     170        }
    171171    }
    172172
     
    643643    public function process_actions() {
    644644        $this->process_bulk_action();
    645 
    646645        $this->process_row_actions();
    647646
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php

    r2248936 r2378844  
    2626     * Register tables with WordPress, and create them if needed.
    2727     *
     28     * @param bool $force_update Optional. Default false. Use true to always run the schema update.
     29     *
    2830     * @return void
    2931     */
    30     public function register_tables() {
     32    public function register_tables( $force_update = false ) {
    3133        global $wpdb;
    3234
     
    3941
    4042        // create the tables
    41         if ( $this->schema_update_required() ) {
     43        if ( $this->schema_update_required() || $force_update ) {
    4244            foreach ( $this->tables as $table ) {
    4345                $this->update_table( $table );
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/abstracts/ActionScheduler_Logger.php

    r2248936 r2378844  
    131131            $message = __( 'action ignored', 'action-scheduler' );
    132132        }
    133         $this->log( $action_id, __( 'action ignored', 'action-scheduler' ) );
     133        $this->log( $action_id, $message );
    134134    }
    135135
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/abstracts/ActionScheduler_Store.php

    r2248936 r2378844  
    2525     *        schedule.
    2626     *
    27      * @return string The action ID
     27     * @return int The action ID
    2828     */
    2929    abstract public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL );
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php

    r2248936 r2378844  
    5757            }
    5858
    59             $wpdb->insert( $wpdb->actionscheduler_actions, $data );
     59            $table_name = ! empty( $wpdb->actionscheduler_actions ) ? $wpdb->actionscheduler_actions : $wpdb->prefix . 'actionscheduler_actions';
     60            $wpdb->insert( $table_name, $data );
    6061            $action_id = $wpdb->insert_id;
    6162
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php

    r2248936 r2378844  
    7878            /** @var \wpdb $wpdb */
    7979            global $wpdb;
    80             $wpdb->insert(
     80            /**
     81             * A default date of '0000-00-00 00:00:00' is invalid in MySQL 5.7 when configured with
     82             * sql_mode including both STRICT_TRANS_TABLES and NO_ZERO_DATE.
     83             */
     84            $default_date = new DateTime( 'tomorrow' );
     85            $null_action  = new ActionScheduler_NullAction();
     86            $date_gmt     = $this->get_scheduled_date_string( $null_action, $default_date );
     87            $date_local   = $this->get_scheduled_date_string_local( $null_action, $default_date );
     88
     89            $row_count = $wpdb->insert(
    8190                $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
    8291                [
    83                     'action_id' => $this->demarkation_id,
    84                     'hook'      => '',
    85                     'status'    => '',
     92                    'action_id'            => $this->demarkation_id,
     93                    'hook'                 => '',
     94                    'status'               => '',
     95                    'scheduled_date_gmt'   => $date_gmt,
     96                    'scheduled_date_local' => $date_local,
     97                    'last_attempt_gmt'     => $date_gmt,
     98                    'last_attempt_local'   => $date_local,
    8699                ]
    87100            );
    88             $wpdb->delete(
    89                 $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
    90                 [ 'action_id' => $this->demarkation_id ]
    91             );
     101            if ( $row_count > 0 ) {
     102                $wpdb->delete(
     103                    $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
     104                    [ 'action_id' => $this->demarkation_id ]
     105                );
     106            }
    92107        }
    93108    }
     
    221236     * @param ActionScheduler_Action $action Action object to be saved.
    222237     * @param DateTime               $date Optional. Schedule date. Default null.
     238     *
     239     * @return int The action ID
    223240     */
    224241    public function save_action( ActionScheduler_Action $action, DateTime $date = null ) {
     
    232249     */
    233250    public function fetch_action( $action_id ) {
    234         if ( $action_id < $this->demarkation_id ) {
    235             return $this->secondary_store->fetch_action( $action_id );
     251        $store = $this->get_store_from_action_id( $action_id, true );
     252        if ( $store ) {
     253            return $store->fetch_action( $action_id );
    236254        } else {
    237             return $this->primary_store->fetch_action( $action_id );
     255            return new ActionScheduler_NullAction();
    238256        }
    239257    }
     
    245263     */
    246264    public function cancel_action( $action_id ) {
    247         if ( $action_id < $this->demarkation_id ) {
    248             $this->secondary_store->cancel_action( $action_id );
     265        $store = $this->get_store_from_action_id( $action_id );
     266        if ( $store ) {
     267            $store->cancel_action( $action_id );
     268        }
     269    }
     270
     271    /**
     272     * Delete an existing action whether migrated or not.
     273     *
     274     * @param int $action_id Action ID.
     275     */
     276    public function delete_action( $action_id ) {
     277        $store = $this->get_store_from_action_id( $action_id );
     278        if ( $store ) {
     279            $store->delete_action( $action_id );
     280        }
     281    }
     282
     283    /**
     284     * Get the schedule date an existing action whether migrated or not.
     285     *
     286     * @param int $action_id Action ID.
     287     */
     288    public function get_date( $action_id ) {
     289        $store = $this->get_store_from_action_id( $action_id );
     290        if ( $store ) {
     291            return $store->get_date( $action_id );
    249292        } else {
    250             $this->primary_store->cancel_action( $action_id );
    251         }
    252     }
    253 
    254     /**
    255      * Delete an existing action whether migrated or not.
    256      *
    257      * @param int $action_id Action ID.
    258      */
    259     public function delete_action( $action_id ) {
    260         if ( $action_id < $this->demarkation_id ) {
    261             $this->secondary_store->delete_action( $action_id );
     293            return null;
     294        }
     295    }
     296
     297    /**
     298     * Mark an existing action as failed whether migrated or not.
     299     *
     300     * @param int $action_id Action ID.
     301     */
     302    public function mark_failure( $action_id ) {
     303        $store = $this->get_store_from_action_id( $action_id );
     304        if ( $store ) {
     305            $store->mark_failure( $action_id );
     306        }
     307    }
     308
     309    /**
     310     * Log the execution of an existing action whether migrated or not.
     311     *
     312     * @param int $action_id Action ID.
     313     */
     314    public function log_execution( $action_id ) {
     315        $store = $this->get_store_from_action_id( $action_id );
     316        if ( $store ) {
     317            $store->log_execution( $action_id );
     318        }
     319    }
     320
     321    /**
     322     * Mark an existing action complete whether migrated or not.
     323     *
     324     * @param int $action_id Action ID.
     325     */
     326    public function mark_complete( $action_id ) {
     327        $store = $this->get_store_from_action_id( $action_id );
     328        if ( $store ) {
     329            $store->mark_complete( $action_id );
     330        }
     331    }
     332
     333    /**
     334     * Get an existing action status whether migrated or not.
     335     *
     336     * @param int $action_id Action ID.
     337     */
     338    public function get_status( $action_id ) {
     339        $store = $this->get_store_from_action_id( $action_id );
     340        if ( $store ) {
     341            return $store->get_status( $action_id );
     342        }
     343        return null;
     344    }
     345
     346    /**
     347     * Return which store an action is stored in.
     348     *
     349     * @param int  $action_id ID of the action.
     350     * @param bool $primary_first Optional flag indicating search the primary store first.
     351     * @return ActionScheduler_Store
     352     */
     353    protected function get_store_from_action_id( $action_id, $primary_first = false ) {
     354        if ( $primary_first ) {
     355            $stores = [
     356                $this->primary_store,
     357                $this->secondary_store,
     358            ];
     359        } elseif ( $action_id < $this->demarkation_id ) {
     360            $stores = [
     361                $this->secondary_store,
     362                $this->primary_store,
     363            ];
    262364        } else {
    263             $this->primary_store->delete_action( $action_id );
    264         }
    265     }
    266 
    267     /**
    268      * Get the schedule date an existing action whether migrated or not.
    269      *
    270      * @param int $action_id Action ID.
    271      */
    272     public function get_date( $action_id ) {
    273         if ( $action_id < $this->demarkation_id ) {
    274             return $this->secondary_store->get_date( $action_id );
    275         } else {
    276             return $this->primary_store->get_date( $action_id );
    277         }
    278     }
    279 
    280     /**
    281      * Mark an existing action as failed whether migrated or not.
    282      *
    283      * @param int $action_id Action ID.
    284      */
    285     public function mark_failure( $action_id ) {
    286         if ( $action_id < $this->demarkation_id ) {
    287             $this->secondary_store->mark_failure( $action_id );
    288         } else {
    289             $this->primary_store->mark_failure( $action_id );
    290         }
    291     }
    292 
    293     /**
    294      * Log the execution of an existing action whether migrated or not.
    295      *
    296      * @param int $action_id Action ID.
    297      */
    298     public function log_execution( $action_id ) {
    299         if ( $action_id < $this->demarkation_id ) {
    300             $this->secondary_store->log_execution( $action_id );
    301         } else {
    302             $this->primary_store->log_execution( $action_id );
    303         }
    304     }
    305 
    306     /**
    307      * Mark an existing action complete whether migrated or not.
    308      *
    309      * @param int $action_id Action ID.
    310      */
    311     public function mark_complete( $action_id ) {
    312         if ( $action_id < $this->demarkation_id ) {
    313             $this->secondary_store->mark_complete( $action_id );
    314         } else {
    315             $this->primary_store->mark_complete( $action_id );
    316         }
    317     }
    318 
    319     /**
    320      * Get an existing action status whether migrated or not.
    321      *
    322      * @param int $action_id Action ID.
    323      */
    324     public function get_status( $action_id ) {
    325         if ( $action_id < $this->demarkation_id ) {
    326             return $this->secondary_store->get_status( $action_id );
    327         } else {
    328             return $this->primary_store->get_status( $action_id );
    329         }
    330     }
    331 
     365            $stores = [
     366                $this->primary_store,
     367            ];
     368        }
     369
     370        foreach ( $stores as $store ) {
     371            $action = $store->fetch_action( $action_id );
     372            if ( ! is_a( $action, 'ActionScheduler_NullAction' ) ) {
     373                return $store;
     374            }
     375        }
     376        return null;
     377    }
    332378
    333379    /* * * * * * * * * * * * * * * * * * * * * * * * * * *
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/migration/Controller.php

    r2248936 r2378844  
    150150        add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 );
    151151        add_action( 'init', array( $this, 'maybe_hook_migration' ) );
    152         add_action( 'shutdown', array( $this, 'schedule_migration' ), 0, 0 );
     152        add_action( 'wp_loaded', array( $this, 'schedule_migration' ) );
    153153
    154154        // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/classes/migration/Scheduler.php

    r2248936 r2378844  
    8484
    8585        if ( empty( $when ) ) {
    86             $when = time();
     86            $when = time() + MINUTE_IN_SECONDS;
    8787        }
    8888
  • highways-sync-for-intercom/trunk/includes/lib/action-scheduler/functions.php

    r2248936 r2378844  
    1111 * @param array  $args Arguments to pass when the hook triggers.
    1212 * @param string $group The group to assign this job to.
    13  * @return string The action ID.
     13 * @return int The action ID.
    1414 */
    1515function as_enqueue_async_action( $hook, $args = array(), $group = '' ) {
     16    if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
     17        return 0;
     18    }
    1619    return ActionScheduler::factory()->async( $hook, $args, $group );
    1720}
     
    2023 * Schedule an action to run one time
    2124 *
    22  * @param int $timestamp When the job will run
    23  * @param string $hook The hook to trigger
    24  * @param array $args Arguments to pass when the hook triggers
    25  * @param string $group The group to assign this job to
    26  *
    27  * @return string The job ID
     25 * @param int $timestamp When the job will run.
     26 * @param string $hook The hook to trigger.
     27 * @param array $args Arguments to pass when the hook triggers.
     28 * @param string $group The group to assign this job to.
     29 *
     30 * @return int The action ID.
    2831 */
    2932function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) {
     33    if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
     34        return 0;
     35    }
    3036    return ActionScheduler::factory()->single( $hook, $args, $timestamp, $group );
    3137}
     
    3440 * Schedule a recurring action
    3541 *
    36  * @param int $timestamp When the first instance of the job will run
    37  * @param int $interval_in_seconds How long to wait between runs
    38  * @param string $hook The hook to trigger
    39  * @param array $args Arguments to pass when the hook triggers
    40  * @param string $group The group to assign this job to
    41  *
    42  * @return string The job ID
     42 * @param int $timestamp When the first instance of the job will run.
     43 * @param int $interval_in_seconds How long to wait between runs.
     44 * @param string $hook The hook to trigger.
     45 * @param array $args Arguments to pass when the hook triggers.
     46 * @param string $group The group to assign this job to.
     47 *
     48 * @return int The action ID.
    4349 */
    4450function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) {
     51    if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
     52        return 0;
     53    }
    4554    return ActionScheduler::factory()->recurring( $hook, $args, $timestamp, $interval_in_seconds, $group );
    4655}
     
    6372 *   |    +-------------------- hour (0 - 23)
    6473 *   +------------------------- min (0 - 59)
    65  * @param string $hook The hook to trigger
    66  * @param array $args Arguments to pass when the hook triggers
    67  * @param string $group The group to assign this job to
    68  *
    69  * @return string The job ID
     74 * @param string $hook The hook to trigger.
     75 * @param array $args Arguments to pass when the hook triggers.
     76 * @param string $group The group to assign this job to.
     77 *
     78 * @return int The action ID.
    7079 */
    7180function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) {
     81    if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
     82        return 0;
     83    }
    7284    return ActionScheduler::factory()->cron( $hook, $args, $timestamp, $schedule, $group );
    7385}
     
    8395 * by this method also.
    8496 *
    85  * @param string $hook The hook that the job will trigger
    86  * @param array $args Args that would have been passed to the job
    87  * @param string $group
    88  *
    89  * @return string The scheduled action ID if a scheduled action was found, or empty string if no matching action found.
     97 * @param string $hook The hook that the job will trigger.
     98 * @param array $args Args that would have been passed to the job.
     99 * @param string $group The group the job is assigned to.
     100 *
     101 * @return string|null The scheduled action ID if a scheduled action was found, or null if no matching action found.
    90102 */
    91103function as_unschedule_action( $hook, $args = array(), $group = '' ) {
     104    if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
     105        return 0;
     106    }
    92107    $params = array();
    93108    if ( is_array($args) ) {
     
    109124 * Cancel all occurrences of a scheduled action.
    110125 *
    111  * @param string $hook The hook that the job will trigger
    112  * @param array $args Args that would have been passed to the job
    113  * @param string $group
     126 * @param string $hook The hook that the job will trigger.
     127 * @param array $args Args that would have been passed to the job.
     128 * @param string $group The group the job is assigned to.
    114129 */
    115130function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) {
     131    if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
     132        return;
     133    }
    116134    if ( empty( $args ) ) {
    117135        if ( ! empty( $hook ) && empty( $group ) ) {
     
    132150 * Check if there is an existing action in the queue with a given hook, args and group combination.
    133151 *
    134  * An action in the queue could be pending, in-progress or aysnc. If the is pending for a time in
     152 * An action in the queue could be pending, in-progress or async. If the is pending for a time in
    135153 * future, its scheduled date will be returned as a timestamp. If it is currently being run, or an
    136154 * async action sitting in the queue waiting to be processed, in which case boolean true will be
     
    145163 */
    146164function as_next_scheduled_action( $hook, $args = NULL, $group = '' ) {
     165    if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
     166        return false;
     167    }
    147168    $params = array();
    148169    if ( is_array($args) ) {
     
    192213 *        'order' => 'ASC'
    193214 *
    194  * @param string $return_format OBJECT, ARRAY_A, or ids
     215 * @param string $return_format OBJECT, ARRAY_A, or ids.
    195216 *
    196217 * @return array
    197218 */
    198219function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) {
     220    if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
     221        return array();
     222    }
    199223    $store = ActionScheduler::store();
    200224    foreach ( array('date', 'modified') as $key ) {
     
    235259 * the PHP default.
    236260 *
    237  * @param mixed $date_string A date/time string. Valid formats are explained in http://php.net/manual/en/datetime.formats.php
    238  * @param string $timezone A timezone identifier, like UTC or Europe/Lisbon. The list of valid identifiers is available http://php.net/manual/en/timezones.php
     261 * @param mixed $date_string A date/time string. Valid formats are explained in http://php.net/manual/en/datetime.formats.php.
     262 * @param string $timezone A timezone identifier, like UTC or Europe/Lisbon. The list of valid identifiers is available http://php.net/manual/en/timezones.php.
    239263 *
    240264 * @return ActionScheduler_DateTime
  • highways-sync-for-intercom/trunk/readme.txt

    r2285958 r2378844  
    9696== Changelog ==
    9797
     98= 1.0.6 =
     99* Added: Updated Action Scheduler to 3.1.6
     100* Added: Logging to WooCommerce Logs (If installed and available)
     101
    98102= 1.0.5 =
    99103* FIX: Bug Fix for Chat Bubble (Logged Out Users)
Note: See TracChangeset for help on using the changeset viewer.