added post upload actions

This commit is contained in:
Roland Gruber 2004-10-19 18:18:46 +00:00
parent 46e5af15ef
commit 4638db3d33
5 changed files with 104 additions and 3 deletions

View File

@ -507,8 +507,29 @@ class baseModule {
}
}
/**
* This function executes one post upload action.
*
* @param array $data array containing one account in each element
* @param array $ids array(<column_name> => <column number>)
* @param array $failed list of accounts which were not created successfully
* @param array $temp variable to store temporary data between two post actions
* @return array current status
* <br> array (
* <br> 'status' => 'finished' | 'inProgress'
* <br> 'progress' => 0..100
* <br> 'errors' => array (<array of parameters for StatusMessage>)
* <br> )
*/
function doUploadPostActions($data, $ids, $failed, &$temp) {
return array(
'status' => 'finished',
'progress' => 100,
'errors' => array()
);
}
}
?>

View File

@ -479,6 +479,53 @@ function buildUploadAccounts($scope, $data, $ids) {
else return $partialAccounts;
}
/**
* This function executes one post upload action.
*
* @param string $scope account type
* @param array $data array containing one account in each element
* @param array $ids array(<column_name> => <column number>)
* @param array $failed list of accounts which were not created successfully
* @return array current status
* <br> array (
* <br> 'status' => 'finished' | 'inProgress'
* <br> 'module' => <name of active module>
* <br> 'progress' => 0..100
* <br> 'errors' => array (<array of parameters for StatusMessage>)
* <br> )
*/
function doUploadPostActions($scope, $data, $ids, $failed) {
// check if function is called the first time
if (! isset($_SESSION['mass_postActions']['remainingModules'])) {
// make list of remaining modules
$moduleList = $_SESSION['config']->get_AccountModules($scope);
$_SESSION['mass_postActions']['remainingModules'] = $moduleList;
}
$activeModule = $_SESSION['mass_postActions']['remainingModules'][0];
// initialize temporary variable
if (!isset($_SESSION['mass_postActions'][$activeModule])) {
$_SESSION['mass_postActions'][$activeModule] = array();
}
// let first module do one post action
$module = new $activeModule($scope);
$return = $module->doUploadPostActions($data, $ids, $failed, $_SESSION['mass_postActions'][$activeModule]);
// remove active module from list if already finished
if ($return['status'] == 'finished') {
unset($_SESSION['mass_postActions']['remainingModules'][0]);
$_SESSION['mass_postActions']['remainingModules'] = array_values($_SESSION['mass_postActions']['remainingModules']);
}
// update status and return back to upload page
$return['module'] = $activeModule;
if (sizeof($_SESSION['mass_postActions']['remainingModules']) > 0) {
$return['status'] = 'inProgress';
}
else {
$return['status'] = 'finished';
}
return $return;
}
/**
* This class includes all modules and attributes of an account.
*

View File

@ -13,7 +13,11 @@ masscreate:
- mass_counter: aktuelle Position im Account-Array
- mass_errors: Fehlermeldungen beim Upload
- mass_csv: CSV-Datei als Vorlage für Upload
- mass_failed: Liste der Accounts, die nicht erzeugt werden konnten
- mass_postActions: temporäre Daten für den Upload
- mass_data: Eingabedaten
- mass_ids: Tabelle Spaltenname => Spaltennummer
- mass_scope: Account-Typ
main:
- domain_message: Wird auf der "neue Domain" Seite ausgegeben, wenn keine Domäne gefunden wurde

View File

@ -179,6 +179,11 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$_SESSION['mass_accounts'] = $_SESSION['ldap']->encrypt(serialize($accounts));
$_SESSION['mass_counter'] = 0;
$_SESSION['mass_errors'] = array();
$_SESSION['mass_failed'] = array();
$_SESSION['mass_postActions'] = array();
$_SESSION['mass_data'] = $_SESSION['ldap']->encrypt(serialize($data));
$_SESSION['mass_ids'] = $ids;
$_SESSION['mass_scope'] = $_POST['scope'];
// show links for upload and LDIF export
echo "<h1 align=\"center\">" . _("LAM has checked your input and is now ready to create the accounts.") . "</h1>\n";
echo "<p>&nbsp;</p>\n";

View File

@ -57,7 +57,7 @@ echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n
// create accounts
$accounts = unserialize($_SESSION['ldap']->decrypt($_SESSION['mass_accounts']));
if ($_SESSION['mass_counter'] < sizeof($accounts)) {
if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_postActions']['finished'])) {
$maxTime = get_cfg_var('max_execution_time') - 5;
$refreshTime = get_cfg_var('max_execution_time') + 1;
$startTime = time();
@ -69,6 +69,7 @@ if ($_SESSION['mass_counter'] < sizeof($accounts)) {
echo "<td bgcolor=\"grey\" width=\"" . (100 - (($_SESSION['mass_counter'] * 100) / sizeof($accounts))) . "%\">&nbsp;</td></tr>\n";
echo "</table>";
flush(); // send HTML to browser
// add accounts to LDAP
while (($_SESSION['mass_counter'] < sizeof($accounts)) && ($startTime + $maxTime > time())) {
// create accounts as long as max_execution_time is not near
$attrs = $accounts[$_SESSION['mass_counter']];
@ -82,9 +83,32 @@ if ($_SESSION['mass_counter'] < sizeof($accounts)) {
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']++;
}
// do post upload actions
if ($_SESSION['mass_counter'] >= sizeof($accounts)) {
$data = unserialize($_SESSION['ldap']->decrypt($_SESSION['mass_data']));
$return = doUploadPostActions($_SESSION['mass_scope'], $data, $_SESSION['mass_ids'], $failed);
if ($return['status'] == 'finished') {
$_SESSION['mass_postActions']['finished'] = true;
}
for ($i = 0; $i < sizeof($return['errors']); $i++) $_SESSION['mass_errors'][] = $return['errors'][$i];
echo "<h1>" . _("Additional tasks for module: ") . $return['module'] . "</h1>\n";
echo "<table align=\"center\" width=\"80%\" style=\"border-color: grey\" border=\"2\" cellspacing=\"0\" rules=\"none\">\n";
echo "<tr><td bgcolor=\"blue\" width=\"" . $return['progress'] . "%\">&nbsp;</td>";
echo "<td bgcolor=\"grey\" width=\"" . (100 - $return['progress']) . "%\">&nbsp;</td></tr>\n";
echo "</table>";
flush();
while (!isset($_SESSION['mass_postActions']['finished']) && ($startTime + $maxTime > time())) {
$return = doUploadPostActions($_SESSION['mass_scope'], $data, $_SESSION['mass_ids'], $failed);
if ($return['status'] == 'finished') {
$_SESSION['mass_postActions']['finished'] = true;
}
for ($i = 0; $i < sizeof($return['errors']); $i++) $_SESSION['mass_errors'][] = $return['errors'][$i];
}
}
echo "</body></html>";
}
// all accounts have been created