From 65209b0401af04f77d762c34823817f6b463d255 Mon Sep 17 00:00:00 2001
From: sp
Date: Thu, 9 Jun 2022 00:23:19 +1000
Subject: [PATCH] bugfix for xero refresh token when things goes wrong, email
is sent to patrick for manual operation.
---
.idea/php.xml | 4 +-
XeroOauth2.php | 162 ++++++++--------
XeroOauth2ShortCode.php | 134 ++++++++------
XeroOauth2Sync.php | 398 ++++++++++++++++++++++++++++++++++++++++
js/bts_timesheet.js | 2 +-
js/xeroc.js | 2 +-
ts.php | 71 ++++---
7 files changed, 611 insertions(+), 162 deletions(-)
create mode 100644 XeroOauth2Sync.php
diff --git a/.idea/php.xml b/.idea/php.xml
index 329d0f0..d3e0cec 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -27,7 +27,9 @@
-
+
+
+
diff --git a/XeroOauth2.php b/XeroOauth2.php
index 1ee308c..c0619ca 100644
--- a/XeroOauth2.php
+++ b/XeroOauth2.php
@@ -2,7 +2,7 @@
/* xero integration oauth 2 */
-/* required by XeroOauth1 in 2021 */
+/* required by XeroOauth2 in 2021 */
namespace Biukop;
require_once(dirname(__FILE__) . '/vendor/autoload.php');
@@ -20,7 +20,8 @@ class XeroOAuth2
private $clientID = '83CC79EEC6A54B4E8C2CA7AD61D1BF69';
private $clientSecret = 'axgKF-Ri60D89conDFhqZsi1wu7uLdQFGvMpino9nI-nfO3f';
- private $clientContactGroupID="48646f3d-cf5e-4fea-8c8b-5812bd540e1b";
+
+ private $minimum_sync_interval_in_seconds = 600;
public $provider;
public $options = [
@@ -34,11 +35,13 @@ class XeroOAuth2
public $xeroTenantId;
private $shortcodes;
+ private $sync;
public function __construct($office)
{
$this->office = $office;
$this->shortcodes = new XeroOauth2ShortCode($this);
+ $this->sync = new XeroOauth2Sync($this);
$this->storage = new StorageClass();
add_action('init', array($this, 'init'));
@@ -51,18 +54,19 @@ class XeroOAuth2
}
public function __call($method, $args) {
- if ( method_exists($this->XeroOauth1, $method) ) {
- syslog(LOG_INFO,"Calling $method");
- $this->XeroOauth1->$method($args);
- } else {
- error_log("$method is not defined" );
- }
+ error_log("$method is not defined" );
+ }
+
+ public function sync_users($mininterval, $employeeonly, $clientsonly) {
+ $this->sync->sync_users($mininterval, $employeeonly, $clientsonly);
}
public function init()
{
$this->provider = $this->create_provider();
- $this->init_wp();
+ if ($this->refresh_token() && is_user_logged_in()) {
+ $this->instant_sync();
+ }
}
public function getTenantId() {
@@ -122,7 +126,7 @@ class XeroOAuth2
Field::make('html', 'crb_information_text')
->set_html('Connect/Reconnect
if the above field is empty,
- or the expire date looks suspicous, please reconnect to XeroOauth1
+ or the expire date looks suspicous, please reconnect to XeroOauth2