Commit ba125996 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1037 Check for upgraded profiles that don't have flags. Implement

flag fix in 'z-push-admin -a fixstates'.

Released under the Affero GNU General Public License (AGPL) version 3.
parent c3cf8ad6
......@@ -495,6 +495,11 @@ class DeviceManager {
public function GetAdditionalUserSyncFolders() {
$folders = array();
foreach($this->device->GetAdditionalFolders() as $df) {
if (!isset($df['flags'])) {
$df['flags'] = 0;
ZLog::Write(LOGLEVEL_WARN, sprintf("DeviceManager->GetAdditionalUserSyncFolders(): Additional folder '%s' has no flags. Please run 'z-push-admin -a fixstates' to fix this issue.", $df['name']));
}
$folder = $this->getAdditionalSyncFolderObject($df['store'], $df['folderid'], $df['name'], $df['type'], $df['flags'], DeviceManager::FLD_ORIGIN_SHARED);
$folders[$folder->BackendId] = $folder;
}
......
......@@ -717,7 +717,6 @@ class ZPushAdmin {
$devices = $devData->devices;
$knownUsers = array_keys($devData->devices);
ZLog::Write(LOGLEVEL_DEBUG, print_r($devData,1),false);
foreach ($obsoleteUsers as $ouser) {
$lowerOUser = strtolower($ouser);
......@@ -855,7 +854,7 @@ class ZPushAdmin {
$nouuid = 0;
$fixed = 0;
$asdevices = ZPush::GetStateMachine()->GetAllDevices(false);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesHierarchyFolderData(): found %d devices", count($devices)));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesHierarchyFolderData(): found %d devices", count($asdevices)));
foreach ($asdevices as $devid) {
try {
......@@ -920,4 +919,57 @@ class ZPushAdmin {
return array($devices, $seen, $fixed, $nouuid);
}
/**
* Fixes potentially missing flags on additional folders.
*
* @access public
* @return array(seenDevices, devicesWithAdditionalFolders, fixedAdditionalFolders)
*/
static public function FixStatesAdditionalFolderFlags() {
$devices = 0;
$devicesWithAddFolders = 0;
$fixed = 0;
$asdevices = ZPush::GetStateMachine()->GetAllDevices(false);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesAdditionalFolderFlags(): found %d devices", count($asdevices)));
foreach ($asdevices as $devid) {
try {
// get the device
$devicedata = ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA);
$devices++;
$needsFixing = false;
foreach (self::ListUsers($devid) as $username) {
$device = new ASDevice($devid, ASDevice::UNDEFINED, $username, ASDevice::UNDEFINED);
$device->SetData($devicedata, false);
$addFolders = $device->GetAdditionalFolders();
if ($addFolders) {
$devicesWithAddFolders++;
foreach($addFolders as $df) {
if (!isset($df['flags'])) {
$device->EditAdditionalFolder($df['folderid'], $df['name'], 0);
$needsFixing = true;
}
}
}
$newData = $device->GetData();
if ($newData) {
$devicedata = $newData;
}
}
if ($needsFixing) {
ZPush::GetStateMachine()->SetState($devicedata, $devid, IStateMachine::DEVICEDATA);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesAdditionalFolderFlags(): updated device '%s' because flags were fixed", $devid));
$fixed++;
}
}
catch (StateNotFoundException $e) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::FixStatesAdditionalFolderFlags(): state for device '%s' can not be found", $devid));
}
}
return array($devices, $devicesWithAddFolders, $fixed);
}
}
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