Skip to content

Commit

Permalink
Simplify/cleanup device initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Nov 17, 2013
1 parent 9a949e6 commit 6504571
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 36 deletions.
48 changes: 26 additions & 22 deletions framework/ActiveSync/lib/Horde/ActiveSync.php
Expand Up @@ -766,10 +766,9 @@ public function handleRequest($cmd, $devId)
$this->_device->rwstatus = self::RWSTATUS_NA;
$this->_device->user = $this->_driver->getUser();
$this->_device->id = $devId;
$this->_device->version = $version;
$this->_device->needsVersionUpdate($this->getSupportedVersions());

// @TODO: Remove is_callable check (and extra else clause) for H6.
// @TODO: Remove is_callable check for H6.
// Combine this with the modifyDevice callback? Allow $device
// to be modified here?
if (is_callable(array($this->_driver, 'createDeviceCallback'))) {
Expand All @@ -790,17 +789,22 @@ public function handleRequest($cmd, $devId)
if (is_callable(array($this->_driver, 'modifyDeviceCallback'))) {
$this->_device = $this->_driver->modifyDeviceCallback($this->_device);
}
$this->_device->save();
}
} else {
$this->_device->save();
}
} else {
$this->_device = $this->_state->loadDeviceInfo($devId, $this->_driver->getUser());
$this->_device->version = $version;

// If the device state was removed from storage, we may lose the
// device properties, so try to repopulate what we can. userAgent
// is ALWAYS available, so if it's missing, the state is gone.
if (empty($this->_device->userAgent)) {
$this->_device->userAgent = $this->_request->getHeader('User-Agent');
$this->_device->deviceType = !empty($get['DeviceType']) ? $get['DeviceType'] : '';
$this->_device->user = $this->_driver->getUser();
}

// Check this here so we only need to save the device object once.
if ($this->_device->properties['version'] < $this->_maxVersion &&
if ($this->_device->properties[Horde_ActiveSync_Device::VERSION] < $this->_maxVersion &&
$this->_device->needsVersionUpdate($this->getSupportedVersions())) {

$needMsRp = true;
Expand All @@ -810,22 +814,22 @@ public function handleRequest($cmd, $devId)
if (is_callable(array($this->_driver, 'modifyDeviceCallback'))) {
$this->_device = $this->_driver->modifyDeviceCallback($this->_device);
}
}

$this->_device->save();

if (is_callable(array($this->_driver, 'deviceCallback'))) {
$callback_ret = $this->_driver->deviceCallback($this->_device);
if ($callback_ret !== true) {
$msg = sprintf(
'The device %s was disallowed for user %s per policy settings.',
$this->_device->id,
$this->_device->user);
self::$_logger->err($msg);
if ($version > self::VERSION_TWELVEONE) {
$this->_globalError = $callback_ret;
} else {
throw new Horde_ActiveSync_Exception($msg);
}
$this->_device->save();
$this->_device->version = $version;
if (is_callable(array($this->_driver, 'deviceCallback'))) {
$callback_ret = $this->_driver->deviceCallback($this->_device);
if ($callback_ret !== true) {
$msg = sprintf(
'The device %s was disallowed for user %s per policy settings.',
$this->_device->id,
$this->_device->user);
self::$_logger->err($msg);
if ($version > self::VERSION_TWELVEONE) {
$this->_globalError = $callback_ret;
} else {
throw new Horde_ActiveSync_Exception($msg);
}
}
}
Expand Down
60 changes: 46 additions & 14 deletions framework/ActiveSync/lib/Horde/ActiveSync/Device.php
Expand Up @@ -35,6 +35,11 @@
* along with any custom properties set.
* @property string announcedVersion The most last EAS supported versions
* announced to the device.
* @property string multiplex Bitmask describing collections that this
* device does not support user created
* folders for, therefore all sources must
* be multiplexed together. Masks are
* the MULTIPLEX_* constants.
*
*/
class Horde_ActiveSync_Device
Expand All @@ -47,6 +52,7 @@ class Horde_ActiveSync_Device
const PHONE_NUMBER = 'Settings:PhoneNumber';
const VERSION = 'version';
const MULTIPLEX = 'multiplex';
const ANNOUNCED_VERSION = 'announcedVersion';

// Bitwise constants for flagging device must use multiplexed collections.
// @since 2.9.0
Expand Down Expand Up @@ -93,11 +99,18 @@ public function __construct(Horde_ActiveSync_State_Base $state, array $data = ar
*/
public function &__get($property)
{
if (isset($this->_properties[$property])) {
return $this->_properties[$property];
} else {
$return = null;
return $return;
switch ($property) {
//case self::VERSION:
case self::MULTIPLEX:
case self::ANNOUNCED_VERSION:
return $this->_properties['properties'][$property];
default:
if (isset($this->_properties[$property])) {
return $this->_properties[$property];
} else {
$return = null;
return $return;
}
}
}

Expand All @@ -106,9 +119,23 @@ public function &__get($property)
*/
public function __set($property, $value)
{
if (!isset($this->_properties[$property]) || $value != $this->_properties[$property]) {
$this->_dirty[$property] = true;
$this->_properties[$property] = $value;
switch ($property) {
//case self::VERSION:
case self::MULTIPLEX:
case self::ANNOUNCED_VERSION:
$properties = $this->properties;
if (empty($properties)) {
$properties = array();
}
$properties[$property] = $value;
$this->setDeviceProperties($properties);
break;

default:
if (!isset($this->_properties[$property]) || $value != $this->_properties[$property]) {
$this->_dirty[$property] = true;
$this->_properties[$property] = $value;
}
}
}

Expand All @@ -129,14 +156,16 @@ public function __isset($property)
*/
public function needsVersionUpdate($supported)
{
if (empty($this->properties['announcedVersion'])) {
$this->_properties['properties']['announcedVersion'] = $supported;
$this->_dirty['properties'] = true;
if (empty($this->properties[self::ANNOUNCED_VERSION])) {
$properties = $this->properties;
$properties[self::ANNOUNCED_VERSION] = $supported;
$this->setDeviceProperties($properties);
return false;
}
if ($this->properties['announcedVersion'] != $supported) {
$this->_properties['properties']['announcedVersion'] = $supported;
$this->_dirty['properties'] = true;
if ($this->properties[self::ANNOUNCED_VERSION] != $supported) {
$properties = $this->properties;
$properties[self::ANNOUNCED_VERSION] = $supported;
$this->setDeviceProperties($properties);
return true;
}

Expand Down Expand Up @@ -231,6 +260,9 @@ public function getFormattedDeviceProperties()
if (!empty($this->properties[self::VERSION])) {
$data[_("EAS Version")] = $this->properties[self::VERSION];
}
if (!empty($this->properties[self::MULTIPLEX])) {
$data[_("Forced Multiplexed Bitmask")] = $this->properties[self::MULTIPLEX];
}

return $data;
}
Expand Down

0 comments on commit 6504571

Please sign in to comment.