Commit 17c960da authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #518 in ZP/z-push from...

Merge pull request #518 in ZP/z-push from feature/ZP-1197-add-a-flag-to-webservicedevice--getdevicedetails to develop

* commit 'be218d85':
  ZP-1197 rename $noHierarchyCache to $stripHierarchyCache.
  ZP-1197 Make stripping of HierarchyCache from ASDevice optional, expose optional stripping to webservice (default: strip).
  ZP-1197 Implement StripData() for HierarchyCache + MemoryChangesWrapper.
parents 390c86d8 be218d85
......@@ -175,18 +175,20 @@ class ASDevice extends StateObject {
}
/**
* Removes internal data from the object, so this data can not be exposed
* Removes internal data from the object, so this data can not be exposed.
*
* @param boolean $stripHierarchyCache (opt) strips the hierarchy cache - default: true
*
* @access public
* @return boolean
*/
public function StripData() {
public function StripData($stripHierarchyCache = true) {
unset($this->changed);
unset($this->unsetdata);
unset($this->hierarchyCache);
unset($this->forceSave);
unset($this->newdevice);
unset($this->ignoredMessageIds);
unset($this->backend2folderidCache);
if (isset($this->ignoredmessages) && is_array($this->ignoredmessages)) {
$imessages = $this->ignoredmessages;
......@@ -199,6 +201,14 @@ class ASDevice extends StateObject {
$this->ignoredmessages = $unserializedMessage;
}
if (!$stripHierarchyCache && $this->hierarchyCache !== false && $this->hierarchyCache instanceof ChangesMemoryWrapper) {
$this->hierarchyCache->StripData();
}
else {
unset($this->hierarchyCache);
}
return true;
}
......
......@@ -403,4 +403,19 @@ class ChangesMemoryWrapper extends HierarchyCache implements IImportChanges, IEx
$this->changes = array();
$this->step = 0;
}
/**
* Removes internal data from the object, so this data can not be exposed.
*
* @access public
* @return boolean
*/
public function StripData() {
unset($this->changes);
unset($this->step);
unset($this->destinationImporter);
unset($this->exportImporter);
return parent::StripData();
}
}
......@@ -181,6 +181,21 @@ class HierarchyCache {
return sprintf("HierarchyCache is %s - Cached objects: %d", ((isset($this->cacheById))?"up":"down"), ((isset($this->cacheById))?count($this->cacheById):"0"));
}
/**
* Removes internal data from the object, so this data can not be exposed.
*
* @access public
* @return boolean
*/
public function StripData() {
unset($this->changed);
unset($this->cacheByIdOld);
foreach ($this->cacheById as $id => $folder) {
$folder->StripData();
}
return true;
}
/**
* Returns objects which should be persistent
* called before serialization
......
......@@ -69,11 +69,12 @@ class ZPushAdmin {
*
* @param string $devid device id
* @param string $user user to be looked up
* @param boolean $withHierarchyCache (opt) includes the HierarchyCache - default: false
*
* @return ASDevice object
* @access public
*/
static public function GetDeviceDetails($devid, $user) {
static public function GetDeviceDetails($devid, $user, $withHierarchyCache = false) {
try {
$device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
......@@ -127,7 +128,7 @@ class ZPushAdmin {
}
}
}
$device->StripData();
$device->StripData(!$withHierarchyCache);
return $device;
}
catch (StateNotFoundException $e) {
......
......@@ -50,16 +50,18 @@ class WebserviceDevice {
/**
* Returns the details of a given deviceid of the Request::GetGETUser().
*
* @param boolean $withHierarchyCache (opt) includes the HierarchyCache - default: false
*
* @access public
* @return ASDevice object
*/
public function GetDeviceDetails($deviceId) {
public function GetDeviceDetails($deviceId, $withHierarchyCache = false) {
$user = Request::GetGETUser();
$deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::GetDeviceDetails('%s'): getting device details from state of user '%s'", $deviceId, $user));
ZPush::GetTopCollector()->AnnounceInformation(sprintf("Retrieved details of device '%s'", $deviceId), true);
return ZPushAdmin::GetDeviceDetails($deviceId, $user);
return ZPushAdmin::GetDeviceDetails($deviceId, $user, $withHierarchyCache);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment