added upload preactions

This commit is contained in:
Roland Gruber 2012-10-06 16:37:36 +00:00
parent f77f350a8c
commit 59ba19c292
5 changed files with 72 additions and 14 deletions

View File

@ -1 +1 @@
3.9 3.9.1

View File

@ -14,6 +14,7 @@
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"><title>Upgrade notes</title> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"><title>Upgrade notes</title>
@ -30,7 +31,15 @@ This is a list of API changes for all LAM releases.
<br> <br>
<h2>3.8 -&gt; 3.9</h2>Module interface:<br> <h2>3.9 -&gt; 4.0</h2>Module interface:<br>
<ul>
<li>new function: <span style="font-weight: bold;">doUploadPreActions()</span></li>
<li>function <span style="font-weight: bold;">doUploadPostActions() </span>contains attributes by reference<span style="font-weight: bold;"><br>
</span></li>
</ul>
<br>
<h2>3.8 -&gt; 3.9</h2>
Module interface:<br>
<ul> <ul>
<li>new function <span style="font-weight: bold;">supportsAdminInterface()</span>: Can be used to mark modules that only support the self service.</li> <li>new function <span style="font-weight: bold;">supportsAdminInterface()</span>: Can be used to mark modules that only support the self service.</li>

View File

@ -974,6 +974,16 @@ abstract class baseModule {
return "enabled"; return "enabled";
} }
/**
* Runs any actions that need to be done before an LDAP entry is created.
*
* @param array $attributes LDAP attributes of this entry (attributes are provided as reference, handle modifications of $attributes with care)
* @return array array which contains status messages. Each entry is an array containing the status message parameters.
*/
public function doUploadPreActions($attributes) {
return array();
}
/** /**
* This function is responsible to do additional tasks after the account has been created in LDAP (e.g. modifying group memberships, adding Quota etc..). * This function is responsible to do additional tasks after the account has been created in LDAP (e.g. modifying group memberships, adding Quota etc..).
* *
@ -1036,7 +1046,7 @@ abstract class baseModule {
* The modification is aborted if an error message is returned. * The modification is aborted if an error message is returned.
* *
* @param boolean $newAccount new account * @param boolean $newAccount new account
* @param array $attributes LDAP attributes of this entry * @param array $attributes LDAP attributes of this entry (added/modified attributes are provided as reference, handle modifications of $attributes with care)
* @return array array which contains status messages. Each entry is an array containing the status message parameters. * @return array array which contains status messages. Each entry is an array containing the status message parameters.
*/ */
public function preModifyActions($newAccount, $attributes) { public function preModifyActions($newAccount, $attributes) {

View File

@ -490,6 +490,24 @@ function buildUploadAccounts($scope, $data, $ids, $selectedModules) {
else return $partialAccounts; else return $partialAccounts;
} }
/**
* Runs any actions that need to be done before an LDAP entry is created.
*
* @param String $scope account type
* @param array $selectedModules list of selected account modules
* @param array $attributes LDAP attributes of this entry (attributes are provided as reference, handle modifications of $attributes with care)
* @return array array which contains status messages. Each entry is an array containing the status message parameters.
*/
function doUploadPreActions($scope, $selectedModules, $attributes) {
$messages = array();
for ($i = 0; $i < sizeof($selectedModules); $i++) {
$activeModule = $selectedModules[$i];
$module = new $activeModule($scope);
$messages = array_merge($messages, $module->doUploadPreActions($attributes));
}
return $messages;
}
/** /**
* This function executes one post upload action. * This function executes one post upload action.
* *
@ -1658,13 +1676,17 @@ class accountContainer {
$prePostModifyAttributes = array_merge($prePostModifyAttributes, $attributes[$this->finalDN]['notchanged']); $prePostModifyAttributes = array_merge($prePostModifyAttributes, $attributes[$this->finalDN]['notchanged']);
} }
if (isset($attributes[$this->finalDN]['modify'])) { if (isset($attributes[$this->finalDN]['modify'])) {
$prePostModifyAttributes = array_merge($prePostModifyAttributes, $attributes[$this->finalDN]['modify']); foreach ($attributes[$this->finalDN]['modify'] as $key => $value) {
$prePostModifyAttributes[$key] = &$attributes[$this->finalDN]['modify'][$key];
}
foreach ($attributes[$this->finalDN]['modify'] as $key => $value) { foreach ($attributes[$this->finalDN]['modify'] as $key => $value) {
$prePostModifyAttributes['MOD.' . $key] = $value; $prePostModifyAttributes['MOD.' . $key] = $value;
} }
} }
if (isset($attributes[$this->finalDN]['add'])) { if (isset($attributes[$this->finalDN]['add'])) {
$prePostModifyAttributes = array_merge($prePostModifyAttributes, $attributes[$this->finalDN]['add']); foreach ($attributes[$this->finalDN]['add'] as $key => $value) {
$prePostModifyAttributes[$key] = &$attributes[$this->finalDN]['add'][$key];
}
foreach ($attributes[$this->finalDN]['add'] as $key => $value) { foreach ($attributes[$this->finalDN]['add'] as $key => $value) {
$prePostModifyAttributes['NEW.' . $key] = $value; $prePostModifyAttributes['NEW.' . $key] = $value;
} }

View File

@ -98,15 +98,32 @@ if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_po
unset($attrs[$key]); unset($attrs[$key]);
} }
} }
$success = @ldap_add($_SESSION['ldap']->server(), $dn, $attrs); // run preactions
if (!$success) { $preAttributes = array();
$errorMessage = array( foreach ($attrs as $key => $value) {
"ERROR", $preAttributes[$key] = &$attrs[$key];
_("LAM was unable to create account %s! An LDAP error occured."), }
ldap_errno($_SESSION['ldap']->server()) . ": " . ldap_error($_SESSION['ldap']->server()), $preAttributes['dn'] = &$dn;
array($_SESSION['mass_counter'])); $preMessages = doUploadPreActions($scope, $_SESSION['mass_selectedModules'], $preAttributes);
$_SESSION['mass_errors'][] = $errorMessage; $preActionOk = true;
$_SESSION['mass_failed'][] = $_SESSION['mass_counter']; for ($i = 0; $i < sizeof($preMessages); $i++) {
if (($preMessages[$i][0] == 'ERROR') || ($preMessages[$i][0] == 'WARN')) {
$preActionOk = false;
$_SESSION['mass_errors'][] = $preMessages[$i];
}
}
if ($preActionOk) {
// add LDAP entry
$success = @ldap_add($_SESSION['ldap']->server(), $dn, $attrs);
if (!$success) {
$errorMessage = array(
"ERROR",
_("LAM was unable to create account %s! An LDAP error occured."),
ldap_errno($_SESSION['ldap']->server()) . ": " . ldap_error($_SESSION['ldap']->server()),
array($_SESSION['mass_counter']));
$_SESSION['mass_errors'][] = $errorMessage;
$_SESSION['mass_failed'][] = $_SESSION['mass_counter'];
}
} }
$_SESSION['mass_counter']++; $_SESSION['mass_counter']++;
} }