Commit dbb61c5e authored by Sebastian Kummer's avatar Sebastian Kummer

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

Merge pull request #359 in ZP/z-push from feature/ZP-1037-modify-open-shared-folders-api-to to develop

* commit '46254ee5':
  ZP-1037 Fixed logging.
  ZP-1037 Execute FixStatesAdditionalFolderFlags() when calling z-push-admin fixstates.
  ZP-1037 Check for upgraded profiles that don't have flags. Implement flag fix in 'z-push-admin -a fixstates'.
  ZP-1037 Added flags to OpenSharedFolderAPI in ASDevice, DeviceManager, ZPushAdmin and WebserviceDevice. Added constant DeviceManager::FLD_FLAGS_REPLYASUSER. Renamed private method DeviceManager->getAdditionalSyncFolder() to getAdditionalSyncFolderObject() for better readability, modified checks on ASDevice->EditAdditionalFolder() to allow a flag modification (maintaining the same name), added SyncFolder->Flag as ignored parameter and populate it when calling DeviceManager->GetAdditionalUserSyncFolders().
parents a9192351 46254ee5
......@@ -854,11 +854,12 @@ class ASDevice extends StateObject {
* @param string $folderid the folder id of the additional folder.
* @param string $name the name of the additional folder (has to be unique for all folders on the device).
* @param string $type AS foldertype of SYNC_FOLDER_TYPE_USER_*
* @param int $flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
public function AddAdditionalFolder($store, $folderid, $name, $type) {
public function AddAdditionalFolder($store, $folderid, $name, $type, $flags) {
// check if type is of a additional user type
if (!in_array($type, array(SYNC_FOLDER_TYPE_USER_CONTACT, SYNC_FOLDER_TYPE_USER_APPOINTMENT, SYNC_FOLDER_TYPE_USER_TASK, SYNC_FOLDER_TYPE_USER_MAIL, SYNC_FOLDER_TYPE_USER_NOTE, SYNC_FOLDER_TYPE_USER_JOURNAL))) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->AddAdditionalFolder(): folder can not be added because the specified type '%s' is not a permitted user type.", $type));
......@@ -900,6 +901,7 @@ class ASDevice extends StateObject {
'folderid' => $folderid,
'name' => $name,
'type' => $type,
'flags' => $flags,
);
$this->additionalfolders = $af;
......@@ -914,11 +916,12 @@ class ASDevice extends StateObject {
*
* @param string $folderid the folder id of the additional folder.
* @param string $name the name of the additional folder (has to be unique for all folders on the device).
* @param int $flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
public function EditAdditionalFolder($folderid, $name) {
public function EditAdditionalFolder($folderid, $name, $flags) {
// check if a folder with this ID is known
if (!isset($this->additionalfolders[$folderid])) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be edited because there is no folder known with this folder id: '%s'. Add the folder first.", $folderid));
......@@ -926,9 +929,9 @@ class ASDevice extends StateObject {
}
// check if a folder with the new name is already in the list
foreach ($this->additionalfolders as $k => $folder) {
if ($folder['name'] == $name) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be added because there is already an additional folder with the same name: '%s'", $name));
foreach ($this->additionalfolders as $existingFolderid => $folder) {
if ($folder['name'] == $name && $folderid !== $existingFolderid) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be edited because there is already an additional folder with the same name: '%s'", $name));
return false;
}
}
......@@ -936,8 +939,8 @@ class ASDevice extends StateObject {
// check if a folder with the new name is already known on the device (regular folder)
foreach($this->GetHierarchyCache()->ExportFolders() as $syncedFolderid => $folder) {
// $folder is a SyncFolder object here
if ($folder->displayname == $name) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be added because there is already a folder with the same name synchronized: '%s'", $folderid));
if ($folder->displayname == $name && $folderid !== $folder->BackendId && $folderid !== $syncedFolderid) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be edited because there is already a folder with the same name synchronized: '%s'", $folderid));
return false;
}
}
......@@ -945,6 +948,7 @@ class ASDevice extends StateObject {
// update the name
$af = $this->additionalfolders;
$af[$folderid]['name'] = $name;
$af[$folderid]['flags'] = $flags;
$this->additionalfolders = $af;
return true;
......
......@@ -60,6 +60,8 @@ class DeviceManager {
const FLD_ORIGIN_SHARED = "S";
const FLD_ORIGIN_GAB = "G";
const FLD_FLAGS_REPLYASUSER = 1;
private $device;
private $deviceHash;
private $saveDevice;
......@@ -493,7 +495,12 @@ class DeviceManager {
public function GetAdditionalUserSyncFolders() {
$folders = array();
foreach($this->device->GetAdditionalFolders() as $df) {
$folder = $this->getAdditionalSyncFolder($df['store'], $df['folderid'], $df['name'], $df['type'], DeviceManager::FLD_ORIGIN_SHARED);
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;
}
......@@ -501,7 +508,7 @@ class DeviceManager {
if (KOE_CAPABILITY_GAB && $this->IsKoe() && KOE_GAB_STORE != "" && KOE_GAB_NAME != "") {
// if KOE_GAB_FOLDERID is set, use it
if (KOE_GAB_FOLDERID != "") {
$folder = $this->getAdditionalSyncFolder(KOE_GAB_STORE, KOE_GAB_FOLDERID, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT, DeviceManager::FLD_ORIGIN_GAB);
$folder = $this->getAdditionalSyncFolderObject(KOE_GAB_STORE, KOE_GAB_FOLDERID, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT, 0, DeviceManager::FLD_ORIGIN_GAB);
$folders[$folder->BackendId] = $folder;
}
else {
......@@ -518,7 +525,7 @@ class DeviceManager {
}
if ($backendGabId) {
$folders[$backendGabId] = $this->getAdditionalSyncFolder(KOE_GAB_STORE, $backendGabId, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT, DeviceManager::FLD_ORIGIN_GAB);
$folders[$backendGabId] = $this->getAdditionalSyncFolderObject(KOE_GAB_STORE, $backendGabId, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT, 0, DeviceManager::FLD_ORIGIN_GAB);
}
}
}
......@@ -1141,12 +1148,13 @@ class DeviceManager {
* @param string $folderid
* @param string $name
* @param int $type
* @param int $flags
* @param string $folderOrigin
*
* @access private
* @returns SyncFolder
*/
private function getAdditionalSyncFolder($store, $folderid, $name, $type, $folderOrigin) {
private function getAdditionalSyncFolderObject($store, $folderid, $name, $type, $flags, $folderOrigin) {
$folder = new SyncFolder();
$folder->BackendId = $folderid;
$folder->serverid = $this->GetFolderIdForBackendId($folder->BackendId, true, $folderOrigin, $name);
......@@ -1156,6 +1164,7 @@ class DeviceManager {
// save store as custom property which is not streamed directly to the device
$folder->NoBackendFolder = true;
$folder->Store = $store;
$folder->Flags = $flags;
return $folder;
}
......
......@@ -326,6 +326,7 @@ define("SYNC_FOLDERHIERARCHY_VERSION","FolderHierarchy:Version");
define("SYNC_FOLDERHIERARCHY_IGNORE_STORE","FolderHierarchy:IgnoreStore");
define("SYNC_FOLDERHIERARCHY_IGNORE_NOBCKENDFLD","FolderHierarchy:IgnoreNoBackendFolder");
define("SYNC_FOLDERHIERARCHY_IGNORE_BACKENDID","FolderHierarchy:IgnoreBackendId");
define("SYNC_FOLDERHIERARCHY_IGNORE_FLAGS","FolderHierarchy:IgnoreFlags");
// MeetingResponse
define("SYNC_MEETINGRESPONSE_CALENDARID","MeetingResponse:CalendarId");
......
......@@ -54,6 +54,7 @@ class SyncFolder extends SyncObject {
public $Store;
public $NoBackendFolder;
public $BackendId;
public $Flags;
function SyncFolder() {
$mapping = array (
......@@ -79,6 +80,10 @@ class SyncFolder extends SyncObject {
SYNC_FOLDERHIERARCHY_IGNORE_BACKENDID => array ( self::STREAMER_VAR => "BackendId",
self::STREAMER_TYPE => self::STREAMER_TYPE_IGNORE),
SYNC_FOLDERHIERARCHY_IGNORE_FLAGS => array ( self::STREAMER_VAR => "Flags",
self::STREAMER_TYPE => self::STREAMER_TYPE_IGNORE),
);
parent::SyncObject($mapping);
......
......@@ -506,6 +506,7 @@ class ZPushAdmin {
'name' => $so->displayname,
'type' => $so->type,
'origin' => Utils::GetFolderOriginFromId($syncfolderid),
'flags' => 0, // static folders have no flags
);
}
}
......@@ -528,11 +529,12 @@ class ZPushAdmin {
* @param string $add_folderid the folder id of the additional folder.
* @param string $add_name the name of the additional folder (has to be unique for all folders on the device).
* @param string $add_type AS foldertype of SYNC_FOLDER_TYPE_USER_*
* @param int $add_flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
static public function AdditionalFolderAdd($user, $devid, $add_store, $add_folderid, $add_name, $add_type) {
static public function AdditionalFolderAdd($user, $devid, $add_store, $add_folderid, $add_name, $add_type, $add_flags) {
// load device data
$device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
try {
......@@ -549,7 +551,7 @@ class ZPushAdmin {
return false;
}
$status = $device->AddAdditionalFolder($add_store, $add_folderid, $add_name, $add_type);
$status = $device->AddAdditionalFolder($add_store, $add_folderid, $add_name, $add_type, $add_flags);
if ($status)
ZPush::GetStateMachine()->SetState($device->GetData(), $devid, IStateMachine::DEVICEDATA);
......@@ -570,11 +572,12 @@ class ZPushAdmin {
* @param string $devid device id of where the folder should be updated.
* @param string $add_folderid the folder id of the additional folder.
* @param string $add_name the name of the additional folder (has to be unique for all folders on the device).
* @param int $add_flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
static public function AdditionalFolderEdit($user, $devid, $add_folderid, $add_name) {
static public function AdditionalFolderEdit($user, $devid, $add_folderid, $add_name, $add_flags) {
// load device data
$device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
try {
......@@ -597,7 +600,7 @@ class ZPushAdmin {
return false;
}
$status = $device->EditAdditionalFolder($add_folderid, $add_name);
$status = $device->EditAdditionalFolder($add_folderid, $add_name, $add_flags);
if ($status)
ZPush::GetStateMachine()->SetState($device->GetData(), $devid, IStateMachine::DEVICEDATA);
......@@ -714,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);
......@@ -852,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 {
......@@ -917,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);
}
}
......@@ -190,17 +190,19 @@ class WebserviceDevice {
* @param string $add_folderid the folder id of the additional folder.
* @param string $add_name the name of the additional folder (has to be unique for all folders on the device).
* @param string $add_type AS foldertype of SYNC_FOLDER_TYPE_USER_*
* @param int $add_flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
public function AdditionalFolderAdd($deviceId, $add_store, $add_folderid, $add_name, $add_type) {
public function AdditionalFolderAdd($deviceId, $add_store, $add_folderid, $add_name, $add_type, $add_flags) {
$user = Request::GetGETUser();
$deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
$add_folderid = preg_replace("/[^A-Za-z0-9]/", "", $add_folderid);
$add_type = preg_replace("/[^0-9]/", "", $add_type);
$add_flags = preg_replace("/[^0-9]/", "", $add_flags);
$status = ZPushAdmin::AdditionalFolderAdd($user, $deviceId, $add_store, $add_folderid, $add_name, $add_type);
$status = ZPushAdmin::AdditionalFolderAdd($user, $deviceId, $add_store, $add_folderid, $add_name, $add_type, $add_flags);
if (!$status) {
ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
......@@ -217,21 +219,23 @@ class WebserviceDevice {
* @param string $deviceId device id of where the folder should be updated.
* @param string $add_folderid the folder id of the additional folder.
* @param string $add_name the name of the additional folder (has to be unique for all folders on the device).
* @param int $add_flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
public function AdditionalFolderEdit($deviceId, $add_folderid, $add_name) {
public function AdditionalFolderEdit($deviceId, $add_folderid, $add_name, $add_flags) {
$user = Request::GetGETUser();
$deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
$add_folderid = preg_replace("/[^A-Za-z0-9]/", "", $add_folderid);
$add_flags = preg_replace("/[^0-9]/", "", $add_flags);
$status = ZPushAdmin::AdditionalFolderEdit($user, $deviceId, $add_folderid, $add_name);
$status = ZPushAdmin::AdditionalFolderEdit($user, $deviceId, $add_folderid, $add_name, $add_flags);
if (!$status) {
ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
}
ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::AdditionalFolderEdit(): added folder for device '%s' of user '%s': %s", $deviceId, $user, Utils::PrintAsString($status)));
ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::AdditionalFolderEdit(): edited folder for device '%s' of user '%s': %s", $deviceId, $user, Utils::PrintAsString($status)));
ZPush::GetTopCollector()->AnnounceInformation("Edited additional folder", true);
return $status;
......
......@@ -744,6 +744,12 @@ class ZPushAdminCLI {
printf("Devices: %d - Processed: %d - Fixed: %d - Device+User without hierarchy: %d\n", $stat[0], $stat[1], $stat[2], $stat[3]);
else
echo ZLog::GetLastMessage(LOGLEVEL_ERROR) . "\n";
echo "\tChecking flags of shared folders: ";
if (($stat = ZPushAdmin::FixStatesAdditionalFolderFlags()) !== false)
printf("Devices: %d - Devices with additional folders: %d - Fixed: %d\n", $stat[0], $stat[1], $stat[2]);
else
echo ZLog::GetLastMessage(LOGLEVEL_ERROR) . "\n";
}
/**
......
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