|
|
@@ -134,7 +134,7 @@ class SyncUsers {
|
|
|
|
|
|
if (!$usrTo) {
|
|
|
$syncDisabled = false;
|
|
|
- $syncTodoList[] = "Stwórz użytkownika '{$usrLogin}' w bazie LDAP";
|
|
|
+ $syncTodoList[] = "Utwórz użytkownika '{$usrLogin}' w bazie LDAP";
|
|
|
}
|
|
|
else {// $usrFrom && $usrTo
|
|
|
|
|
|
@@ -212,27 +212,25 @@ class SyncUsers {
|
|
|
return $groupsTodo;
|
|
|
}
|
|
|
|
|
|
- public function getSyncGroupTodoList($groupID, $syncNestedGroups = false) {
|
|
|
+ public function getSyncGroupTodoList($idGroup, $syncNestedGroups = false) {
|
|
|
$syncTodoList = array();
|
|
|
- $groupFrom = $this->_fromStorage->getGroup($groupID);
|
|
|
- $groupTo = $this->_toStorage->getGroup($groupID);
|
|
|
+ $groupFrom = $this->_fromStorage->getGroup($idGroup);
|
|
|
+ $groupTo = $this->_toStorage->getGroup($idGroup);
|
|
|
|
|
|
if (!$groupFrom) {
|
|
|
- $syncTodoList[] = "Group {$groupID} not exists in fromStorage";
|
|
|
+ $syncTodoList[] = "Grupa {$idGroup} nie istnieje w bazie danych";
|
|
|
return $syncTodoList;
|
|
|
}
|
|
|
- else if (!$groupTo) {
|
|
|
- $syncTodoList[] = "Create group {$groupID} in toStorage";
|
|
|
+ if (!$groupTo) {
|
|
|
+ $syncTodoList[] = "Utwórz grupę {$idGroup} w bazie LDAP";
|
|
|
return $syncTodoList;
|
|
|
}
|
|
|
- else {
|
|
|
- $updateData = array();
|
|
|
- if (empty($groupTo->realName) && $groupFrom->realName != $groupTo->realName) {
|
|
|
- $updateData['realName'] = $groupFrom->realName;
|
|
|
- }
|
|
|
- foreach ($updateData as $key => $val) {
|
|
|
- $syncTodoList[] = "Update {$key}: {$val}";
|
|
|
- }
|
|
|
+ $updateData = array();
|
|
|
+ if (empty($groupTo->realName) && $groupFrom->realName != $groupTo->realName) {
|
|
|
+ $updateData['realName'] = $groupFrom->realName;
|
|
|
+ }
|
|
|
+ foreach ($updateData as $key => $val) {
|
|
|
+ $syncTodoList[] = "Aktualizuj {$key}: {$val}";
|
|
|
}
|
|
|
|
|
|
if ($syncNestedGroups) {
|
|
|
@@ -254,12 +252,12 @@ class SyncUsers {
|
|
|
}
|
|
|
|
|
|
if (!empty($groupsTodo)) {
|
|
|
- foreach ($groupsTodo as $kGroupID => $vBool) {
|
|
|
+ foreach ($groupsTodo as $kIdGroup => $vBool) {
|
|
|
if ($vBool) {
|
|
|
- $syncTodoList[] = "Add group '{$kGroupID}' to group '{$groupID}' in toStorage";
|
|
|
+ $syncTodoList[] = "Dodaj grupę '{$kIdGroup}' do grupy '{$idGroup}' w bazie LDAP";
|
|
|
}
|
|
|
else {
|
|
|
- $syncTodoList[] = "Remove group '{$kGroupID}' from group '{$groupID}' in toStorage";
|
|
|
+ $syncTodoList[] = "Usuń grupę '{$kIdGroup}' z grupy '{$idGroup}' w bazie LDAP";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -286,22 +284,21 @@ class SyncUsers {
|
|
|
}
|
|
|
|
|
|
if (!empty($groupsTodo)) {
|
|
|
- foreach ($groupsTodo as $kGroupID => $vBool) {
|
|
|
+ foreach ($groupsTodo as $kIdGroup => $vBool) {
|
|
|
if ($vBool) {
|
|
|
- $syncTodoList[] = "Add parent group '{$kGroupID}' to group '{$groupID}' in toStorage";// == add $groupID to $kGroupID
|
|
|
+ $syncTodoList[] = "Dodaj grupę nadrzędną '{$kIdGroup}' do grupy '{$idGroup}' w bazie LDAP";// == add $idGroup to $kIdGroup
|
|
|
}
|
|
|
else {
|
|
|
- $groupTest = $this->_fromStorage->getGroup($kGroupID);
|
|
|
+ $groupTest = $this->_fromStorage->getGroup($kIdGroup);
|
|
|
if ($groupTest) {
|
|
|
- $syncTodoList[] = "Remove parent group '{$kGroupID}' from group '{$groupID}' in toStorage";// == remove $groupID from $kGroupID
|
|
|
+ $syncTodoList[] = "Usuń grupę nadrzędną '{$kIdGroup}' z grupy '{$idGroup}' w bazie LDAP";// == remove $idGroup from $kIdGroup
|
|
|
} else {
|
|
|
- //$syncTodoList[] = "Keep parent group '{$kGroupID}' in group '{$groupID}' in toStorage, because that group dont exists in fromStorage";
|
|
|
+ //$syncTodoList[] = "Keep parent group '{$kIdGroup}' in group '{$idGroup}' in toStorage, because that group dont exists in fromStorage";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return $syncTodoList;
|
|
|
@@ -312,44 +309,35 @@ class SyncUsers {
|
|
|
*
|
|
|
* @return bool or -int if error @see getSyncUserErrorMsg($errCode);
|
|
|
*/
|
|
|
- public function syncGroup($groupID, $syncNestedGroups = false) {
|
|
|
- $groupFrom = $this->_fromStorage->getGroup($groupID);
|
|
|
- $groupTo = $this->_toStorage->getGroup($groupID);
|
|
|
+ public function syncGroup($idGroup, $syncNestedGroups = false) {
|
|
|
+ $groupFrom = $this->_fromStorage->getGroup($idGroup);
|
|
|
+ $groupTo = $this->_toStorage->getGroup($idGroup);
|
|
|
|
|
|
DBG::_('DBG_SU', '>0', 'groupFrom', $groupFrom, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
DBG::_('DBG_SU', '>0', 'groupTo', $groupTo, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
|
- if (!$groupFrom) {
|
|
|
- $this->setError(1, "Group {$groupID} not exists in fromStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
|
|
|
- return false;
|
|
|
- }
|
|
|
- else if (!$groupTo) {
|
|
|
+ if (!$groupFrom) throw new Exception("Grupa [{$idGroup}] nie istnieje w bazie danych");
|
|
|
+ if (!$groupTo) {
|
|
|
|
|
|
$this->_toStorage->createGroup($groupFrom);
|
|
|
|
|
|
- $groupTo = $this->_toStorage->getGroup($groupID);
|
|
|
- $synced = $this->syncExistingGroup($groupID, $groupFrom, $groupTo, $syncNestedGroups);
|
|
|
- if (!$synced) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
+ $groupTo = $this->_toStorage->getGroup($idGroup);
|
|
|
+ if (!$groupTo) throw new Exception("Nie udało się utworzyć grupy [{$idGroup}] w bazie LDAP");
|
|
|
+ $this->syncExistingGroup($idGroup, $groupFrom, $groupTo, $syncNestedGroups);
|
|
|
}
|
|
|
else {// $groupFrom && $groupTo
|
|
|
- $synced = $this->syncExistingGroup($groupID, $groupFrom, $groupTo, $syncNestedGroups);
|
|
|
- if (!$synced) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ $this->syncExistingGroup($idGroup, $groupFrom, $groupTo, $syncNestedGroups);
|
|
|
}
|
|
|
|
|
|
- $this->_fromStorage->setSyncGroupDate($groupID);
|
|
|
- $this->_toStorage->setSyncGroupDate($groupID);
|
|
|
+ $this->_fromStorage->setSyncGroupDate($idGroup);
|
|
|
+ $this->_toStorage->setSyncGroupDate($idGroup);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public function syncExistingGroup($groupID, ObjectGroup $groupFrom, ObjectGroup $groupTo, $syncNestedGroups = false) {
|
|
|
- if (!$groupFrom) return false;
|
|
|
- if (!$groupTo) return false;
|
|
|
+ if (!$groupFrom) throw new Exception("Nie podano grupy z bazy danych!");
|
|
|
+ if (!$groupTo) throw new Exception("Nie podano grupy z bazy LDAP!");
|
|
|
|
|
|
$updateData = array();
|
|
|
if (empty($groupTo->realName) && $groupFrom->realName != $groupTo->realName) {
|
|
|
@@ -358,14 +346,12 @@ class SyncUsers {
|
|
|
|
|
|
//if ($groupFrom->employeeType != $groupTo->employeeType) $updateData['employeeType'] = $groupFrom->employeeType;
|
|
|
$updated = $this->_toStorage->updateGroup($groupTo, $updateData);
|
|
|
-
|
|
|
if (!$updated) {
|
|
|
$errors = $this->_toStorage->getRawErrorsList();
|
|
|
foreach ($errors as $vErr) {
|
|
|
$this->setError($vErr->code, $vErr->msg, $vErr->dbgMsg);
|
|
|
}
|
|
|
- $this->setError(1, "TODO: update group {$groupID} from fromStorage to toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
|
|
|
- return false;
|
|
|
+ throw new Exception("TODO: update group [{$groupID}] from fromStorage to toStorage");
|
|
|
}
|
|
|
|
|
|
if ($syncNestedGroups) {
|
|
|
@@ -387,17 +373,14 @@ class SyncUsers {
|
|
|
if (!$groupFrom) $groupFrom = $this->_fromStorage->getGroup($groupID);
|
|
|
if (!$groupTo) $groupTo = $this->_toStorage->getGroup($groupID);
|
|
|
|
|
|
- if (V::get('DBG_SU', 0, $_GET, 'int') > 0) {
|
|
|
- echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">groupFrom (hasNestedGroups:'.(!empty($groupFrom->nestedGroups)).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($groupFrom);echo'</pre>';
|
|
|
- echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">groupTo (hasNestedGroups:'.(!empty($groupTo->nestedGroups)).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($groupTo);echo'</pre>';
|
|
|
- }
|
|
|
+ DBG::_('DBG_SU', '>0', "groupFrom (hasNestedGroups:" . (!empty($groupFrom->nestedGroups)) . ")", $groupFrom, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ DBG::_('DBG_SU', '>0', "groupTo (hasNestedGroups:" . (!empty($groupTo->nestedGroups)) . ")", $groupTo, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
|
if (empty($groupFrom->nestedGroups) && empty($groupTo->nestedGroups)) {
|
|
|
// nothing to do
|
|
|
return true;
|
|
|
}
|
|
|
else {
|
|
|
-
|
|
|
/*
|
|
|
[nestedGroups] => Array(
|
|
|
[2981] => stdClass Object(
|
|
|
@@ -407,7 +390,6 @@ class SyncUsers {
|
|
|
[zasobID] => 2981
|
|
|
[zasobDESC] => Kierownik ds. Rozwoju Biznesu
|
|
|
*/
|
|
|
-
|
|
|
/**
|
|
|
* $groupsTodo - groups todo list:
|
|
|
* 'com.apple.access_mail' => true - add to this group
|
|
|
@@ -428,24 +410,17 @@ class SyncUsers {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (V::get('DBG_SU', 0, $_GET, 'int') > 0) {
|
|
|
- echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">groupsTodo (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($groupsTodo);echo'</pre>';
|
|
|
- }
|
|
|
+ DBG::_('DBG_SU', '>0', "groupsTodo", $groupsTodo, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
|
if (!empty($groupsTodo)) {
|
|
|
foreach ($groupsTodo as $kGroupID => $vBool) {
|
|
|
if ($vBool) {
|
|
|
$added = $this->_toStorage->addNestedGroup($groupID, $kGroupID);
|
|
|
- if (!$added) {
|
|
|
- $this->setError(1, "Error: group '{$kGroupID}' add to group '{$groupID}' in toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
|
|
|
- }
|
|
|
+ if (!$added) throw new Exception("Error: group '{$kGroupID}' add to group '{$groupID}' in toStorage");
|
|
|
}
|
|
|
else {
|
|
|
$removed = $this->_toStorage->removeNestedGroup($groupID, $kGroupID);
|
|
|
- if (!$removed) {
|
|
|
- $this->setError(1, "Error: group '{$kGroupID}' remove from group '{$groupID}' in toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
|
|
|
- }
|
|
|
+ if (!$removed) throw new Exception("Error: group '{$kGroupID}' remove from group '{$groupID}' in toStorage");
|
|
|
}
|
|
|
}
|
|
|
}
|