From: Raphaël Barrois Date: Sun, 19 Sep 2010 19:44:26 +0000 (+0200) Subject: Add script for filling directory_name for xnet accounts (Closes #1178) X-Git-Tag: xorg/1.0.1~171 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=2079bd05a1f8ac0f204ba04c1776c25e78ac78d3;p=platal.git Add script for filling directory_name for xnet accounts (Closes #1178) This script tries to guess the directory_name from the full_name. Any part matching "(...)" or " - ..." will be considered as a comment, and added to the 'comment' field of the group this user is a member of (only if there is only one such group and no current comment). All errors are displayed at the end of the run, the 'directory_name' won't be fixed for them (still 'NULL'); this list can then be accessed by simply running the script again. Signed-off-by: Raphaël Barrois --- diff --git a/upgrade/1.0.1/xnet_directory_name.php b/upgrade/1.0.1/xnet_directory_name.php new file mode 100755 index 0000000..5bc7526 --- /dev/null +++ b/upgrade/1.0.1/xnet_directory_name.php @@ -0,0 +1,64 @@ +#!/usr/bin/php5 +next()) { + $matches = array(); + $comment = ""; + // Match any of the following: + // ... - _MATCH_ + // ... (_MATCH_) + // \pL means 'any unicode letter' + if (preg_match('/([\pL- ]+)(\((.*)\)| +- +(.*))$/', $full, $matches)) { + $full_name = trim($matches[1]); + $comment = trim($matches[count($matches) - 1]); + } else { + $full_name = $full; + } + $matches = array(); + if (preg_match('/^([\pL.-]+) +(.*)/u', $full_name, &$matches)) { + $dir_name = mb_strtoupper(trim($matches[2])) . " " . ucwords(trim($matches[1])); + if ($comment != "") { + if ($nb_assos > 1) { + $errors[$hruid] = "Can't update comment to |$comment|: more than one asso ($nb_assos)."; + continue; + } + if ($comm != null && $comm != "") { + $errors[$hruid] = "Can't update comment to |$comment|: comment already set to |$comm|."; + continue; + } + } + echo "$hruid: |$full| => |$dir_name| (display: |$display|"; + if ($comment != "") { + echo "; comment: |$comment|"; + } + echo ").\n"; + XDB::execute('UPDATE accounts SET directory_name = {?} WHERE hruid = {?}', $dir_name, $hruid); + if ($comment != "") { + XDB::execute('UPDATE group_members SET comm = {?} WHERE uid = {?} AND asso_id = {?}', + $comm, $uid, $asso); + } + } else { + $errors[$hruid] = "Unable to match |$full|."; + } +} + +echo "== ERRORS ==\n"; +foreach($errors as $hruid => $error) { + echo "$hruid\n\t$error\n"; +} +?> +