Compare commits
10 Commits
6dffc6100e
...
2164f5947f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2164f5947f | ||
|
|
94eb707118 | ||
|
|
4b2c6bf254 | ||
|
|
701e3060bb | ||
|
|
9ab55866b9 | ||
|
|
53073dbb1f | ||
|
|
6211c48e44 | ||
|
|
c96920a30a | ||
|
|
b6b7103624 | ||
|
|
0b0a176058 |
@@ -6,6 +6,8 @@ stages:
|
||||
- build
|
||||
|
||||
build_job:
|
||||
only:
|
||||
- develop
|
||||
stage: build
|
||||
script:
|
||||
# Download fileManager
|
||||
@@ -13,5 +15,5 @@ build_job:
|
||||
- bash docker/build.sh $VERSION
|
||||
|
||||
before_script:
|
||||
- VERSION=$(git describe | awk -F- '{ if( $2) {print $1 "." $2} else {print $1 ".0"} }' )
|
||||
- VERSION=$(git describe | awk -F- '{ if( $2) {print $1 "." $2} else {print $1 ".1"} }' )
|
||||
- echo $VERSION
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Use our base image
|
||||
FROM gitlab.luranasoft.com:5050/luos/docker/base-image:1.0.54-php8.3
|
||||
FROM gitlab.luranasoft.com:5050/luos/docker/base-image:1.0.55-php8.3
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /code
|
||||
|
||||
@@ -15,4 +15,3 @@ $scriptDir = dirname(__FILE__).'/';
|
||||
error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT);
|
||||
|
||||
include WORKFLOW_BIN_PATH . '/cli.php';
|
||||
|
||||
|
||||
884
workflow/engine/bin/tasks/cliAuthSources.php
Normal file
884
workflow/engine/bin/tasks/cliAuthSources.php
Normal file
@@ -0,0 +1,884 @@
|
||||
<?php
|
||||
/**
|
||||
* Command line task to sync auth sources
|
||||
*/
|
||||
|
||||
use ProcessMaker\Model\Department;
|
||||
use ProcessMaker\Core\JobsManager;
|
||||
use ProcessMaker\Model\Groupwf;
|
||||
use ProcessMaker\Model\RbacAuthenticationSource;
|
||||
use ProcessMaker\Model\RbacUsers;
|
||||
use ProcessMaker\Model\User;
|
||||
use ProcessMaker\Model\GroupUser;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use \Department as DepartmentModel;
|
||||
|
||||
CLI::taskName('auth-sources-sync');
|
||||
CLI::taskDescription(<<<EOT
|
||||
Update plugin translations
|
||||
|
||||
LANG is the language, such as 'fr' (French) or 'zh-CN' (mainland Chinese).
|
||||
If the language is not specified, then it is 'en' (English) by default.
|
||||
|
||||
EOT
|
||||
);
|
||||
CLI::taskArg('workspace', false);
|
||||
CLI::taskRun('run_auth_sources_sync');
|
||||
|
||||
$GLOBALS['deletedRemoved'] = 0;
|
||||
$GLOBALS['deletedRemovedUsers'] = '';
|
||||
$GLOBALS['dAlready'] = 0;
|
||||
$GLOBALS['dMoved'] = 0;
|
||||
$GLOBALS['dImpossible'] = 0;
|
||||
$GLOBALS['dCreated'] = 0;
|
||||
$GLOBALS['dRemoved'] = 0;
|
||||
$GLOBALS['dAlreadyUsers'] = '';
|
||||
$GLOBALS['dMovedUsers'] = '';
|
||||
$GLOBALS['dImpossibleUsers'] = '';
|
||||
$GLOBALS['dCreatedUsers'] = '';
|
||||
$GLOBALS['dRemovedUsers'] = '';
|
||||
$GLOBALS['gAlready'] = 0;
|
||||
$GLOBALS['gMoved'] = 0;
|
||||
$GLOBALS['gImpossible'] = 0;
|
||||
$GLOBALS['gCreated'] = 0;
|
||||
$GLOBALS['gRemoved'] = 0;
|
||||
$GLOBALS['gAlreadyUsers'] = '';
|
||||
$GLOBALS['gMovedUsers'] = '';
|
||||
$GLOBALS['gImpossibleUsers'] = '';
|
||||
$GLOBALS['gCreatedUsers'] = '';
|
||||
$GLOBALS['gRemovedUsers'] = '';
|
||||
$GLOBALS['usersRemovedOu'] = [];
|
||||
$GLOBALS['managersHierarchy'] = [];
|
||||
$GLOBALS['oldManagersHierarchy'] = [];
|
||||
$GLOBALS['managersToClear'] = [];
|
||||
$GLOBALS['deletedManager'] = 0;
|
||||
|
||||
function run_auth_sources_sync($command, $args)
|
||||
{
|
||||
if (!empty($command) && count($command) >= 1) {
|
||||
$workspace = $command[0];
|
||||
CLI::logging("Check workspace $workspace ...\n", null, 'blue');
|
||||
|
||||
if (!is_dir(PATH_DB . $workspace) || !file_exists(PATH_DB . $workspace . PATH_SEP . 'db.php')) {
|
||||
CLI::logging("Workspace not found ❌\n",null, 'red');
|
||||
CLI::logging("Syncronization canceled 🚫\n",null, 'red');
|
||||
return;
|
||||
}
|
||||
$startTime = microtime(true);
|
||||
CLI::logging("Workspace \"$workspace\" found.......... ✅\n",null, 'green');
|
||||
initWorkspace($workspace);
|
||||
|
||||
executeLdapCron();
|
||||
|
||||
$endTime = microtime(true);
|
||||
$runtime = $endTime - $startTime;
|
||||
|
||||
CLI::logging("Syncronization completed 🎉🎉🎉\n", null, 'green');
|
||||
CLI::logging("Start time: " . date('d-m-Y H:i:s', $startTime) . "\n", null, 'green');
|
||||
CLI::logging("Runtime: " . round($runtime, 2) . " seconds\n", null, 'green');
|
||||
} else {
|
||||
CLI::logging("The command requires the workspace name\n");
|
||||
}
|
||||
}
|
||||
|
||||
function executeLdapCron()
|
||||
{
|
||||
$plugin = new LdapSource();
|
||||
$rbac = RBAC::getSingleton();
|
||||
|
||||
if (is_null($rbac->authSourcesObj)) {
|
||||
$rbac->authSourcesObj = new AuthenticationSource();
|
||||
}
|
||||
|
||||
unset($GLOBALS['translation']);
|
||||
|
||||
$plugin->setFrontEnd(true);
|
||||
$plugin->setDebug(true);
|
||||
|
||||
//Get all authsource for this plugin ( ldapAdvanced plugin, because other authsources are not needed )
|
||||
//$arrayAuthenticationSource = $plugin->getAuthSources();
|
||||
|
||||
$filters = ['orderBy' => ['AUTH_SOURCE_NAME', 'ASC']];
|
||||
$rbacAuthenticationSource = new RbacAuthenticationSource();
|
||||
$arrayAuthenticationSource = $rbacAuthenticationSource->show($filters);
|
||||
|
||||
$filters = array(
|
||||
'conditions' => ['DEP_STATUS' => 'ACTIVE'],
|
||||
'orderBy' => ['DEP_TITLE', 'ASC']
|
||||
);
|
||||
$department = new Department();
|
||||
$aDepartments = $department->show($filters);
|
||||
|
||||
$filters = array(
|
||||
'conditions' => ['GRP_STATUS' => 'ACTIVE'],
|
||||
'orderBy' => ['GRP_TITLE', 'ASC']
|
||||
);
|
||||
$groupwf = new Groupwf();
|
||||
$aGroups = $groupwf->show($filters);
|
||||
|
||||
|
||||
$plugin->frontEndShow('START');
|
||||
$plugin->debugLog('START');
|
||||
$plugin->stdLog(null, 'cron execution started');
|
||||
|
||||
foreach ($arrayAuthenticationSource['data'] ?? [] as $value) {
|
||||
$arrayAuthenticationSourceData = $value;
|
||||
try {
|
||||
$plugin->debugLog("ldapadvanced.php > function executeCron() > foreach > \$arrayAuthenticationSourceData ---->\n" . print_r($arrayAuthenticationSourceData, true));
|
||||
$plugin->stdLog(null, 'AuthenticationSourceData', ['result' => $arrayAuthenticationSourceData]);
|
||||
|
||||
$plugin->authSourceUid = $arrayAuthenticationSourceData['AUTH_SOURCE_UID'];
|
||||
$plugin->ldapcnn = null;
|
||||
|
||||
$plugin->setArrayDepartmentUserSynchronizedChecked([]);
|
||||
$plugin->setArrayUserUpdateChecked([]);
|
||||
|
||||
// Get all User (USR_UID, USR_USERNAME, USR_AUTH_USER_DN) registered in RBAC with this Authentication Source
|
||||
$plugin->setArrayAuthenticationSourceUsers($arrayAuthenticationSourceData['AUTH_SOURCE_UID']); //INITIALIZE DATA
|
||||
// Set some logs to show
|
||||
$plugin->frontEndShow('TEXT', 'Authentication Source: ' . $arrayAuthenticationSourceData['AUTH_SOURCE_NAME']);
|
||||
$plugin->log(null, 'Executing cron for Authentication Source: ' . $arrayAuthenticationSourceData['AUTH_SOURCE_NAME']);
|
||||
$plugin->stdLog(null, 'authentication source', ['AUTH_SOURCE_NAME' => $arrayAuthenticationSourceData['AUTH_SOURCE_NAME']]);
|
||||
|
||||
// Get all departments from Ldap/ActiveDirectory and build a hierarchy using dn (ou->ou parent)
|
||||
$aLdapDepts = $plugin->searchDepartments();
|
||||
|
||||
// Obtain all departments from PM with a valid department in LDAP/ActiveDirectory
|
||||
$aRegisteredDepts = $plugin->getRegisteredDepartments($aLdapDepts, $aDepartments['data'] ?? []);
|
||||
|
||||
// Set some logs to show
|
||||
$plugin->debugLog("ldapadvanced.php > function executeCron() > foreach > \$aRegisteredDepts ---->\n" . print_r($aRegisteredDepts, true));
|
||||
$plugin->stdLog(null, 'RegisteredDepartments', ['result' => $aRegisteredDepts]);
|
||||
// Get all group from Ldap/ActiveDirectory
|
||||
$aLdapGroups = $plugin->searchGroups();
|
||||
// Obtain all groups from PM with a valid group in LDAP/ActiveDirectory
|
||||
$aRegisteredGroups = $plugin->getRegisteredGroups($aLdapGroups, $aGroups['data'] ?? []);
|
||||
// Set some logs to show
|
||||
$plugin->debugLog("ldapadvanced.php > function executeCron() > foreach > \$aRegisteredGroups ---->\n" . print_r($aRegisteredGroups, true));
|
||||
$plugin->stdLog(null, 'RegisteredGroups', ['result' => $aRegisteredGroups]);
|
||||
|
||||
// Get all users from Removed OU
|
||||
$GLOBALS['usersRemovedOu'] = $plugin->getUsersFromRemovedOu($arrayAuthenticationSourceData);
|
||||
$GLOBALS['deletedRemoved'] = count($GLOBALS['usersRemovedOu']);
|
||||
|
||||
//Department - Synchronize Users
|
||||
$numDepartments = count($aRegisteredDepts);
|
||||
$count = 0;
|
||||
|
||||
$plugin->debugLog("ldapadvanced.php > function executeCron() > foreach > \$numDepartments ----> $numDepartments");
|
||||
$plugin->stdLog(null, 'NumberDepartments', ['result' => $numDepartments]);
|
||||
|
||||
foreach ($aRegisteredDepts as $registeredDept) {
|
||||
$count++;
|
||||
departmentSynchronizeUsers($plugin, $numDepartments, $count, $registeredDept);
|
||||
}
|
||||
|
||||
//Department - Print log
|
||||
$logResults = sprintf(
|
||||
"- Departments -> Existing users: %d, moved: %d, impossible: %d, created: %d, removed: %d",
|
||||
$GLOBALS['dAlready'],
|
||||
$GLOBALS['dMoved'],
|
||||
$GLOBALS['dImpossible'],
|
||||
$GLOBALS['dCreated'],
|
||||
$GLOBALS['dRemoved']
|
||||
);
|
||||
|
||||
$plugin->frontEndShow('TEXT', $logResults);
|
||||
$plugin->log(null, $logResults);
|
||||
$context = [
|
||||
'existingUsers' => $GLOBALS['dAlready'],
|
||||
'moved' => $GLOBALS['dMoved'],
|
||||
'impossible' => $GLOBALS['dImpossible'],
|
||||
'created' => $GLOBALS['dCreated'],
|
||||
'removed' => $GLOBALS['dRemoved']
|
||||
];
|
||||
$plugin->stdLog(null, 'departments', $context);
|
||||
// Group - Synchronize Users
|
||||
$numGroups = count($aRegisteredGroups);
|
||||
$count = 0;
|
||||
|
||||
$plugin->debugLog("ldapadvanced.php > function executeCron() > foreach > \$numGroups ----> $numGroups");
|
||||
$plugin->stdLog(null, 'NumberGroups', ['result' => $numGroups]);
|
||||
|
||||
foreach ($aRegisteredGroups as $registeredGroup) {
|
||||
$count++;
|
||||
$arrayAux = groupSynchronizeUsers($plugin, $numGroups, $count, $registeredGroup);
|
||||
}
|
||||
|
||||
// Group - Print log
|
||||
$logResults = sprintf(
|
||||
"- Groups -> Existing users: %d, moved: %d, impossible: %d, created: %d, removed: %d",
|
||||
$GLOBALS['gAlready'],
|
||||
$GLOBALS['gMoved'],
|
||||
$GLOBALS['gImpossible'],
|
||||
$GLOBALS['gCreated'],
|
||||
$GLOBALS['gRemoved']
|
||||
);
|
||||
|
||||
$plugin->frontEndShow('TEXT', $logResults);
|
||||
|
||||
$plugin->log(null, $logResults);
|
||||
$context = [
|
||||
'existingUsers' => $GLOBALS['gAlready'],
|
||||
'moved' => $GLOBALS['gMoved'],
|
||||
'impossible' => $GLOBALS['gImpossible'],
|
||||
'created' => $GLOBALS['gCreated'],
|
||||
'removed' => $GLOBALS['gRemoved']
|
||||
];
|
||||
$plugin->stdLog(null, 'groups', $context);
|
||||
|
||||
// Manager
|
||||
$plugin->clearManager($GLOBALS['managersToClear']);
|
||||
|
||||
|
||||
if (isset($arrayAuthenticationSourceData['AUTH_SOURCE_DATA']['DEPARTMENTS_TO_UNASSIGN'])) {
|
||||
if (is_array($arrayAuthenticationSourceData['AUTH_SOURCE_DATA']['DEPARTMENTS_TO_UNASSIGN'])) {
|
||||
foreach ($arrayAuthenticationSourceData['AUTH_SOURCE_DATA']['DEPARTMENTS_TO_UNASSIGN'] as $departmentUID) {
|
||||
// Delete manager assignments
|
||||
$user = new User();
|
||||
$GLOBALS['deletedManager'] = $user->updateData(
|
||||
['USR_REPORTS_TO' => ''],
|
||||
['DEP_UID' => $departmentUID, ['USR_REPORTS_TO', '!=', '']]
|
||||
);
|
||||
|
||||
$rbacUsers = new RbacUsers();
|
||||
$totalRbacUsers = $rbacUsers->show(['conditions' => ['DEP_UID' => $departmentUID]]);
|
||||
$GLOBALS['dMoved'] += (int)$totalRbacUsers['total'];
|
||||
$rbacUsers->updateData(
|
||||
['DEP_UID' => ''],
|
||||
['DEP_UID' => $departmentUID]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
unset($arrayAuthenticationSourceData['AUTH_SOURCE_DATA']['DEPARTMENTS_TO_UNASSIGN']);
|
||||
|
||||
$rbac = RBAC::getSingleton();
|
||||
$rbac->authSourcesObj->update($arrayAuthenticationSourceData);
|
||||
}
|
||||
|
||||
if (isset($arrayAuthenticationSourceData['AUTH_SOURCE_DATA']['GROUPS_TO_UNASSIGN'])) {
|
||||
if (is_array($arrayAuthenticationSourceData['AUTH_SOURCE_DATA']['GROUPS_TO_UNASSIGN'])) {
|
||||
foreach ($arrayAuthenticationSourceData['AUTH_SOURCE_DATA']['GROUPS_TO_UNASSIGN'] as $groupUID) {
|
||||
$groupUser = new GroupUser();
|
||||
$dataGroupUser = $groupUser->show([
|
||||
'fields' => ['USR_UID'],
|
||||
'limit' => 1000,
|
||||
'conditions' => ['GRP_UID' => $groupUID]
|
||||
]);
|
||||
|
||||
$users = [];
|
||||
foreach ($dataGroupUser['data'] ?? [] as $user) {
|
||||
$users[] = $user['USR_UID'];
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$GLOBALS['deletedManager'] = $user->updateDataFromListUsersUids(
|
||||
['USR_REPORTS_TO' => ''],
|
||||
$users,
|
||||
[['USR_REPORTS_TO', '!=', '']]
|
||||
);
|
||||
|
||||
$GLOBALS['gMoved'] += $dataGroupUser['total'];
|
||||
|
||||
// Delete group assignments
|
||||
$groupUser = new GroupUser();
|
||||
$groupUser->removeGroupUser(['GRP_UID' => $groupUID]);
|
||||
}
|
||||
}
|
||||
|
||||
unset($arrayAuthenticationSourceData['AUTH_SOURCE_DATA']['GROUPS_TO_UNASSIGN']);
|
||||
|
||||
$rbac = RBAC::getSingleton();
|
||||
$rbac->authSourcesObj->update($arrayAuthenticationSourceData);
|
||||
}
|
||||
|
||||
|
||||
$rbacUsers = new RbacUsers();
|
||||
$rbacUsersData = $rbacUsers->show([
|
||||
'fields' => ['USR_AUTH_USER_DN'],
|
||||
'conditions' => [['USR_AUTH_USER_DN', '!=', '']]
|
||||
]);
|
||||
|
||||
$existingUsers = [];
|
||||
foreach ($rbacUsersData['data'] ?? [] as $usersData) {
|
||||
$existingUsers[] = $usersData['USR_AUTH_USER_DN'];
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['managersHierarchy'] as $managerDN => $subordinates) {
|
||||
if (!in_array($managerDN, $existingUsers)) {
|
||||
unset($GLOBALS['managersHierarchy'][$managerDN]);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the managers assigments counters
|
||||
$plugin->synchronizeManagers($GLOBALS['managersHierarchy']);
|
||||
|
||||
$deletedManagersAssignments = array_diff_assoc_recursive($GLOBALS['oldManagersHierarchy'], $GLOBALS['managersHierarchy']);
|
||||
$newManagersAssignments = array_diff_assoc_recursive($GLOBALS['managersHierarchy'], $GLOBALS['oldManagersHierarchy']);
|
||||
$deletedManagers = [];
|
||||
$newManagers = [];
|
||||
$movedManagers = [];
|
||||
|
||||
if (is_array($deletedManagersAssignments)) {
|
||||
foreach ($deletedManagersAssignments as $dn1 => $subordinates1) {
|
||||
foreach ($subordinates1 as $subordinate) {
|
||||
if (!in_array($subordinate, $deletedManagers)) {
|
||||
$deletedManagers[] = $subordinate;
|
||||
}
|
||||
|
||||
foreach ($newManagersAssignments as $dn2 => $subordinates2) {
|
||||
if (isset($subordinates2[$subordinate])) {
|
||||
$movedManagers[] = $subordinate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($newManagersAssignments)) {
|
||||
foreach ($newManagersAssignments as $dn1 => $subordinates1) {
|
||||
foreach ($subordinates1 as $subordinate) {
|
||||
if (!in_array($subordinate, $newManagers)) {
|
||||
$newManagers[] = $subordinate;
|
||||
}
|
||||
|
||||
foreach ($deletedManagersAssignments as $dn2 => $subordinates2) {
|
||||
if (isset($subordinates2[$subordinate])) {
|
||||
if (!in_array($subordinate, $movedManagers)) {
|
||||
$movedManagers[] = $subordinate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Print and log the users's information
|
||||
//Retired/Deactivated Users
|
||||
$logResults = sprintf("- Retired/Deactivated Users: %d", $GLOBALS['deletedRemoved']);
|
||||
|
||||
$plugin->frontEndShow('TEXT', $logResults);
|
||||
|
||||
$plugin->log(null, $logResults);
|
||||
$context = [
|
||||
'deletedRemoved' => $GLOBALS['deletedRemoved']
|
||||
];
|
||||
$plugin->stdLog(null, 'retired/deactivated users', $context);
|
||||
|
||||
if ($GLOBALS['deletedRemoved'] > 0) {
|
||||
$plugin->log(null, 'Retired/Deactivated Users: ');
|
||||
$plugin->log(null, $GLOBALS['deletedRemovedUsers']);
|
||||
$context = [
|
||||
'deletedRemovedUsers' => $GLOBALS['deletedRemovedUsers']
|
||||
];
|
||||
$plugin->stdLog(null, 'retired/deactivated users', $context);
|
||||
}
|
||||
|
||||
if ($GLOBALS['dAlready'] + $GLOBALS['gAlready'] > 0) {
|
||||
$plugin->log(null, 'Existing Users: ');
|
||||
$plugin->log(null, $GLOBALS['dAlreadyUsers'] . ' ' . $GLOBALS['gAlreadyUsers']);
|
||||
$context = [
|
||||
'dAlreadyUsers' => $GLOBALS['dAlreadyUsers'],
|
||||
'gAlreadyUsers' => $GLOBALS['gAlreadyUsers']
|
||||
];
|
||||
$plugin->stdLog(null, 'existing users', $context);
|
||||
}
|
||||
|
||||
if ($GLOBALS['dMoved'] + $GLOBALS['gMoved'] > 0) {
|
||||
$plugin->log(null, 'Moved Users: ');
|
||||
$plugin->log(null, $GLOBALS['dMovedUsers'] . ' ' . $GLOBALS['gMovedUsers']);
|
||||
$context = [
|
||||
'dMovedUsers' => $GLOBALS['dMovedUsers'],
|
||||
'gMovedUsers' => $GLOBALS['gMovedUsers']
|
||||
];
|
||||
$plugin->stdLog(null, 'moved users', $context);
|
||||
}
|
||||
|
||||
if ($GLOBALS['dImpossible'] + $GLOBALS['gImpossible'] > 0) {
|
||||
$plugin->log(null, 'Impossible Users: ');
|
||||
$plugin->log(null, $GLOBALS['dImpossibleUsers'] . ' ' . $GLOBALS['gImpossibleUsers']);
|
||||
$context = [
|
||||
'dImpossibleUsers' => $GLOBALS['dImpossibleUsers'],
|
||||
'gImpossibleUsers' => $GLOBALS['gImpossibleUsers']
|
||||
];
|
||||
$plugin->stdLog(null, 'impossible users', $context);
|
||||
}
|
||||
|
||||
if ($GLOBALS['dCreated'] + $GLOBALS['gCreated'] > 0) {
|
||||
$plugin->log(null, 'Created Users: ');
|
||||
$plugin->log(null, $GLOBALS['dCreatedUsers'] . ' ' . $GLOBALS['gCreatedUsers']);
|
||||
$context = [
|
||||
'dCreatedUsers' => $GLOBALS['dCreatedUsers'],
|
||||
'gCreatedUsers' => $GLOBALS['gCreatedUsers']
|
||||
];
|
||||
$plugin->stdLog(null, 'created users', $context);
|
||||
}
|
||||
|
||||
if ($GLOBALS['dRemoved'] + $GLOBALS['gRemoved'] > 0) {
|
||||
$plugin->log(null, 'Removed Users: ');
|
||||
$plugin->log(null, $GLOBALS['dRemovedUsers'] . ' ' . $GLOBALS['gRemovedUsers']);
|
||||
$context = [
|
||||
'dRemovedUsers' => $GLOBALS['dRemovedUsers'],
|
||||
'gRemovedUsers' => $GLOBALS['gRemovedUsers']
|
||||
];
|
||||
$plugin->stdLog(null, 'removed users', $context);
|
||||
}
|
||||
|
||||
//Print and log the managers assignments's information
|
||||
$logResults = sprintf(
|
||||
"- Managers assignments: created %d, moved %d, removed %d",
|
||||
count($newManagers) - count($movedManagers),
|
||||
count($movedManagers),
|
||||
count($deletedManagers) - count($movedManagers) + $GLOBALS['deletedManager']
|
||||
);
|
||||
|
||||
$plugin->frontEndShow('TEXT', $logResults);
|
||||
|
||||
$plugin->log(null, $logResults);
|
||||
$context = [
|
||||
'created' => count($newManagers) - count($movedManagers),
|
||||
'moved' => count($movedManagers),
|
||||
'removed' => count($deletedManagers) - count($movedManagers) + $GLOBALS['deletedManager']
|
||||
];
|
||||
$plugin->stdLog(null, 'managers assignments', $context);
|
||||
|
||||
// Update Users data based on the LDAP Server
|
||||
$plugin->stdLog(null, 'usersUpdateData', [$arrayAuthenticationSourceData['AUTH_SOURCE_UID']]);
|
||||
$result = $plugin->usersUpdateData($arrayAuthenticationSourceData['AUTH_SOURCE_UID']);
|
||||
$logResults = sprintf("- Deleted/Removed Users: %d", $result['countUserDeleted']);
|
||||
$plugin->frontEndShow('TEXT', $logResults);
|
||||
$plugin->log(null, $logResults);
|
||||
// Deactive Users
|
||||
$plugin->stdLog(null, 'deactiveArrayOfUsers', [$GLOBALS['usersRemovedOu']]);
|
||||
$plugin->deactiveArrayOfUsers($GLOBALS['usersRemovedOu']);
|
||||
} catch (Exception $e) {
|
||||
$plugin = new LdapSource();
|
||||
$message = $e->getMessage();
|
||||
$context = [
|
||||
'action' => 'ldapSynchronize',
|
||||
'authSource' => $arrayAuthenticationSourceData
|
||||
];
|
||||
$plugin->stdLog(null, $message, $context, 'error');
|
||||
Log::channel(':ldapSynchronize')->error($message, Bootstrap::context($context));
|
||||
}
|
||||
}
|
||||
|
||||
$plugin->frontEndShow('END');
|
||||
$plugin->debugLog('END');
|
||||
$plugin->stdLog(null, 'cron execution finalized');
|
||||
}
|
||||
|
||||
|
||||
|
||||
function departmentSynchronizeUsers($ldapAdvanced, $numDepartments, $count, array $arrayDepartmentData)
|
||||
{
|
||||
$plugin = new LdapSource();
|
||||
try {
|
||||
$ldapAdvanced->debugLog("ldapadvanced.php > function departmentSynchronizeUsers() > START");
|
||||
$ldapAdvanced->debugLog("ldapadvanced.php > function departmentSynchronizeUsers() > \$arrayDepartmentData ---->\n" . print_r($arrayDepartmentData, true));
|
||||
$plugin->stdLog(null, 'department synchronize users started', ['result' => $arrayDepartmentData]);
|
||||
|
||||
//Get users from ProcessMaker tables (for this Department)
|
||||
$ldapAdvanced->setArrayDepartmentUsers($arrayDepartmentData['DEP_UID']); //INITIALIZE DATA
|
||||
|
||||
//Clear the manager assignments
|
||||
$arrayUserUid = [];
|
||||
|
||||
foreach ($ldapAdvanced->arrayDepartmentUsersByUid as $user) {
|
||||
$arrayUserUid[] = $user['USR_UID'];
|
||||
|
||||
if (isset($user['USR_REPORTS_TO']) && $user['USR_REPORTS_TO'] != '') {
|
||||
$dn = (isset($ldapAdvanced->arrayAuthenticationSourceUsersByUid[$user['USR_REPORTS_TO']]['USR_AUTH_USER_DN']))? $ldapAdvanced->arrayAuthenticationSourceUsersByUid[$user['USR_REPORTS_TO']]['USR_AUTH_USER_DN'] : '';
|
||||
|
||||
if ($dn != '') {
|
||||
if (!isset($GLOBALS['oldManagersHierarchy'][$dn])) {
|
||||
$GLOBALS['oldManagersHierarchy'][$dn] = [];
|
||||
}
|
||||
$GLOBALS['oldManagersHierarchy'][$dn][$user['USR_UID']] = $user['USR_UID'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$GLOBALS['managersToClear'] = $arrayUserUid;
|
||||
|
||||
//Synchronize Users from Department
|
||||
//Now we need to go over ldapusers and check if the user exists in ldap but not in PM, then we need to create it
|
||||
$arrayData = array(
|
||||
'already' => $GLOBALS['dAlready'],
|
||||
'moved' => $GLOBALS['dMoved'],
|
||||
'impossible' => $GLOBALS['dImpossible'],
|
||||
'created' => $GLOBALS['dCreated'],
|
||||
'alreadyUsers' => $GLOBALS['dAlreadyUsers'],
|
||||
'movedUsers' => $GLOBALS['dMovedUsers'],
|
||||
'impossibleUsers' => $GLOBALS['dImpossibleUsers'],
|
||||
'createdUsers' => $GLOBALS['dCreatedUsers'],
|
||||
|
||||
'managersHierarchy' => $GLOBALS['managersHierarchy'],
|
||||
'arrayUserUid' => [],
|
||||
|
||||
'n' => $numDepartments,
|
||||
'i' => $count
|
||||
);
|
||||
|
||||
//Get Users from LDAP (for this Department)
|
||||
$arrayData = $ldapAdvanced->ldapGetUsersFromDepartment('SYNCHRONIZE', $arrayDepartmentData['DEP_LDAP_DN'], $arrayData);
|
||||
|
||||
$GLOBALS['dAlready'] = $arrayData['already'];
|
||||
$GLOBALS['dMoved'] = $arrayData['moved'];
|
||||
$GLOBALS['dImpossible'] = $arrayData['impossible'];
|
||||
$GLOBALS['dCreated'] = $arrayData['created'];
|
||||
$GLOBALS['dAlreadyUsers'] = $arrayData['alreadyUsers'];
|
||||
$GLOBALS['dMovedUsers'] = $arrayData['movedUsers'];
|
||||
$GLOBALS['dImpossibleUsers'] = $arrayData['impossibleUsers'];
|
||||
$GLOBALS['dCreatedUsers'] = $arrayData['createdUsers'];
|
||||
|
||||
$GLOBALS['managersHierarchy'] = $arrayData['managersHierarchy'];
|
||||
$arrayUserUid = $arrayData['arrayUserUid'];
|
||||
|
||||
//(D) Update Users
|
||||
$arrayAux = array_diff(array_keys($ldapAdvanced->arrayDepartmentUsersByUid), $arrayUserUid);
|
||||
|
||||
departmentRemoveUsers($arrayDepartmentData['DEP_UID'], $arrayAux);
|
||||
|
||||
$GLOBALS['dRemoved'] += count($arrayAux);
|
||||
$GLOBALS['dRemovedUsers'] = '';
|
||||
|
||||
$ldapAdvanced->debugLog("ldapadvanced.php > function departmentSynchronizeUsers() > END");
|
||||
$plugin->stdLog(null, 'department synchronize users finalized');
|
||||
|
||||
//Return all UID of Users synchronized in the Department (Return all UID of Users of this Department)
|
||||
return $arrayUserUid;
|
||||
} catch (Exception $e) {
|
||||
$plugin = new LdapSource();
|
||||
$message = $e->getMessage();
|
||||
$context = [
|
||||
'trace' => $e->getTrace()
|
||||
];
|
||||
$plugin->stdLog(null, $message, $context, 'error');
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function groupSynchronizeUsers($ldapAdvanced, $numGroups, $count, array $arrayGroupData)
|
||||
{
|
||||
$plugin = new LdapSource();
|
||||
try {
|
||||
$ldapAdvanced->debugLog("ldapadvanced.php > function groupSynchronizeUsers() > START");
|
||||
$ldapAdvanced->debugLog("ldapadvanced.php > function groupSynchronizeUsers() > \$arrayGroupData ---->\n" . print_r($arrayGroupData, true));
|
||||
$plugin->stdLog(null, 'group synchronize users started', ['result' => $arrayGroupData]);
|
||||
|
||||
//Get users from ProcessMaker tables (for this Group)
|
||||
$ldapAdvanced->setArrayGroupUsers($arrayGroupData['GRP_UID']); //INITIALIZE DATA
|
||||
|
||||
//Clear the manager assignments
|
||||
$arrayUserUid = [];
|
||||
|
||||
foreach ($ldapAdvanced->arrayGroupUsersByUid as $key => $user) {
|
||||
$arrayUserUid[] = $user['USR_UID'];
|
||||
|
||||
if (isset($user['USR_REPORTS_TO']) && $user['USR_REPORTS_TO'] != '') {
|
||||
$dn = (isset($ldapAdvanced->arrayAuthenticationSourceUsersByUid[$user['USR_REPORTS_TO']]['USR_AUTH_USER_DN']))? $ldapAdvanced->arrayAuthenticationSourceUsersByUid[$user['USR_REPORTS_TO']]['USR_AUTH_USER_DN'] : '';
|
||||
|
||||
if ($dn != '') {
|
||||
if (!isset($GLOBALS['oldManagersHierarchy'][$dn])) {
|
||||
$GLOBALS['oldManagersHierarchy'][$dn] = [];
|
||||
}
|
||||
|
||||
$GLOBALS['oldManagersHierarchy'][$dn][$user['USR_UID']] = $user['USR_UID'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$GLOBALS['managersToClear'] = array_merge($GLOBALS['managersToClear'], $arrayUserUid);
|
||||
|
||||
//Synchronize Users from Group
|
||||
//Now we need to go over ldapusers and check if the user exists in ldap but not in PM, then we need to create it
|
||||
$arrayData = array(
|
||||
'already' => $GLOBALS['gAlready'],
|
||||
'moved' => $GLOBALS['gMoved'],
|
||||
'impossible' => $GLOBALS['gImpossible'],
|
||||
'created' => $GLOBALS['gCreated'],
|
||||
'alreadyUsers' => $GLOBALS['gAlreadyUsers'],
|
||||
'movedUsers' => $GLOBALS['gMovedUsers'],
|
||||
'impossibleUsers' => $GLOBALS['gImpossibleUsers'],
|
||||
'createdUsers' => $GLOBALS['gCreatedUsers'],
|
||||
|
||||
'managersHierarchy' => $GLOBALS['managersHierarchy'],
|
||||
'arrayUserUid' => [],
|
||||
|
||||
'n' => $numGroups,
|
||||
'i' => $count
|
||||
);
|
||||
|
||||
//Get Users from LDAP (for this Group)
|
||||
$arrayData = $ldapAdvanced->ldapGetUsersFromGroup('SYNCHRONIZE', $arrayGroupData, $arrayData);
|
||||
|
||||
$GLOBALS['gAlready'] = $arrayData['already'];
|
||||
$GLOBALS['gMoved'] = $arrayData['moved'];
|
||||
$GLOBALS['gImpossible'] = $arrayData['impossible'];
|
||||
$GLOBALS['gCreated'] = $arrayData['created'];
|
||||
$GLOBALS['gAlreadyUsers'] = $arrayData['alreadyUsers'];
|
||||
$GLOBALS['gMovedUsers'] = $arrayData['movedUsers'];
|
||||
$GLOBALS['gImpossibleUsers'] = $arrayData['impossibleUsers'];
|
||||
$GLOBALS['gCreatedUsers'] = $arrayData['createdUsers'];
|
||||
|
||||
$GLOBALS['managersHierarchy'] = $arrayData['managersHierarchy'];
|
||||
$arrayUserUid = $arrayData['arrayUserUid'];
|
||||
|
||||
//(G) Update Users
|
||||
$arrayAux = array_diff(array_keys($ldapAdvanced->arrayGroupUsersByUid), $arrayUserUid);
|
||||
|
||||
groupRemoveUsers($arrayGroupData['GRP_UID'], $arrayAux);
|
||||
|
||||
$GLOBALS['gRemoved'] += count($arrayAux);
|
||||
$GLOBALS['gRemovedUsers'] = '';
|
||||
|
||||
$ldapAdvanced->debugLog("ldapadvanced.php > function groupSynchronizeUsers() > END");
|
||||
$plugin->stdLog(null, 'group synchronize users finalized');
|
||||
|
||||
//Return all UID of Users synchronized in the Group (Return all UID of Users of this Group)
|
||||
return $arrayUserUid;
|
||||
} catch (Exception $e) {
|
||||
$plugin = new LdapSource();
|
||||
$message = $e->getMessage();
|
||||
$context = [
|
||||
'trace' => $e->getTrace()
|
||||
];
|
||||
$plugin->stdLog(null, $message, $context, 'error');
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
function departmentRemoveUsers($departmentUid, array $arrayUserUid)
|
||||
{
|
||||
try {
|
||||
$department = new DepartmentModel();
|
||||
$department->Load($departmentUid);
|
||||
|
||||
$departmentManagerUid = $department->getDepManager();
|
||||
|
||||
foreach ($arrayUserUid as $value) {
|
||||
$userUid = $value;
|
||||
|
||||
$department->removeUserFromDepartment($departmentUid, $userUid);
|
||||
|
||||
if ($userUid == $departmentManagerUid) {
|
||||
$department->update(array('DEP_UID' => $departmentUid, 'DEP_MANAGER' => ''));
|
||||
|
||||
$department->updateDepartmentManager($departmentUid);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$plugin = new LdapSource();
|
||||
$message = $e->getMessage();
|
||||
$context = [
|
||||
'trace' => $e->getTrace()
|
||||
];
|
||||
$plugin->stdLog(null, $message, $context, 'error');
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
function groupRemoveUsers($groupUid, array $arrayUserUid)
|
||||
{
|
||||
try {
|
||||
$group = new Groups();
|
||||
|
||||
foreach ($arrayUserUid as $value) {
|
||||
$userUid = $value;
|
||||
|
||||
$group->removeUserOfGroup($groupUid, $userUid);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$plugin = new LdapSource();
|
||||
$message = $e->getMessage();
|
||||
$context = [
|
||||
'trace' => $e->getTrace()
|
||||
];
|
||||
$plugin->stdLog(null, $message, $context, 'error');
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function array_diff_assoc_recursive($array1, $array2)
|
||||
{
|
||||
foreach ($array1 as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
if (!isset($array2[$key])) {
|
||||
$difference[$key] = $value;
|
||||
} else {
|
||||
if (!is_array($array2[$key])) {
|
||||
$difference[$key] = $value;
|
||||
} else {
|
||||
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
|
||||
|
||||
if ($new_diff != false) {
|
||||
$difference[$key] = $new_diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isset($array2[$key]) || $array2[$key] != $value) {
|
||||
$difference[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (!isset($difference))? [] : $difference;
|
||||
}
|
||||
|
||||
|
||||
function initWorkspace($workspace) {
|
||||
define('SYS_SYS', $workspace);
|
||||
config(["system.workspace" => $workspace]);
|
||||
define('URL_KEY', config('app.key'));
|
||||
//PM Paths DATA
|
||||
define('PATH_DATA_SITE', PATH_DATA . 'sites/' . config("system.workspace") . '/');
|
||||
define('PATH_DOCUMENT', PATH_DATA_SITE . 'files/');
|
||||
define('PATH_DATA_MAILTEMPLATES', PATH_DATA_SITE . 'mailTemplates/');
|
||||
define('PATH_DATA_PUBLIC', PATH_DATA_SITE . 'public/');
|
||||
define('PATH_DATA_REPORTS', PATH_DATA_SITE . 'reports/');
|
||||
define('PATH_DYNAFORM', PATH_DATA_SITE . 'xmlForms/');
|
||||
define('PATH_IMAGES_ENVIRONMENT_FILES', PATH_DATA_SITE . 'usersFiles' . PATH_SEP);
|
||||
define('PATH_IMAGES_ENVIRONMENT_USERS', PATH_DATA_SITE . 'usersPhotographies' . PATH_SEP);
|
||||
|
||||
if (is_file(PATH_DATA_SITE . '.server_info')) {
|
||||
$SERVER_INFO = file_get_contents(PATH_DATA_SITE . PATH_SEP . '.server_info');
|
||||
$SERVER_INFO = unserialize($SERVER_INFO);
|
||||
|
||||
define('SERVER_NAME', $SERVER_INFO['SERVER_NAME']);
|
||||
define('SERVER_PORT', $SERVER_INFO['SERVER_PORT']);
|
||||
//to do improvement G::is_https()
|
||||
if ((isset($SERVER_INFO['HTTPS']) && $SERVER_INFO['HTTPS'] == 'on') ||
|
||||
(isset($SERVER_INFO['HTTP_X_FORWARDED_PROTO']) && $SERVER_INFO['HTTP_X_FORWARDED_PROTO'] == 'https')) {
|
||||
define('REQUEST_SCHEME', 'https');
|
||||
} else {
|
||||
define('REQUEST_SCHEME', $SERVER_INFO['REQUEST_SCHEME']);
|
||||
}
|
||||
} else {
|
||||
CLI::logging('WARNING! No server info found!', null, 'red');
|
||||
}
|
||||
//load Processmaker translations
|
||||
Bootstrap::LoadTranslationObject(SYS_LANG);
|
||||
|
||||
|
||||
//DB
|
||||
$phpCode = '';
|
||||
|
||||
$fileDb = fopen(PATH_DB . $workspace . PATH_SEP . 'db.php', 'r');
|
||||
|
||||
if ($fileDb) {
|
||||
while (!feof($fileDb)) {
|
||||
$buffer = fgets($fileDb, 4096); //Read a line
|
||||
|
||||
$phpCode .= preg_replace('/define\s*\(\s*[\x22\x27](.*)[\x22\x27]\s*,\s*(\x22.*\x22|\x27.*\x27)\s*\)\s*;/i', '$$1 = $2;', $buffer);
|
||||
}
|
||||
|
||||
fclose($fileDb);
|
||||
}
|
||||
|
||||
$phpCode = str_replace(['<?php', '<?', '?>'], ['', '', ''], $phpCode);
|
||||
|
||||
eval($phpCode);
|
||||
|
||||
$dsn = $DB_ADAPTER . '://' . $DB_USER . ':' . $DB_PASS . '@' . $DB_HOST . '/' . $DB_NAME;
|
||||
$dsnRbac = $DB_ADAPTER . '://' . $DB_RBAC_USER . ':' . $DB_RBAC_PASS . '@' . $DB_RBAC_HOST . '/' . $DB_RBAC_NAME;
|
||||
$dsnRp = $DB_ADAPTER . '://' . $DB_REPORT_USER . ':' . $DB_REPORT_PASS . '@' . $DB_REPORT_HOST . '/' . $DB_REPORT_NAME;
|
||||
|
||||
switch ($DB_ADAPTER) {
|
||||
case 'mysql':
|
||||
$dsn .= '?encoding=utf8';
|
||||
$dsnRbac .= '?encoding=utf8';
|
||||
break;
|
||||
case 'mssql':
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$pro = [];
|
||||
$pro['datasources']['workflow']['connection'] = $dsn;
|
||||
$pro['datasources']['workflow']['adapter'] = $DB_ADAPTER;
|
||||
$pro['datasources']['rbac']['connection'] = $dsnRbac;
|
||||
$pro['datasources']['rbac']['adapter'] = $DB_ADAPTER;
|
||||
$pro['datasources']['rp']['connection'] = $dsnRp;
|
||||
$pro['datasources']['rp']['adapter'] = $DB_ADAPTER;
|
||||
|
||||
Propel::initConfiguration($pro);
|
||||
|
||||
/**
|
||||
* Load Laravel database connection
|
||||
*/
|
||||
$dbHost = explode(':', $DB_HOST);
|
||||
config(['database.connections.workflow.host' => $dbHost[0]]);
|
||||
config(['database.connections.workflow.database' => $DB_NAME]);
|
||||
config(['database.connections.workflow.username' => $DB_USER]);
|
||||
config(['database.connections.workflow.password' => $DB_PASS]);
|
||||
if (count($dbHost) > 1) {
|
||||
config(['database.connections.workflow.port' => $dbHost[1]]);
|
||||
}
|
||||
|
||||
//Enable RBAC, We need to keep both variables in upper and lower case.
|
||||
$rbac = $RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$rbac->sSystem = 'PROCESSMAKER';
|
||||
|
||||
if (!defined('DB_ADAPTER')) {
|
||||
define('DB_ADAPTER', $DB_ADAPTER);
|
||||
}
|
||||
if (!defined('DB_HOST')) {
|
||||
define('DB_HOST', $DB_HOST);
|
||||
}
|
||||
if (!defined('DB_NAME')) {
|
||||
define('DB_NAME', $DB_NAME);
|
||||
}
|
||||
if (!defined('DB_USER')) {
|
||||
define('DB_USER', $DB_USER);
|
||||
}
|
||||
if (!defined('DB_PASS')) {
|
||||
define('DB_PASS', $DB_PASS);
|
||||
}
|
||||
if (!defined('DB_RBAC_HOST')) {
|
||||
define('DB_RBAC_HOST', $DB_RBAC_HOST);
|
||||
}
|
||||
if (!defined('DB_RBAC_NAME')) {
|
||||
define('DB_RBAC_NAME', $DB_RBAC_NAME);
|
||||
}
|
||||
if (!defined('DB_RBAC_USER')) {
|
||||
define('DB_RBAC_USER', $DB_RBAC_USER);
|
||||
}
|
||||
if (!defined('DB_RBAC_PASS')) {
|
||||
define('DB_RBAC_PASS', $DB_RBAC_PASS);
|
||||
}
|
||||
if (!defined('DB_REPORT_HOST')) {
|
||||
define('DB_REPORT_HOST', $DB_REPORT_HOST);
|
||||
}
|
||||
if (!defined('DB_REPORT_NAME')) {
|
||||
define('DB_REPORT_NAME', $DB_REPORT_NAME);
|
||||
}
|
||||
if (!defined('DB_REPORT_USER')) {
|
||||
define('DB_REPORT_USER', $DB_REPORT_USER);
|
||||
}
|
||||
if (!defined('DB_REPORT_PASS')) {
|
||||
define('DB_REPORT_PASS', $DB_REPORT_PASS);
|
||||
}
|
||||
if (!defined('SYS_SKIN')) {
|
||||
define('SYS_SKIN', $arraySystemConfiguration['default_skin']);
|
||||
}
|
||||
|
||||
$dateSystem = date('Y-m-d H:i:s');
|
||||
if (empty($now)) {
|
||||
$now = $dateSystem;
|
||||
}
|
||||
|
||||
//Processing
|
||||
CLI::logging('Processing workspace: ' . $workspace, null, 'green');
|
||||
|
||||
/**
|
||||
* JobsManager
|
||||
*/
|
||||
JobsManager::getSingleton()->init();
|
||||
}
|
||||
@@ -103,6 +103,7 @@ class CLI
|
||||
public static function help ($args, $opts = null)
|
||||
{
|
||||
global $argv;
|
||||
|
||||
$scriptName = $argv[0];
|
||||
if (is_array($args) && count($args) > 0 ) {
|
||||
$taskName = $args[0];
|
||||
@@ -202,10 +203,12 @@ EOT;
|
||||
CLI::taskName( "help" );
|
||||
CLI::taskRun( array ('self','help'
|
||||
) );
|
||||
|
||||
global $argv;
|
||||
$args = $argv;
|
||||
$cliname = array_shift( $args );
|
||||
$taskName = array_shift( $args );
|
||||
|
||||
if (isset($taskName[0])) {
|
||||
while ($taskName[0] == '-') {
|
||||
$taskName = array_shift( $args );
|
||||
@@ -345,7 +348,7 @@ EOT;
|
||||
* @param string $message the message to display
|
||||
* @param string $filename the log file to write messages
|
||||
*/
|
||||
public static function logging ($message, $filename = null)
|
||||
public static function logging($message, $filename = null, $color = null)
|
||||
{
|
||||
static $log_file = null;
|
||||
if (isset( $filename )) {
|
||||
@@ -355,7 +358,7 @@ EOT;
|
||||
if (isset( $log_file )) {
|
||||
fwrite( $log_file, $message );
|
||||
}
|
||||
echo $message;
|
||||
eprintln($message, $color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,8 @@
|
||||
|
||||
use ProcessMaker\Model\Process as ProcessModel;
|
||||
use ProcessMaker\Validation\ValidationUploadedFiles;
|
||||
use ProcessMaker\Core\System;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
//validate the data post
|
||||
if (!isset($_SESSION['USER_LOGGED'])) {
|
||||
@@ -115,6 +117,9 @@ try {
|
||||
exit();
|
||||
}
|
||||
|
||||
// Capture the original case data (before any modifications)
|
||||
$originalCaseData = $Fields['APP_DATA']; // this is the data that came from the DB
|
||||
|
||||
if ($swpmdynaform) {
|
||||
$dataFields = $Fields["APP_DATA"];
|
||||
$dataFields["CURRENT_DYNAFORM"] = $_GET['UID'];
|
||||
@@ -122,6 +127,9 @@ try {
|
||||
$oPmDynaform = new PmDynaform($dataFields);
|
||||
$pmdynaform = $oPmDynaform->validatePost($pmdynaform);
|
||||
|
||||
// get the keys of the fields defined on the form
|
||||
$keysDefinedOnForm = array_keys($pmdynaform);
|
||||
|
||||
$Fields["APP_DATA"] = array_merge( $Fields["APP_DATA"], $pmdynaform );
|
||||
}
|
||||
|
||||
@@ -280,8 +288,55 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
//Save files
|
||||
// Prepare data to send to external system
|
||||
|
||||
// Get the form data with values from the case
|
||||
$first = $originalCaseData; // original case data is the first array
|
||||
$second = $Fields['APP_DATA']; // array of fields with all modifications (form + triggers)
|
||||
|
||||
// get keys
|
||||
$keysFirst = array_keys($first);
|
||||
|
||||
// compute keys
|
||||
$bothKeys = array_values(array_intersect($keysFirst, $keysDefinedOnForm));
|
||||
$firstOnly = array_values(array_diff($keysFirst, $keysDefinedOnForm));
|
||||
$secondOnly = array_values(array_diff($keysDefinedOnForm, $keysFirst));
|
||||
|
||||
// compute items
|
||||
$bothItems = array_intersect_key($first, array_flip($bothKeys));
|
||||
$secondItems = array_intersect_key($second, array_flip($secondOnly));
|
||||
|
||||
// build "both" with both values (first and second)
|
||||
$formWithValues = [];
|
||||
foreach ($bothKeys as $k) {
|
||||
$formWithValues[$k] = [
|
||||
'old' => $first[$k],
|
||||
'new' => $second[$k],
|
||||
];
|
||||
}
|
||||
foreach ($secondOnly as $k) {
|
||||
$formWithValues[$k] = [
|
||||
'old' => null,
|
||||
'new' => $second[$k],
|
||||
];
|
||||
}
|
||||
// now $formWithValues has the new and old values of the fields defined in the form);
|
||||
|
||||
// Build the payload
|
||||
$payload = [
|
||||
'app_uid' => $_SESSION['APPLICATION'], // APP_UID
|
||||
'dyn_uid' => $_GET['UID'], // DYN_UID (form UID)
|
||||
'process_uid' => $_SESSION['PROCESS'], // PRO_UID
|
||||
'case_number' => $Fields['APP_NUMBER'], // optional
|
||||
'fields' => $formWithValues, // only fields defined in the form, with old and new values
|
||||
'modified_case' => $Fields['APP_DATA'], // after all field‑mapping logic
|
||||
'user_uid' => $_SESSION['USER_LOGGED'], // USER_UID
|
||||
'task_uid' => $_SESSION['TASK'], // TAS_UID
|
||||
];
|
||||
|
||||
send_case_data_to_external($payload);
|
||||
|
||||
//Save files
|
||||
if (isset( $_FILES["form"]["name"] ) && count( $_FILES["form"]["name"] ) > 0) {
|
||||
$oInputDocument = new \ProcessMaker\BusinessModel\Cases\InputDocument();
|
||||
$oInputDocument->uploadFileCase($_FILES, $oCase, $aData, $_SESSION["USER_LOGGED"], $_SESSION["APPLICATION"], $_SESSION["INDEX"]);
|
||||
@@ -374,3 +429,36 @@ try {
|
||||
G::RenderPage( 'publish', 'blank' );
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
function send_case_data_to_external( $payload ) {
|
||||
// send case data to external system
|
||||
$appUid = $_SESSION['APPLICATION'];
|
||||
$systemConfig = System::getSystemConfiguration('', '', config("system.workspace"));
|
||||
$caseDataHost = isset($systemConfig['case_data_host']) ? $systemConfig['case_data_host']: null;
|
||||
|
||||
if (empty($caseDataHost)) {
|
||||
// If no external endpoint is configured, just return
|
||||
return;
|
||||
}
|
||||
$message = '['.$appUid.'] Send case data to external service: '. $caseDataHost;
|
||||
Log::info( $message );
|
||||
|
||||
// Send it to the external endpoint
|
||||
$client = new \GuzzleHttp\Client();
|
||||
try {
|
||||
$response = $client->post($caseDataHost.'/api/'.SYS_SYS.'/receive_case', [
|
||||
'json' => $payload,
|
||||
'timeout' => 15, //15 s timeout
|
||||
]);
|
||||
|
||||
// Optional: log the response
|
||||
$log = json_decode((string)$response->getBody(), true);
|
||||
$message = "[".$appUid.'] External API response: ' . $log['status'] . ' - ' . $log['message'];
|
||||
Log::info( $message);
|
||||
} catch (\Exception $ex) {
|
||||
// If the external call fails you can decide whether to abort or just log
|
||||
$message = '['.$appUid.'] Could not notify external service: ' . $ex->getMessage();
|
||||
Log::error( $message );
|
||||
}
|
||||
}
|
||||
@@ -1,93 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* users_ViewPhoto.php
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2008 Colosa Inc.23
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*/
|
||||
if (($RBAC_Response = $RBAC->userCanAccess( "PM_LOGIN" )) != 1)
|
||||
|
||||
use ProcessMaker\Model\User;
|
||||
|
||||
if (($RBAC_Response = $RBAC->userCanAccess( "PM_LOGIN" )) != 1) {
|
||||
return $RBAC_Response;
|
||||
|
||||
$direction = PATH_IMAGES_ENVIRONMENT_USERS . $_REQUEST['pUID'] . ".gif";
|
||||
// header('Pragma: ');
|
||||
// header('Cache-Control: cache');
|
||||
|
||||
|
||||
if (! file_exists( $direction )) {
|
||||
$direction = PATH_HOME . 'public_html/images/user.gif';
|
||||
}
|
||||
G::sendHeaders( $direction );
|
||||
|
||||
DumpHeaders( $direction );
|
||||
|
||||
/*
|
||||
* This function is verified to work with Netscape and the *very latest*
|
||||
* version of IE. I don't know if it works with Opera, but it should now.
|
||||
*/
|
||||
function DumpHeaders ($filename)
|
||||
{
|
||||
|
||||
global $root_path;
|
||||
|
||||
if (! $filename)
|
||||
return;
|
||||
|
||||
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
|
||||
|
||||
$isIE = 0;
|
||||
|
||||
if (strstr( $HTTP_USER_AGENT, 'compatible; MSIE ' ) !== false && strstr( $HTTP_USER_AGENT, 'Opera' ) === false) {
|
||||
$isIE = 1;
|
||||
}
|
||||
|
||||
if (strstr( $HTTP_USER_AGENT, 'compatible; MSIE 6' ) !== false && strstr( $HTTP_USER_AGENT, 'Opera' ) === false) {
|
||||
$isIE6 = 1;
|
||||
}
|
||||
// Validate transversal path in pUID parameter
|
||||
$pUID = basename($_REQUEST['pUID']); // Elimina path traversal
|
||||
$pUID = preg_replace('/[^a-zA-Z0-9_-]/', '', $pUID); // Solo caracteres seguros
|
||||
|
||||
$aux = preg_replace( '[^-a-zA-Z0-9\.]', '_', $filename );
|
||||
$aux = explode( '_', $aux );
|
||||
$downloadName = $aux[count( $aux ) - 1];
|
||||
|
||||
if ($isIE && ! isset( $isIE6 )) {
|
||||
// http://support.microsoft.com/support/kb/articles/Q182/3/15.asp
|
||||
// Do not have quotes around filename, but that applied to
|
||||
// "attachment"... does it apply to inline too?
|
||||
|
||||
|
||||
// This combination seems to work mostly. IE 5.5 SP 1 has
|
||||
// known issues (see the Microsoft Knowledge Base)
|
||||
header( "Content-Disposition: inline; filename=$downloadName" );
|
||||
|
||||
// This works for most types, but doesn't work with Word files
|
||||
header( "Content-Type: application/download; name=\"$downloadName\"" );
|
||||
|
||||
//header("Content-Type: $type0/$type1; name=\"$downloadName\"");
|
||||
//header("Content-Type: application/x-msdownload; name=\"$downloadName\"");
|
||||
//header("Content-Type: application/octet-stream; name=\"$downloadName\"");
|
||||
if (empty($pUID)) {
|
||||
$filename = PATH_HOME . 'public_html/images/user.gif';
|
||||
} else {
|
||||
header( "Content-Disposition: attachment; filename=\"$downloadName\"" );
|
||||
header( "Content-Type: application/octet-stream; name=\"$downloadName\"" );
|
||||
$filename = PATH_IMAGES_ENVIRONMENT_USERS . $pUID . ".gif";
|
||||
}
|
||||
|
||||
//$filename = PATH_UPLOAD . "$filename";
|
||||
// Verify if user image exists, if not, try to get it by USR_UID, if still not found, use default user image
|
||||
if (!file_exists($filename)) {
|
||||
$user = new User();
|
||||
$filters = array(
|
||||
'limit' => 1,
|
||||
'fields' => ['USR_UID'],
|
||||
'conditions' => [['USR_ID', '=', $pUID]]
|
||||
);
|
||||
$result = $user->show($filters);
|
||||
if ($result['total'] == 1){
|
||||
$filename = PATH_IMAGES_ENVIRONMENT_USERS . $result['data'][0]['USR_UID'] . ".gif";
|
||||
if (!file_exists($filename)) {
|
||||
$filename = PATH_HOME . 'public_html/images/user.gif';
|
||||
}
|
||||
} else {
|
||||
$filename = PATH_HOME . 'public_html/images/user.gif';
|
||||
}
|
||||
}
|
||||
|
||||
// Verify if file exists, if not, return 404
|
||||
if (! file_exists( $filename )) {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Get file info
|
||||
$lastModified = filemtime($filename);
|
||||
$fileSize = filesize($filename);
|
||||
$etag = md5($fileSize . $lastModified . $filename);
|
||||
|
||||
header('Content-Type: image/gif');
|
||||
header('ETag: "' . $etag . '"');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
|
||||
header('Content-Length: ' . $fileSize);
|
||||
header('Cache-Control: public, must-revalidate, max-age=300'); // 5 min cache
|
||||
|
||||
// Validate Client eTAg
|
||||
$clientEtag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : '';
|
||||
if ($clientEtag === '"' . $etag . '"') {
|
||||
header('HTTP/1.1 304 Not Modified');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Show image
|
||||
readfile($filename);
|
||||
}
|
||||
|
||||
//G::header2( "location: /files/" .$_SESSION['ENVIRONMENT']. "/" .$appid, $filename);
|
||||
|
||||
exit();
|
||||
|
||||
@@ -35,11 +35,11 @@ class Department extends Model
|
||||
try {
|
||||
$query = static::query();
|
||||
|
||||
if (is_array($filters['fields'])) {
|
||||
if (!empty($filters['fields']) && is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (is_array($filters['conditions'])) {
|
||||
if (!empty($filters['conditions']) && is_array($filters['conditions'])) {
|
||||
if (!empty($filters['conditions']['text'])) {
|
||||
$query->where('DEP_TITLE', 'like', '%' . $filters['conditions']['text'] . '%');
|
||||
unset($filters['conditions']['text']);
|
||||
@@ -49,13 +49,13 @@ class Department extends Model
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if (is_array($filters['start']) || is_array($filters['limit'])) {
|
||||
if ((!empty($filters['start']) && is_array($filters['start'])) || (!empty($filters['limit']) && is_array($filters['limit']))) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (is_array($filters['orderBy'])) {
|
||||
if (!empty($filters['orderBy']) && is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
|
||||
@@ -133,4 +133,86 @@ class GroupUser extends Model
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function show($filters = array())
|
||||
{
|
||||
try {
|
||||
$query = static::query();
|
||||
|
||||
if (!empty($filters['fields']) && is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (!empty($filters['conditions']) && is_array($filters['conditions'])) {
|
||||
$query->where($filters['conditions']);
|
||||
}
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if ((!empty($filters['start']) && is_array($filters['start'])) || (!empty($filters['limit']) && is_array($filters['limit']))) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (!empty($filters['orderBy']) && is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
$data =$query->get()->toArray();
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $data
|
||||
];
|
||||
return $result;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUsersByGroupId($filters = [])
|
||||
{
|
||||
$query = static::query();
|
||||
|
||||
if (!empty($filters['fields']) && is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (!empty($filters['conditions']) && is_array($filters['conditions'])) {
|
||||
$query->where($filters['conditions']);
|
||||
}
|
||||
|
||||
$query->leftJoin('USERS', 'GROUP_USER.USR_UID', '=', 'USERS.USR_UID');
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if ((!empty($filters['start']) && is_array($filters['start'])) || (!empty($filters['limit']) && is_array($filters['limit']))) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (!empty($filters['orderBy']) && is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
$data =$query->get()->toArray();
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $data
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function removeGroupUser($conditions)
|
||||
{
|
||||
try {
|
||||
$responseSave = GroupUser::where($conditions)
|
||||
->delete();
|
||||
|
||||
return $responseSave;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ class Groupwf extends Model
|
||||
try {
|
||||
$query = static::query();
|
||||
|
||||
if (is_array($filters['fields'])) {
|
||||
if (!empty($filters['fields']) && is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (is_array($filters['conditions'])) {
|
||||
if (!empty($filters['conditions']) && is_array($filters['conditions'])) {
|
||||
if (!empty($filters['conditions']['text'])) {
|
||||
$query->where('GRP_TITLE', 'like', '%' . $filters['conditions']['text'] . '%');
|
||||
unset($filters['conditions']['text']);
|
||||
@@ -44,13 +44,13 @@ class Groupwf extends Model
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if (is_array($filters['start']) || is_array($filters['limit'])) {
|
||||
if ((!empty($filters['start']) && is_array($filters['start'])) || (!empty($filters['limit']) && is_array($filters['limit']))) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (is_array($filters['orderBy'])) {
|
||||
if (!empty($filters['orderBy']) && is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
|
||||
@@ -34,11 +34,11 @@ class RbacAuthenticationSource extends Model
|
||||
try {
|
||||
$query = static::query();
|
||||
|
||||
if (is_array($filters['fields'])) {
|
||||
if (!empty($filters['fields']) && is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (is_array($filters['conditions'])) {
|
||||
if (!empty($filters['conditions']) && is_array($filters['conditions'])) {
|
||||
if (!empty($filters['conditions']['text'])) {
|
||||
$query->where('AUTH_SOURCE_NAME', 'like', '%' . $filters['conditions']['text'] . '%');
|
||||
unset($filters['conditions']['text']);
|
||||
@@ -48,13 +48,13 @@ class RbacAuthenticationSource extends Model
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if (is_array($filters['start']) || is_array($filters['limit'])) {
|
||||
if ((!empty($filters['start']) && is_array($filters['start'])) || (!empty($filters['limit']) && is_array($filters['limit']))) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (is_array($filters['orderBy'])) {
|
||||
if (!empty($filters['orderBy']) && is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
|
||||
@@ -20,23 +20,23 @@ class RbacUsers extends Model
|
||||
try {
|
||||
$query = static::query();
|
||||
|
||||
if (is_array($filters['fields'])) {
|
||||
if (!empty($filters['fields']) && is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (is_array($filters['conditions'])) {
|
||||
if (!empty($filters['conditions']) && is_array($filters['conditions'])) {
|
||||
$query->where($filters['conditions']);
|
||||
}
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if (is_array($filters['start']) || is_array($filters['limit'])) {
|
||||
if ((!empty($filters['start']) && is_array($filters['start'])) || (!empty($filters['limit']) && is_array($filters['limit']))) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (is_array($filters['orderBy'])) {
|
||||
if (!empty($filters['orderBy']) && is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
@@ -96,6 +96,17 @@ class RbacUsers extends Model
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateDataFromListUsersUids($userData, $usersUids = [])
|
||||
{
|
||||
try {
|
||||
$responseSave = self::whereIn('USR_UID', $usersUids)
|
||||
->update($userData);
|
||||
return $responseSave;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if username exists
|
||||
*
|
||||
|
||||
@@ -18,6 +18,79 @@ class User extends Model
|
||||
// Our custom timestamp columns
|
||||
const CREATED_AT = 'USR_CREATE_DATE';
|
||||
const UPDATED_AT = 'USR_UPDATE_DATE';
|
||||
public function show($filters = array())
|
||||
{
|
||||
try {
|
||||
$query = static::query();
|
||||
|
||||
if (!empty($filters['fields']) && is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (!empty($filters['conditions']) && is_array($filters['conditions'])) {
|
||||
$query->where($filters['conditions']);
|
||||
}
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if ((!empty($filters['start']) && is_array($filters['start'])) || (!empty($filters['limit']) && is_array($filters['limit']))) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (!empty($filters['orderBy']) && is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
$data =$query->get()->toArray();
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $data
|
||||
];
|
||||
return $result;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function getByListUids($listUids, $filters = array())
|
||||
{
|
||||
try {
|
||||
$query = static::query();
|
||||
|
||||
if (!empty($filters['fields']) && is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (!empty($filters['conditions']) && is_array($filters['conditions'])) {
|
||||
$query->where($filters['conditions']);
|
||||
}
|
||||
|
||||
$query->whereIn('USR_UID', $listUids);
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if ((!empty($filters['start']) && is_array($filters['start'])) || (!empty($filters['limit']) && is_array($filters['limit']))) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (!empty($filters['orderBy']) && is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
$data =$query->get()->toArray();
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $data
|
||||
];
|
||||
return $result;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the delegations this user has (all of them)
|
||||
@@ -317,4 +390,31 @@ class User extends Model
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function updateData($userData, $conditions = [])
|
||||
{
|
||||
try {
|
||||
$responseSave = self::where($conditions)
|
||||
->update($userData);
|
||||
return $responseSave;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateDataFromListUsersUids($userData, $usersUids = [], $extraConditions = [])
|
||||
{
|
||||
try {
|
||||
$query = self::whereIn('USR_UID', $usersUids);
|
||||
|
||||
if (!empty($extraConditions) && is_array($extraConditions)) {
|
||||
$query->where($extraConditions);
|
||||
}
|
||||
|
||||
$responseSave = $query->update($userData);
|
||||
return $responseSave;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user