refactoring

This commit is contained in:
Roland Gruber 2023-10-12 07:59:09 +02:00
parent c3bd3c1762
commit 72f0ccf488
7 changed files with 43 additions and 49 deletions

View file

@ -1268,10 +1268,10 @@ abstract class baseModule {
* <br> * <br>
* It allows additional LDAP changes when an account is deleted. * 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() { public function delete_attributes(): array {
return 0; return [];
} }
/** /**

View file

@ -386,18 +386,17 @@ class nisNetGroupUser extends baseModule {
} }
/** /**
* Additional LDAP operations on delete. * {@inheritDoc}
* * @see baseModule::delete_attributes()
* @return List of LDAP operations, same as for save_attributes() */
*/ function delete_attributes(): array {
function delete_attributes() {
$uid = $this->getUid(); $uid = $this->getUid();
if (empty($uid)) { if (empty($uid)) {
return array(); return [];
} }
$return = array(); $return = [];
// remove from NIS netgroups // remove from NIS netgroups
$changes = array(); $changes = [];
foreach ($this->groups as $group) { foreach ($this->groups as $group) {
$changes[$group['dn']][] = $this->createNetGroupValue($group, $uid); $changes[$group['dn']][] = $this->createNetGroupValue($group, $uid);
} }

View file

@ -998,12 +998,11 @@ class posixAccount extends baseModule implements passwordService,AccountStatusPr
} }
/** /**
* Additional LDAP operations on delete. * {@inheritDoc}
* * @see baseModule::delete_attributes()
* @return List of LDAP operations, same as for save_attributes() */
*/ function delete_attributes(): array {
function delete_attributes() { $return = [];
$return = array();
// remove memberUids if set // remove memberUids if set
$groups = searchLDAPByAttribute('memberUid', $this->attributes['uid'][0], 'posixGroup', array('dn'), array('group')); $groups = searchLDAPByAttribute('memberUid', $this->attributes['uid'][0], 'posixGroup', array('dn'), array('group'));
for ($i = 0; $i < sizeof($groups); $i++) { for ($i = 0; $i < sizeof($groups); $i++) {

View file

@ -164,12 +164,11 @@ class posixGroup extends baseModule implements passwordService {
} }
/** /**
* Checks if the group which should be deleted is still used as primary group. * {@inheritDoc}
* * @see baseModule::delete_attributes()
* @return List of LDAP operations, same as for save_attributes() */
*/ function delete_attributes(): array {
function delete_attributes() { $return = [];
$return = array();
$result = searchLDAPByFilter('(&(objectClass=posixAccount)(gidNumber=' . $this->attributes['gidNumber'][0] . '))', array('dn'), array('user', 'host')); $result = searchLDAPByFilter('(&(objectClass=posixAccount)(gidNumber=' . $this->attributes['gidNumber'][0] . '))', array('dn'), array('user', 'host'));
if (sizeof($result) > 0) { if (sizeof($result) > 0) {
$max = 5; $max = 5;

View file

@ -229,20 +229,18 @@ if (isset($_POST['delete'])) {
foreach ($moduleNames as $singlemodule) { foreach ($moduleNames as $singlemodule) {
// load changes // load changes
$temp = $modules[$singlemodule]->delete_attributes(); $temp = $modules[$singlemodule]->delete_attributes();
if (is_array($temp)) { // merge changes
// merge changes $DNs = array_keys($temp);
$DNs = array_keys($temp); $attributes = array_merge_recursive($temp, $attributes);
$attributes = array_merge_recursive($temp, $attributes); foreach ($DNs as $dn) {
foreach ($DNs as $dn) { $ops = array_keys($temp[$dn]);
$ops = array_keys($temp[$dn]); foreach ($ops as $op) {
foreach ($ops as $op) { $attrs = array_keys($temp[$dn][$op]);
$attrs = array_keys($temp[$dn][$op]); foreach ($attrs as $attribute) {
foreach ($attrs as $attribute) { $attributes[$dn][$op][$attribute] = array_unique($attributes[$dn][$op][$attribute]);
$attributes[$dn][$op][$attribute] = array_unique($attributes[$dn][$op][$attribute]); }
} }
} }
}
}
} }
$DNs = array_keys($attributes); $DNs = array_keys($attributes);
foreach ($DNs as $dn) { foreach ($DNs as $dn) {

View file

@ -479,18 +479,16 @@ function dryRun(): array {
$tempFilesManager = new LamTemporaryFilesManager(); $tempFilesManager = new LamTemporaryFilesManager();
$fileName = $tempFilesManager->registerTemporaryFile('.ldif', 'ldif_'); $fileName = $tempFilesManager->registerTemporaryFile('.ldif', 'ldif_');
$out = $tempFilesManager->openTemporaryFileForWrite($fileName); $out = $tempFilesManager->openTemporaryFileForWrite($fileName);
if ($out !== false) { fwrite($out, $ldif);
fwrite($out, $ldif); $container->addElement(new htmlOutputText(_('LDIF file')), true);
$container->addElement(new htmlOutputText(_('LDIF file')), true); $ldifLink = new htmlLink($fileName, $tempFilesManager->getDownloadLink($fileName));
$ldifLink = new htmlLink($fileName, $tempFilesManager->getDownloadLink($fileName)); $ldifLink->setTargetWindow('_blank');
$ldifLink->setTargetWindow('_blank'); $container->addElement($ldifLink, true);
$container->addElement($ldifLink, true); $container->addVerticalSpace('20px');
$container->addVerticalSpace('20px'); $container->addElement(new htmlOutputText(_('Log output')), true);
$container->addElement(new htmlOutputText(_('Log output')), true); $container->addElement(new htmlInputTextarea('log', $log, 100, 30), true);
$container->addElement(new htmlInputTextarea('log', $log, 100, 30), true); // generate HTML
// generate HTML fclose ($out);
fclose ($out);
}
ob_start(); ob_start();
parseHtml(null, $container, array(), true, 'user'); parseHtml(null, $container, array(), true, 'user');
$content = ob_get_contents(); $content = ob_get_contents();

View file

@ -1,6 +1,7 @@
<?php <?php
use Rector\Config\RectorConfig; use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList; use Rector\Set\ValueObject\SetList;
return static function (RectorConfig $rectorConfig): void { return static function (RectorConfig $rectorConfig): void {