mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-11 09:35:00 +00:00
export and import roles
This commit is contained in:
parent
6679c3b868
commit
d70c90e758
|
@ -101,6 +101,7 @@ $statistic = array(
|
||||||
'documents'=>0,
|
'documents'=>0,
|
||||||
'folders'=>0,
|
'folders'=>0,
|
||||||
'users'=>0,
|
'users'=>0,
|
||||||
|
'roles'=>0,
|
||||||
'groups'=>0,
|
'groups'=>0,
|
||||||
'attributedefinitions'=>0,
|
'attributedefinitions'=>0,
|
||||||
'keywordcategories'=>0,
|
'keywordcategories'=>0,
|
||||||
|
@ -472,13 +473,31 @@ if(!$folderid) {
|
||||||
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
|
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
|
||||||
echo "<dms dbversion=\"".implode('.', array_slice($dms->getDBVersion(), 1, 3))."\" date=\"".date('Y-m-d H:i:s')."\">\n";
|
echo "<dms dbversion=\"".implode('.', array_slice($dms->getDBVersion(), 1, 3))."\" date=\"".date('Y-m-d H:i:s')."\">\n";
|
||||||
|
|
||||||
|
/* Dump roles {{{ */
|
||||||
|
if(!$sections || in_array('roles', $sections)) {
|
||||||
|
$roles = $dms->getAllRoles();
|
||||||
|
if($roles) {
|
||||||
|
echo "<roles>\n";
|
||||||
|
foreach ($roles as $role) {
|
||||||
|
echo " <role id=\"".$role->getId()."\">\n";
|
||||||
|
echo " <attr name=\"name\">".wrapWithCData($role->getName())."</attr>\n";
|
||||||
|
echo " <attr name=\"noaccess\">".wrapWithCData(implode(',', $role->getNoAccess()))."</attr>\n";
|
||||||
|
echo " <attr name=\"role\">".$role->getRole()."</attr>\n";
|
||||||
|
echo " </role>\n";
|
||||||
|
$statistic['roles']++;
|
||||||
|
}
|
||||||
|
echo "</roles>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* Dump users {{{ */
|
/* Dump users {{{ */
|
||||||
if(!$sections || in_array('users', $sections)) {
|
if(!$sections || in_array('users', $sections)) {
|
||||||
$users = $dms->getAllUsers();
|
$users = $dms->getAllUsers();
|
||||||
if($users) {
|
if($users) {
|
||||||
echo "<users>\n";
|
echo "<users>\n";
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
echo " <user id=\"".$user->getId()."\">\n";
|
echo " <user id=\"".$user->getId()."\" role=\"".$user->getRole()->getId()."\">\n";
|
||||||
echo " <attr name=\"login\">".wrapWithCData($user->getLogin())."</attr>\n";
|
echo " <attr name=\"login\">".wrapWithCData($user->getLogin())."</attr>\n";
|
||||||
echo " <attr name=\"pwd\">".wrapWithCData($user->getPwd())."</attr>\n";
|
echo " <attr name=\"pwd\">".wrapWithCData($user->getPwd())."</attr>\n";
|
||||||
echo " <attr name=\"email\">".wrapWithCData($user->getEmail())."</attr>\n";
|
echo " <attr name=\"email\">".wrapWithCData($user->getEmail())."</attr>\n";
|
||||||
|
@ -486,7 +505,7 @@ if($users) {
|
||||||
echo " <attr name=\"comment\">".wrapWithCData($user->getComment())."</attr>\n";
|
echo " <attr name=\"comment\">".wrapWithCData($user->getComment())."</attr>\n";
|
||||||
echo " <attr name=\"language\">".$user->getLanguage()."</attr>\n";
|
echo " <attr name=\"language\">".$user->getLanguage()."</attr>\n";
|
||||||
echo " <attr name=\"theme\">".$user->getTheme()."</attr>\n";
|
echo " <attr name=\"theme\">".$user->getTheme()."</attr>\n";
|
||||||
echo " <attr name=\"role\">".$user->getRole()."</attr>\n";
|
// echo " <attr name=\"role\">".$user->getRole()->getId()."</attr>\n";
|
||||||
echo " <attr name=\"hidden\">".$user->isHidden()."</attr>\n";
|
echo " <attr name=\"hidden\">".$user->isHidden()."</attr>\n";
|
||||||
echo " <attr name=\"disabled\">".$user->isDisabled()."</attr>\n";
|
echo " <attr name=\"disabled\">".$user->isDisabled()."</attr>\n";
|
||||||
echo " <attr name=\"pwdexpiration\">".$user->getPwdExpiration()."</attr>\n";
|
echo " <attr name=\"pwdexpiration\">".$user->getPwdExpiration()."</attr>\n";
|
||||||
|
|
|
@ -21,7 +21,7 @@ function usage() { /* {{{ */
|
||||||
echo " --folder <folder id>: set import folder.".PHP_EOL;
|
echo " --folder <folder id>: set import folder.".PHP_EOL;
|
||||||
echo " --file <file>: file containing the dump.".PHP_EOL;
|
echo " --file <file>: file containing the dump.".PHP_EOL;
|
||||||
echo " --sections <sections>: comma seperated list of sections to read from dump.".PHP_EOL;
|
echo " --sections <sections>: comma seperated list of sections to read from dump.".PHP_EOL;
|
||||||
echo " can be: users, groups, documents, folders, keywordcategories, or".PHP_EOL;
|
echo " can be: users, groups, roles, documents, folders, keywordcategories, or".PHP_EOL;
|
||||||
echo " documentcategories".PHP_EOL;
|
echo " documentcategories".PHP_EOL;
|
||||||
echo " --contentdir <dir>: directory where all document versions are stored".PHP_EOL;
|
echo " --contentdir <dir>: directory where all document versions are stored".PHP_EOL;
|
||||||
echo " which are not included in the xml file.".PHP_EOL;
|
echo " which are not included in the xml file.".PHP_EOL;
|
||||||
|
@ -117,6 +117,10 @@ function insert_user($user) { /* {{{ */
|
||||||
if(in_array('users', $sections)) {
|
if(in_array('users', $sections)) {
|
||||||
if(substr($user['attributes']['pwdexpiration'], 0, 10) == '0000-00-00')
|
if(substr($user['attributes']['pwdexpiration'], 0, 10) == '0000-00-00')
|
||||||
$user['attributes']['pwdexpiration'] = '';
|
$user['attributes']['pwdexpiration'] = '';
|
||||||
|
$roleobj = null;
|
||||||
|
if(array_key_exists($user['role'], $objmap['roles'])) {
|
||||||
|
$roleobj = $dms->getRole($objmap['roles'][$user['role']]);
|
||||||
|
}
|
||||||
$newUser = $dms->addUser(
|
$newUser = $dms->addUser(
|
||||||
$user['attributes']['login'],
|
$user['attributes']['login'],
|
||||||
$user['attributes']['pwd'],
|
$user['attributes']['pwd'],
|
||||||
|
@ -125,7 +129,7 @@ function insert_user($user) { /* {{{ */
|
||||||
$user['attributes']['language'],
|
$user['attributes']['language'],
|
||||||
$user['attributes']['theme'],
|
$user['attributes']['theme'],
|
||||||
$user['attributes']['comment'],
|
$user['attributes']['comment'],
|
||||||
$user['attributes']['role'],
|
$roleobj,
|
||||||
$user['attributes']['hidden'],
|
$user['attributes']['hidden'],
|
||||||
$user['attributes']['disabled'],
|
$user['attributes']['disabled'],
|
||||||
$user['attributes']['pwdexpiration']);
|
$user['attributes']['pwdexpiration']);
|
||||||
|
@ -169,6 +173,36 @@ function set_homefolders() { /* {{{ */
|
||||||
}
|
}
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
function insert_role($role) { /* {{{ */
|
||||||
|
global $logger, $dms, $debug, $sections, $defaultUser, $objmap;
|
||||||
|
|
||||||
|
if($debug) print_r($role);
|
||||||
|
|
||||||
|
if ($newRole = $dms->getRoleByName($role['attributes']['name'])) {
|
||||||
|
$logger->warning("Role '".$role['attributes']['name']."' already exists");
|
||||||
|
} else {
|
||||||
|
if(in_array('roles', $sections)) {
|
||||||
|
$newRole = $dms->addRole(
|
||||||
|
$role['attributes']['name'],
|
||||||
|
$role['role']);
|
||||||
|
if(!$newRole) {
|
||||||
|
$logger->err("Could not add role");
|
||||||
|
$logger->debug($dms->getDB()->getErrorMsg());
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
$logger->info("Added role '".$role['attributes']['name']."'");
|
||||||
|
if(isset($role['attributes']['noaccess'])) {
|
||||||
|
$noaccess = explode(',', $role['attributes']['noaccess']);
|
||||||
|
$role->setNoAccess($noaccess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($newRole)
|
||||||
|
$objmap['roles'][$role['id']] = $newRole->getID();
|
||||||
|
return $newRole;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
function insert_group($group) { /* {{{ */
|
function insert_group($group) { /* {{{ */
|
||||||
global $logger, $dms, $debug, $objmap, $sections, $users;
|
global $logger, $dms, $debug, $objmap, $sections, $users;
|
||||||
|
|
||||||
|
@ -959,7 +993,7 @@ function set_mandatory() { /* {{{ */
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
function startElement($parser, $name, $attrs) { /* {{{ */
|
function startElement($parser, $name, $attrs) { /* {{{ */
|
||||||
global $logger, $dms, $noversioncheck, $elementstack, $objmap, $cur_user, $cur_group, $cur_folder, $cur_document, $cur_version, $cur_statuslog, $cur_workflowlog, $cur_approval, $cur_approvallog, $cur_review, $cur_reviewlog, $cur_attrdef, $cur_documentcat, $cur_keyword, $cur_keywordcat, $cur_file, $cur_link, $cur_workflow, $cur_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition;
|
global $logger, $dms, $noversioncheck, $elementstack, $objmap, $cur_user, $cur_group, $cur_role, $cur_folder, $cur_document, $cur_version, $cur_statuslog, $cur_workflowlog, $cur_approval, $cur_approvallog, $cur_review, $cur_reviewlog, $cur_attrdef, $cur_documentcat, $cur_keyword, $cur_keywordcat, $cur_file, $cur_link, $cur_workflow, $cur_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition;
|
||||||
|
|
||||||
$parent = end($elementstack);
|
$parent = end($elementstack);
|
||||||
array_push($elementstack, array('name'=>$name, 'attributes'=>$attrs));
|
array_push($elementstack, array('name'=>$name, 'attributes'=>$attrs));
|
||||||
|
@ -988,6 +1022,7 @@ function startElement($parser, $name, $attrs) { /* {{{ */
|
||||||
} else {
|
} else {
|
||||||
$cur_user = array();
|
$cur_user = array();
|
||||||
$cur_user['id'] = (int) $attrs['ID'];
|
$cur_user['id'] = (int) $attrs['ID'];
|
||||||
|
$cur_user['role'] = (int) $attrs['ROLE'];
|
||||||
$cur_user['attributes'] = array();
|
$cur_user['attributes'] = array();
|
||||||
$cur_user['individual']['reviewers'] = array();
|
$cur_user['individual']['reviewers'] = array();
|
||||||
$cur_user['individual']['approvers'] = array();
|
$cur_user['individual']['approvers'] = array();
|
||||||
|
@ -1031,6 +1066,15 @@ function startElement($parser, $name, $attrs) { /* {{{ */
|
||||||
$cur_transition['groups'][] = (int) $attrs['ID'];
|
$cur_transition['groups'][] = (int) $attrs['ID'];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "ROLE":
|
||||||
|
$first = $elementstack[1];
|
||||||
|
$second = $elementstack[2];
|
||||||
|
if($first['name'] == 'ROLES') {
|
||||||
|
$cur_role = array();
|
||||||
|
$cur_role['id'] = (int) $attrs['ID'];
|
||||||
|
$cur_role['attributes'] = array();
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "DOCUMENT":
|
case "DOCUMENT":
|
||||||
$cur_document = array();
|
$cur_document = array();
|
||||||
$cur_document['id'] = (int) $attrs['ID'];
|
$cur_document['id'] = (int) $attrs['ID'];
|
||||||
|
@ -1128,6 +1172,8 @@ function startElement($parser, $name, $attrs) { /* {{{ */
|
||||||
$cur_user['attributes'][$attrs['NAME']] = '';
|
$cur_user['attributes'][$attrs['NAME']] = '';
|
||||||
} elseif($parent['name'] == 'GROUP') {
|
} elseif($parent['name'] == 'GROUP') {
|
||||||
$cur_group['attributes'][$attrs['NAME']] = '';
|
$cur_group['attributes'][$attrs['NAME']] = '';
|
||||||
|
} elseif($parent['name'] == 'ROLE') {
|
||||||
|
$cur_role['attributes'][$attrs['NAME']] = '';
|
||||||
} elseif($parent['name'] == 'KEYWORD') {
|
} elseif($parent['name'] == 'KEYWORD') {
|
||||||
$cur_keyword['attributes'][$attrs['NAME']] = '';
|
$cur_keyword['attributes'][$attrs['NAME']] = '';
|
||||||
} elseif($parent['name'] == 'ATTRIBUTEDEFINITION') {
|
} elseif($parent['name'] == 'ATTRIBUTEDEFINITION') {
|
||||||
|
@ -1302,7 +1348,7 @@ function startElement($parser, $name, $attrs) { /* {{{ */
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
function endElement($parser, $name) { /* {{{ */
|
function endElement($parser, $name) { /* {{{ */
|
||||||
global $logger, $dms, $sections, $rootfolder, $objmap, $elementstack, $users, $groups, $links,$cur_user, $cur_group, $cur_folder, $cur_document, $cur_version, $cur_statuslog, $cur_approval, $cur_approvallog, $cur_review, $cur_reviewlog, $cur_attrdef, $cur_documentcat, $cur_keyword, $cur_keywordcat, $cur_file, $cur_link, $cur_workflow, $cur_workflowlog, $cur_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition;
|
global $logger, $dms, $sections, $rootfolder, $objmap, $elementstack, $users, $groups, $links,$cur_user, $cur_group, $cur_role, $cur_folder, $cur_document, $cur_version, $cur_statuslog, $cur_approval, $cur_approvallog, $cur_review, $cur_reviewlog, $cur_attrdef, $cur_documentcat, $cur_keyword, $cur_keywordcat, $cur_file, $cur_link, $cur_workflow, $cur_workflowlog, $cur_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition;
|
||||||
|
|
||||||
array_pop($elementstack);
|
array_pop($elementstack);
|
||||||
$parent = end($elementstack);
|
$parent = end($elementstack);
|
||||||
|
@ -1351,6 +1397,13 @@ function endElement($parser, $name) { /* {{{ */
|
||||||
insert_group($cur_group);
|
insert_group($cur_group);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "ROLE":
|
||||||
|
$first = $elementstack[1];
|
||||||
|
if($first['name'] == 'ROLES') {
|
||||||
|
$roles[$cur_role['id']] = $cur_role;
|
||||||
|
insert_role($cur_role);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'ATTRIBUTEDEFINITION':
|
case 'ATTRIBUTEDEFINITION':
|
||||||
insert_attributedefinition($cur_attrdef);
|
insert_attributedefinition($cur_attrdef);
|
||||||
break;
|
break;
|
||||||
|
@ -1429,7 +1482,7 @@ function endElement($parser, $name) { /* {{{ */
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
function characterData($parser, $data) { /* {{{ */
|
function characterData($parser, $data) { /* {{{ */
|
||||||
global $elementstack, $objmap, $cur_user, $cur_group, $cur_folder, $cur_document, $cur_version, $cur_statuslog, $cur_approval, $cur_approvallog, $cur_review, $cur_reviewlog, $cur_attrdef, $cur_documentcat, $cur_keyword, $cur_keywordcat, $cur_file, $cur_link, $cur_workflow, $cur_workflowlog, $cur_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition;
|
global $elementstack, $objmap, $cur_user, $cur_group, $cur_role, $cur_folder, $cur_document, $cur_version, $cur_statuslog, $cur_approval, $cur_approvallog, $cur_review, $cur_reviewlog, $cur_attrdef, $cur_documentcat, $cur_keyword, $cur_keywordcat, $cur_file, $cur_link, $cur_workflow, $cur_workflowlog, $cur_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition;
|
||||||
|
|
||||||
$current = end($elementstack);
|
$current = end($elementstack);
|
||||||
$parent = prev($elementstack);
|
$parent = prev($elementstack);
|
||||||
|
@ -1517,6 +1570,12 @@ function characterData($parser, $data) { /* {{{ */
|
||||||
else
|
else
|
||||||
$cur_group['attributes'][$current['attributes']['NAME']] = $data;
|
$cur_group['attributes'][$current['attributes']['NAME']] = $data;
|
||||||
break;
|
break;
|
||||||
|
case 'ROLE':
|
||||||
|
if(isset($cur_role['attributes'][$current['attributes']['NAME']]))
|
||||||
|
$cur_role['attributes'][$current['attributes']['NAME']] .= $data;
|
||||||
|
else
|
||||||
|
$cur_role['attributes'][$current['attributes']['NAME']] = $data;
|
||||||
|
break;
|
||||||
case 'ATTRIBUTEDEFINITION':
|
case 'ATTRIBUTEDEFINITION':
|
||||||
if(isset($cur_attrdef['attributes'][$current['attributes']['NAME']]))
|
if(isset($cur_attrdef['attributes'][$current['attributes']['NAME']]))
|
||||||
$cur_attrdef['attributes'][$current['attributes']['NAME']] .= $data;
|
$cur_attrdef['attributes'][$current['attributes']['NAME']] .= $data;
|
||||||
|
@ -1689,7 +1748,7 @@ if(isset($options['no-version-check'])) {
|
||||||
$noversioncheck = true;
|
$noversioncheck = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sections = array('documents', 'folders', 'groups', 'users', 'keywordcategories', 'documentcategories', 'attributedefinitions', 'workflows');
|
$sections = array('documents', 'folders', 'groups', 'users', 'roles', 'keywordcategories', 'documentcategories', 'attributedefinitions', 'workflows');
|
||||||
if(isset($options['sections'])) {
|
if(isset($options['sections'])) {
|
||||||
$sections = explode(',', $options['sections']);
|
$sections = explode(',', $options['sections']);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user