PMCORE-4061 Departments are created multiple times when re-selected for ldap synchronization

This commit is contained in:
Roly Gutierrez
2022-11-24 09:46:41 -04:00
parent 8640a0b209
commit fc34a7cfdd
4 changed files with 83 additions and 64 deletions

View File

@@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use ProcessMaker\BusinessModel\User;
use ProcessMaker\Model\Department;
use ProcessMaker\Model\Groupwf;
/**
@@ -2593,6 +2594,45 @@ class LdapAdvanced
return true;
}
/**
* Get department Uid by title.
* @param string $title
* @return string
*/
public function getDepartmentUidByTitle(string $title): string
{
try {
$department = Department::query()
->where('DEP_STATUS', '=', 'ACTIVE')
->where('DEP_TITLE', '=', $title)
->first();
if (!empty($department)) {
return $department->DEP_UID;
}
} catch (Exception $e) {
$message = $e->getMessage();
Log::channel(':ldapSynchronizeGroups')->error($message, Bootstrap::context());
}
return "";
}
/**
* Check duplicate titles in DEPARTMENT table.
* @return bool
*/
public function checkDuplicateDepartmentTitles(): bool
{
$sql = ""
. "select DEP_TITLE,count(DEP_TITLE) "
. "from DEPARTMENT "
. "group by DEP_TITLE having count(DEP_TITLE)>1";
$results = DB::select(DB::raw($sql));
if (empty($results)) {
return false;
}
return true;
}
/**
* Get number of Users in each Group from the Database
*