public function process($num = 50) { $select = $this->util->select(); $selected_users = array_chunk($select, $num, true); foreach ((array) $selected_users[0] as $wp_id => $script_info) { $args = array('primary_field' => 'wp_id', 'primary_field_data' => $wp_id); try { if ($rave_user = \PSU\Rave\User::create($wp_id)) { $this->util->delete($args); } else { $this->util->set_flag($args, 'createfail'); } //end else } catch (\Exception $e) { $this->util->set_flag($args, 'createfail'); } //end catch if ($this->debug) { echo ($rave_user ? 'Created: ' : 'Failed to create: ') . $wp_id . "\n"; } //end if } //end foreach return count($this->util->select()); }
public function process($num = 50) { $select = $this->util->select(); $selected_users = array_chunk($select, $num, true); foreach ((array) $selected_users[0] as $wp_id => $script_info) { $args = array('primary_field' => 'wp_id', 'primary_field_data' => $wp_id); if ($rave_user = \PSU\Rave\User::get($wp_id)) { //If the user exists in Rave, but has no phone numbers, lets add their Banner mobile number unconfirmed if ($rave_user->phones()->count() === 0) { $phone_args = array('wp_id' => $wp_id, 'phone' => $script_info['mobile_number']); $phone = new \PSU\Rave\Phone($phone_args); $phone->save('no_confirm'); try { if ($rave_user->save()) { $this->util->delete($args); } else { $this->util->set_flag($args, 'savefail'); } //end else } catch (\Exception $e) { $this->util->set_flag($args, 'savefail'); } //end catch } //end if } else { try { $rave_user = \PSU\Rave\User::create($wp_id); $phone_args = array('wp_id' => $wp_id, 'phone' => $script_info['mobile_number']); $phone = new \PSU\Rave\Phone($phone_args); $phone->save('no_confirm'); try { if ($rave_user->save()) { $this->util->delete($args); } else { $this->util->set_flag($args, 'savefail'); } //end else } catch (\Exception $e) { $this->util->set_flag($args, 'savefail'); } //end catch } catch (\Exception $e) { $this->util->set_flag($args, 'createfail'); } //end catch if ($this->debug) { echo ($rave_user ? 'Created: ' : 'Failed to create: ') . $wp_id . "\n"; } //end if } // end else } //end foreach return count($this->util->select()); }
/** * save the number in Rave * * @param $phone \b phone number * @param $option \b the type of Rave manipulation that is being done: (false, opt_out, deferred, resend) */ protected function _rave_save($phone, $option = false) { $user = \PSU\Rave\User::get($this->wp_id); if (!$user) { if (!($user = \PSU\Rave\User::create($this->wp_id))) { throw new UnexpectedValueException('Could not load user information for ' . $this->wp_id); } //end if } // end if if (!$phone || $option == 'deferred' || $option == 'opted_out') { unset($user->mobileNumber1); $confirm = false; } else { $user->rave_set_phone($phone); $confirm = $option != 'no_confirm'; } return $user->save($confirm); }