From c5ce7e32fb32436df569832656b62b598136d0b8 Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 30 Jun 2019 22:27:39 +1000 Subject: [PATCH] command line sync now support bypass, minimum interval 600 seconds --- Xero.php | 12 +++++++----- ts.php | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Xero.php b/Xero.php index b4181e2..56f3aa2 100644 --- a/Xero.php +++ b/Xero.php @@ -71,7 +71,7 @@ class Xero { //does not work for too many users or employees public function sync_users(){ $this->sync_clients(); - //$this->sync_employees(); + $this->sync_employees(); } private function sync_clients(){ $contacts = $this->getClients($this->clientgroup); @@ -130,16 +130,18 @@ class Xero { private function ensure_staff_exists($employee) { $login = $employee->getEmployeeID(); - $xero_employee = $this->getEmployee($login); - $args = $this->xero_employee_profile($xero_employee); $user = get_user_by('login', $login); if ($user === false){ + $xero_employee = $this->getEmployee($login); + $args = $this->xero_employee_profile($xero_employee); $id = wp_insert_user($args); $user = get_user_by('ID', $id); }else{ if ($this->is_too_close_to_sync($user)){ return; } + $xero_employee = $this->getEmployee($login); + $args = $this->xero_employee_profile($xero_employee); $args['ID'] = $user->ID; unset($args['user_pass']); wp_update_user($args); @@ -175,9 +177,9 @@ class Xero { $lastsync = $this->get_last_sync($user->ID); $now = time(); $diff = $now - (int) $lastsync; - echo "lastsync = $lastsync, now = $now , diff = $diff; \n" ; if ($diff < $this->minimum_sync_interval_in_seconds){ - $msg = sprintf("SKIP sync user %d, login=%s, display_name=%s\n", $user->ID, $user->user_login, $user->display_name); + $msg = sprintf("\tSKIP userid(%d),login=%s,display_name=%s,(lastsync=%d secs ago, mininterval=%d) \n", + $user->ID, $user->user_login, $user->display_name, $diff, $this->minimum_sync_interval_in_seconds); $this->logConsole($msg); return true; } diff --git a/ts.php b/ts.php index 8f6c122..99f3b91 100644 --- a/ts.php +++ b/ts.php @@ -91,6 +91,11 @@ class AcareOffice{ wp_enqueue_script( 'bts_ts', plugins_url('js/bts_timesheet.js', __FILE__), array( 'jquery' , 'bts' )); } + public function sync_users() + { + $a=1; + return; + } public function sync_user_cli($args = array(), $assoc_args = array()){ $this->cli = true; echo "running sync user from command line;\n";