Sfoglia il codice sorgente

command line sync now support bypass, minimum interval 600 seconds

master
patrick 6 anni fa
parent
commit
c5ce7e32fb
2 ha cambiato i file con 12 aggiunte e 5 eliminazioni
  1. +7
    -5
      Xero.php
  2. +5
    -0
      ts.php

+ 7
- 5
Xero.php Vedi File

//does not work for too many users or employees //does not work for too many users or employees
public function sync_users(){ public function sync_users(){
$this->sync_clients(); $this->sync_clients();
//$this->sync_employees();
$this->sync_employees();
} }
private function sync_clients(){ private function sync_clients(){
$contacts = $this->getClients($this->clientgroup); $contacts = $this->getClients($this->clientgroup);
private function ensure_staff_exists($employee) private function ensure_staff_exists($employee)
{ {
$login = $employee->getEmployeeID(); $login = $employee->getEmployeeID();
$xero_employee = $this->getEmployee($login);
$args = $this->xero_employee_profile($xero_employee);
$user = get_user_by('login', $login); $user = get_user_by('login', $login);
if ($user === false){ if ($user === false){
$xero_employee = $this->getEmployee($login);
$args = $this->xero_employee_profile($xero_employee);
$id = wp_insert_user($args); $id = wp_insert_user($args);
$user = get_user_by('ID', $id); $user = get_user_by('ID', $id);
}else{ }else{
if ($this->is_too_close_to_sync($user)){ if ($this->is_too_close_to_sync($user)){
return; return;
} }
$xero_employee = $this->getEmployee($login);
$args = $this->xero_employee_profile($xero_employee);
$args['ID'] = $user->ID; $args['ID'] = $user->ID;
unset($args['user_pass']); unset($args['user_pass']);
wp_update_user($args); wp_update_user($args);
$lastsync = $this->get_last_sync($user->ID); $lastsync = $this->get_last_sync($user->ID);
$now = time(); $now = time();
$diff = $now - (int) $lastsync; $diff = $now - (int) $lastsync;
echo "lastsync = $lastsync, now = $now , diff = $diff; \n" ;
if ($diff < $this->minimum_sync_interval_in_seconds){ 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); $this->logConsole($msg);
return true; return true;
} }

+ 5
- 0
ts.php Vedi File

wp_enqueue_script( 'bts_ts', plugins_url('js/bts_timesheet.js', __FILE__), array( 'jquery' , 'bts' )); 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()){ public function sync_user_cli($args = array(), $assoc_args = array()){
$this->cli = true; $this->cli = true;
echo "running sync user from command line;\n"; echo "running sync user from command line;\n";

Loading…
Annulla
Salva