Commit bb01765e authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1092 Have fixstates also fix the parentid of additional folders.

Released under the Affero GNU General Public License (AGPL) version 3.
parent b8be1f7a
......@@ -941,11 +941,13 @@ 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
* @param string $parentid the parentid of this folder.
* @param boolean $checkDups indicates if duplicate names and ids should be verified. Default: true
*
* @access public
* @return boolean
*/
public function EditAdditionalFolder($folderid, $name, $flags) {
public function EditAdditionalFolder($folderid, $name, $flags, $parentid = 0, $checkDups = true) {
// check if a folderid and name were sent
if (!$folderid || !$name) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): No valid folderid ('%s') or name ('%s') sent. Aborting. ", $folderid, $name));
......@@ -967,11 +969,15 @@ 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 && $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;
if ($checkDups) {
// in order to check for the parent-ids we need a shortid
$parentShortId = $this->GetFolderIdForBackendId($parentid, false, null, null);
foreach($this->GetHierarchyCache()->ExportFolders() as $syncedFolderid => $folder) {
// $folder is a SyncFolder object here
if ($folder->displayname == $name && $folderid !== $folder->BackendId && $folderid !== $syncedFolderid && ($folder->parentid == $parentid || $folder->parentid == $parentShortId)) {
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;
}
}
}
......@@ -979,6 +985,7 @@ class ASDevice extends StateObject {
$af = $this->additionalfolders;
$af[$folderid]['name'] = $name;
$af[$folderid]['flags'] = $flags;
$af[$folderid]['parentid'] = $parentid;
$this->additionalfolders = $af;
return true;
......
......@@ -977,17 +977,17 @@ class ZPushAdmin {
}
/**
* Fixes potentially missing flags on additional folders.
* Fixes missing flags or parentids on additional folders.
*
* @access public
* @return array(seenDevices, devicesWithAdditionalFolders, fixedAdditionalFolders)
*/
static public function FixStatesAdditionalFolderFlags() {
static public function FixStatesAdditionalFolders() {
$devices = 0;
$devicesWithAddFolders = 0;
$fixed = 0;
$asdevices = ZPush::GetStateMachine()->GetAllDevices(false);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesAdditionalFolderFlags(): found %d devices", count($asdevices)));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesAdditionalFolders(): found %d devices", count($asdevices)));
foreach ($asdevices as $devid) {
try {
......@@ -1004,8 +1004,14 @@ class ZPushAdmin {
if ($addFolders) {
$devicesWithAddFolders++;
foreach($addFolders as $df) {
if (!isset($df['flags'])) {
$device->EditAdditionalFolder($df['folderid'], $df['name'], 0);
if (!isset($df['flags']) || !isset($df['parentid']) ) {
if (!isset($df['flags'])) {
$df['flags'] = 0;
}
if (!isset($df['parentid'])) {
$df['parentid'] = 0;
}
$device->EditAdditionalFolder($df['folderid'], $df['name'], $df['flags'], $df['parentid']);
$needsFixing = true;
}
}
......@@ -1016,12 +1022,12 @@ class ZPushAdmin {
}
if ($needsFixing) {
ZPush::GetStateMachine()->SetState($devicedata, $devid, IStateMachine::DEVICEDATA);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesAdditionalFolderFlags(): updated device '%s' because flags were fixed", $devid));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesAdditionalFolders(): updated device '%s' because flags or parentids were fixed", $devid));
$fixed++;
}
}
catch (StateNotFoundException $e) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::FixStatesAdditionalFolderFlags(): state for device '%s' can not be found", $devid));
ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::FixStatesAdditionalFolders(): state for device '%s' can not be found", $devid));
}
}
return array($devices, $devicesWithAddFolders, $fixed);
......
......@@ -746,7 +746,7 @@ class ZPushAdminCLI {
echo ZLog::GetLastMessage(LOGLEVEL_ERROR) . "\n";
echo "\tChecking flags of shared folders: ";
if (($stat = ZPushAdmin::FixStatesAdditionalFolderFlags()) !== false)
if (($stat = ZPushAdmin::FixStatesAdditionalFolders()) !== 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