Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberroland committed Oct 12, 2023
1 parent c3bd3c1 commit 72f0ccf
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 49 deletions.
6 changes: 3 additions & 3 deletions lam/lib/baseModule.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1268,10 +1268,10 @@ abstract class baseModule {
* <br>
* It allows additional LDAP changes when an account is deleted.
*
* @return List of LDAP operations, same as for save_attributes()
* @return array of LDAP operations, same as for save_attributes()
*/
public function delete_attributes() {
return 0;
public function delete_attributes(): array {
return [];
}

/**
Expand Down
15 changes: 7 additions & 8 deletions lam/lib/modules/nisNetGroupUser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,17 @@ class nisNetGroupUser extends baseModule {
}

/**
* Additional LDAP operations on delete.
*
* @return List of LDAP operations, same as for save_attributes()
*/
function delete_attributes() {
* {@inheritDoc}
* @see baseModule::delete_attributes()
*/
function delete_attributes(): array {
$uid = $this->getUid();
if (empty($uid)) {
return array();
return [];
}
$return = array();
$return = [];
// remove from NIS netgroups
$changes = array();
$changes = [];
foreach ($this->groups as $group) {
$changes[$group['dn']][] = $this->createNetGroupValue($group, $uid);
}
Expand Down
11 changes: 5 additions & 6 deletions lam/lib/modules/posixAccount.inc
Original file line number Diff line number Diff line change
Expand Up @@ -998,12 +998,11 @@ class posixAccount extends baseModule implements passwordService,AccountStatusPr
}

/**
* Additional LDAP operations on delete.
*
* @return List of LDAP operations, same as for save_attributes()
*/
function delete_attributes() {
$return = array();
* {@inheritDoc}
* @see baseModule::delete_attributes()
*/
function delete_attributes(): array {
$return = [];
// remove memberUids if set
$groups = searchLDAPByAttribute('memberUid', $this->attributes['uid'][0], 'posixGroup', array('dn'), array('group'));
for ($i = 0; $i < sizeof($groups); $i++) {
Expand Down
11 changes: 5 additions & 6 deletions lam/lib/modules/posixGroup.inc
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ class posixGroup extends baseModule implements passwordService {
}

/**
* Checks if the group which should be deleted is still used as primary group.
*
* @return List of LDAP operations, same as for save_attributes()
*/
function delete_attributes() {
$return = array();
* {@inheritDoc}
* @see baseModule::delete_attributes()
*/
function delete_attributes(): array {
$return = [];
$result = searchLDAPByFilter('(&(objectClass=posixAccount)(gidNumber=' . $this->attributes['gidNumber'][0] . '))', array('dn'), array('user', 'host'));
if (sizeof($result) > 0) {
$max = 5;
Expand Down
26 changes: 12 additions & 14 deletions lam/templates/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,18 @@
foreach ($moduleNames as $singlemodule) {
// load changes
$temp = $modules[$singlemodule]->delete_attributes();
if (is_array($temp)) {
// merge changes
$DNs = array_keys($temp);
$attributes = array_merge_recursive($temp, $attributes);
foreach ($DNs as $dn) {
$ops = array_keys($temp[$dn]);
foreach ($ops as $op) {
$attrs = array_keys($temp[$dn][$op]);
foreach ($attrs as $attribute) {
$attributes[$dn][$op][$attribute] = array_unique($attributes[$dn][$op][$attribute]);
}
}
}
}
// merge changes
$DNs = array_keys($temp);
$attributes = array_merge_recursive($temp, $attributes);
foreach ($DNs as $dn) {
$ops = array_keys($temp[$dn]);
foreach ($ops as $op) {
$attrs = array_keys($temp[$dn][$op]);
foreach ($attrs as $attribute) {
$attributes[$dn][$op][$attribute] = array_unique($attributes[$dn][$op][$attribute]);
}
}
}
}
$DNs = array_keys($attributes);
foreach ($DNs as $dn) {
Expand Down
22 changes: 10 additions & 12 deletions lam/templates/tools/multiEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,18 +479,16 @@ function dryRun(): array {
$tempFilesManager = new LamTemporaryFilesManager();
$fileName = $tempFilesManager->registerTemporaryFile('.ldif', 'ldif_');
$out = $tempFilesManager->openTemporaryFileForWrite($fileName);
if ($out !== false) {
fwrite($out, $ldif);
$container->addElement(new htmlOutputText(_('LDIF file')), true);
$ldifLink = new htmlLink($fileName, $tempFilesManager->getDownloadLink($fileName));
$ldifLink->setTargetWindow('_blank');
$container->addElement($ldifLink, true);
$container->addVerticalSpace('20px');
$container->addElement(new htmlOutputText(_('Log output')), true);
$container->addElement(new htmlInputTextarea('log', $log, 100, 30), true);
// generate HTML
fclose ($out);
}
fwrite($out, $ldif);
$container->addElement(new htmlOutputText(_('LDIF file')), true);
$ldifLink = new htmlLink($fileName, $tempFilesManager->getDownloadLink($fileName));
$ldifLink->setTargetWindow('_blank');
$container->addElement($ldifLink, true);
$container->addVerticalSpace('20px');
$container->addElement(new htmlOutputText(_('Log output')), true);
$container->addElement(new htmlInputTextarea('log', $log, 100, 30), true);
// generate HTML
fclose ($out);
ob_start();
parseHtml(null, $container, array(), true, 'user');
$content = ob_get_contents();
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
Expand Down

0 comments on commit 72f0ccf

Please sign in to comment.