seeddms-code/utils/xmldump.php

423 lines
16 KiB
PHP
Raw Normal View History

2012-01-12 16:46:56 +00:00
<?php
ini_set('include_path', '.:/usr/share/php:/usr/share/letodms');
require_once("inc/inc.ClassSettings.php");
2012-12-13 21:35:07 +00:00
//require_once("LetoDMS/Core.php");
require_once("LetoDMS_Core/Core.php");
2012-01-12 16:46:56 +00:00
function usage() { /* {{{ */
echo "Usage:\n";
echo " letodms-xmldump [-h] [-v] [--config <file>]\n";
echo "\n";
echo "Description:\n";
echo " This program creates an xml dump of the whole or parts of the dms.\n";
echo "\n";
echo "Options:\n";
echo " -h, --help: print usage information and exit.\n";
echo " -v, --version: print version and exit.\n";
echo " --config: set alternative config file.\n";
2012-12-13 21:35:07 +00:00
echo " --folder: set start folder.\n";
2012-01-12 16:46:56 +00:00
} /* }}} */
function wrapWithCData($text) { /* {{{ */
if(preg_match("/[<>&]/", $text))
return("<![CDATA[".$text."]]>");
else
return $text;
} /* }}} */
$version = "0.0.1";
$shortoptions = "hv";
2012-12-13 21:35:07 +00:00
$longoptions = array('help', 'version', 'config:', 'folder:');
2012-01-12 16:46:56 +00:00
if(false === ($options = getopt($shortoptions, $longoptions))) {
usage();
exit(0);
}
/* Print help and exit */
if(isset($options['h']) || isset($options['help'])) {
usage();
exit(0);
}
/* Print version and exit */
if(isset($options['v']) || isset($options['verѕion'])) {
echo $version."\n";
exit(0);
}
/* Set alternative config file */
if(isset($options['config'])) {
$settings = new Settings($options['config']);
} else {
$settings = new Settings();
}
2012-12-13 21:35:07 +00:00
if(isset($options['folder'])) {
$folderid = intval($options['folder']);
} else {
$folderid = $settings->_rootFolderID;
}
function tree($folder, $parent=null, $indent='') { /* {{{ */
2012-01-12 16:46:56 +00:00
global $index, $dms;
2012-12-13 21:35:07 +00:00
echo $indent."<folder id=\"".$folder->getId()."\"";
if($parent)
echo " parent=\"".$parent->getID()."\"";
echo ">\n";
2012-01-12 16:46:56 +00:00
echo $indent." <attr name=\"name\">".wrapWithCData($folder->getName())."</attr>\n";
echo $indent." <attr name=\"date\">".date('c', $folder->getDate())."</attr>\n";
echo $indent." <attr name=\"defaultaccess\">".$folder->getDefaultAccess()."</attr>\n";
echo $indent." <attr name=\"inheritaccess\">".$folder->inheritsAccess()."</attr>\n";
echo $indent." <attr name=\"sequence\">".$folder->getSequence()."</attr>\n";
if($folder->getComment())
echo $indent." <attr name=\"comment\">".wrapWithCData($folder->getComment())."</attr>\n";
echo $indent." <attr name=\"owner\">".$folder->getOwner()->getId()."</attr>\n";
2012-12-13 21:35:07 +00:00
if($attributes = $folder->getAttributes()) {
foreach($attributes as $attribute) {
$attrdef = $attribute->getAttributeDefinition();
echo $indent." <attr type=\"user\" attrdef=\"".$attrdef->getID()."\">".$attribute->getValue()."</attr>\n";
}
}
if($folder->inheritsAccess()) {
echo $indent." <acls type=\"inherited\" />\n";
} else {
echo $indent." <acls>\n";
$accesslist = $folder->getAccessList();
foreach($accesslist['users'] as $acl) {
echo $indent." <acl type=\"user\"";
$user = $acl->getUser();
echo " user=\"".$user->getID()."\"";
echo " mode=\"".$acl->getMode()."\"";
echo "/>\n";
}
foreach($accesslist['groups'] as $acl) {
echo $indent." <acl type=\"group\"";
$group = $acl->getGroup();
echo $indent." group=\"".$group->getID()."\"";
echo $indent." mode=\"".$acl->getMode()."\"";
echo "/>\n";
}
echo $indent." </acls>\n";
}
echo $indent."</folder>\n";
2012-01-12 16:46:56 +00:00
$subfolders = $folder->getSubFolders();
if($subfolders) {
foreach($subfolders as $subfolder) {
2012-12-13 21:35:07 +00:00
tree($subfolder, $folder, $indent);
2012-01-12 16:46:56 +00:00
}
}
$documents = $folder->getDocuments();
if($documents) {
foreach($documents as $document) {
$owner = $document->getOwner();
2012-12-13 21:35:07 +00:00
echo $indent."<document id=\"".$document->getId()."\" folder=\"".$folder->getID()."\"";
if($document->isLocked())
echo " locked=\"true\"";
echo ">\n";
echo $indent." <attr name=\"name\">".wrapWithCData($document->getName())."</attr>\n";
echo $indent." <attr name=\"date\">".date('c', $document->getDate())."</attr>\n";
2012-01-12 16:46:56 +00:00
if($document->getExpires())
2012-12-13 21:35:07 +00:00
echo $indent." <attr name=\"expires\">".date('c', $document->getExpires())."</attr>\n";
echo $indent." <attr name=\"owner\">".$owner->getId()."</attr>\n";
2012-01-12 16:46:56 +00:00
if($document->getKeywords())
2012-12-13 21:35:07 +00:00
echo $indent." <attr name=\"keywords\">".wrapWithCData($document->getKeywords())."</attr>\n";
echo $indent." <attr name=\"defaultaccess\">".$document->getDefaultAccess()."</attr>\n";
echo $indent." <attr name=\"inheritaccess\">".$document->inheritsAccess()."</attr>\n";
echo $indent." <attr name=\"sequence\">".$document->getSequence()."</attr>\n";
2012-01-12 16:46:56 +00:00
if($document->isLocked()) {
$user = $document->getLockingUser();
2012-12-13 21:35:07 +00:00
echo $indent." <attr name=\"lockedby\">".$user->getId()."</attr>\n";
2012-01-12 16:46:56 +00:00
}
if($document->getComment())
2012-12-13 21:35:07 +00:00
echo $indent." <attr name=\"comment\">".wrapWithCData($document->getComment())."</attr>\n";
if($attributes = $document->getAttributes()) {
foreach($attributes as $attribute) {
$attrdef = $attribute->getAttributeDefinition();
echo $indent." <attr type=\"user\" attrdef=\"".$attrdef->getID()."\">".$attribute->getValue()."</attr>\n";
}
}
2012-01-12 16:46:56 +00:00
/* Check if acl is not inherited */
if(!$document->inheritsAccess()) {
$acls = $document->getAccessList();
if($acls['groups'] || $acls['users']) {
2012-12-13 21:35:07 +00:00
echo $indent." <acls>\n";
2012-01-12 16:46:56 +00:00
if($acls['users']) {
foreach($acls['users'] as $acluser) {
$user = $acluser->getUser();
2012-12-13 21:35:07 +00:00
echo $indent." <acl type=\"user\">\n";
echo $indent." <attr name=\"user\">".$user->getId()."</attr>\n";
echo $indent." <attr name=\"mode\">".$acluser->getMode()."</attr>\n";
echo $indent." </acl>\n";
2012-01-12 16:46:56 +00:00
}
}
if($acls['groups']) {
foreach($acls['groups'] as $aclgroup) {
$group = $aclgroup->getGroup();
2012-12-13 21:35:07 +00:00
echo $indent." <acl type=\"group\">\n";
echo $indent." <attr name=\"group\">".$group->getId()."</attr>\n";
echo $indent." <attr name=\"mode\">".$acluser->getMode()."</attr>\n";
echo $indent." </acl>\n";
2012-01-12 16:46:56 +00:00
}
}
2012-12-13 21:35:07 +00:00
echo $indent." </acls>\n";
2012-01-12 16:46:56 +00:00
}
}
$cats = $document->getCategories();
if($cats) {
2012-12-13 21:35:07 +00:00
echo $indent." <categories>\n";
2012-01-12 16:46:56 +00:00
foreach($cats as $cat) {
2012-12-13 21:35:07 +00:00
echo $indent." <category>".$cat->getId()."</category>\n";
2012-01-12 16:46:56 +00:00
}
2012-12-13 21:35:07 +00:00
echo $indent." </categories>\n";
2012-01-12 16:46:56 +00:00
}
$versions = $document->getContent();
if($versions) {
2012-12-13 21:35:07 +00:00
echo $indent." <versions>\n";
2012-01-12 16:46:56 +00:00
foreach($versions as $version) {
$approvalStatus = $version->getApprovalStatus();
$reviewStatus = $version->getReviewStatus();
$owner = $version->getUser();
2012-12-13 21:35:07 +00:00
echo $indent." <version id=\"".$version->getVersion()."\">\n";
echo $indent." <attr name=\"mimetype\">".$version->getMimeType()."</attr>\n";
echo $indent." <attr name=\"date\">".date('c', $version->getDate())."</attr>\n";
echo $indent." <attr name=\"filetype\">".$version->getFileType()."</attr>\n";
echo $indent." <attr name=\"comment\">".wrapWithCData($version->getComment())."</attr>\n";
echo $indent." <attr name=\"owner\">".$owner->getId()."</attr>\n";
echo $indent." <attr name=\"orgfilename\">".wrapWithCData($version->getOriginalFileName())."</attr>\n";
if($attributes = $version->getAttributes()) {
foreach($attributes as $attribute) {
$attrdef = $attribute->getAttributeDefinition();
echo $indent." <attr type=\"user\" attrdef=\"".$attrdef->getID()."\">".$attribute->getValue()."</attr>\n";
}
}
2012-01-12 16:46:56 +00:00
if($approvalStatus) {
2012-12-13 21:35:07 +00:00
echo $indent." <approvals>\n";
2012-01-12 16:46:56 +00:00
foreach($approvalStatus as $a) {
2012-12-13 21:35:07 +00:00
echo $indent." <approval id=\"".$a['approveID']."\">\n";
echo $indent." <attr name=\"type\">".$a['type']."</attr>\n";
echo $indent." <attr name=\"required\">".$a['required']."</attr>\n";
echo $indent." <attr name=\"status\">".$a['status']."</attr>\n";
echo $indent." <attr name=\"comment\">".wrapWithCData($a['comment'])."</attr>\n";
echo $indent." <attr name=\"user\">".$a['userID']."</attr>\n";
echo $indent." <attr name=\"date\">".$a['date']."</attr>\n";
echo $indent." </approval>\n";
2012-01-12 16:46:56 +00:00
}
2012-12-13 21:35:07 +00:00
echo $indent." </approvals>\n";
2012-01-12 16:46:56 +00:00
}
if($reviewStatus) {
2012-12-13 21:35:07 +00:00
echo $indent." <reviews>\n";
2012-01-12 16:46:56 +00:00
foreach($reviewStatus as $a) {
2012-12-13 21:35:07 +00:00
echo $indent." <review id=\"".$a['reviewID']."\">\n";
echo $indent." <attr name=\"type\">".$a['type']."</attr>\n";
echo $indent." <attr name=\"required\">".$a['required']."</attr>\n";
echo $indent." <attr name=\"status\">".$a['status']."</attr>\n";
echo $indent." <attr name=\"comment\">".wrapWithCData($a['comment'])."</attr>\n";
echo $indent." <attr name=\"user\">".$a['userID']."</attr>\n";
echo $indent." <attr name=\"date\">".$a['date']."</attr>\n";
echo $indent." </review>\n";
2012-01-12 16:46:56 +00:00
}
2012-12-13 21:35:07 +00:00
echo $indent." </reviews>\n";
2012-01-12 16:46:56 +00:00
}
if(file_exists($dms->contentDir . $version->getPath())) {
2012-12-13 21:35:07 +00:00
echo $indent." <data length=\"".filesize($dms->contentDir . $version->getPath())."\">\n";
2012-01-12 16:46:56 +00:00
if(filesize($dms->contentDir . $version->getPath()) < 1000000) {
echo chunk_split(base64_encode(file_get_contents($dms->contentDir . $version->getPath())), 76, "\n");
}
2012-12-13 21:35:07 +00:00
echo $indent." </data>\n";
} else {
echo $indent." <!-- ".$dms->contentDir . $version->getPath()." not found -->\n";
2012-01-12 16:46:56 +00:00
}
2012-12-13 21:35:07 +00:00
echo $indent." </version>\n";
2012-01-12 16:46:56 +00:00
}
2012-12-13 21:35:07 +00:00
echo $indent." </versions>\n";
2012-01-12 16:46:56 +00:00
}
$files = $document->getDocumentFiles();
if($files) {
2012-12-13 21:35:07 +00:00
echo $indent." <files>\n";
2012-01-12 16:46:56 +00:00
foreach($files as $file) {
$owner = $file->getUser();
2012-12-13 21:35:07 +00:00
echo $indent." <file id=\"".$file->getId()."\">\n";
echo $indent." <attr name=\"name\">".wrapWithCData($file->getName())."</attr>\n";
echo $indent." <attr name=\"mimetype\">".$file->getMimeType()."</attr>\n";
echo $indent." <attr name=\"date\">".date('c', $file->getDate())."</attr>\n";
echo $indent." <attr name=\"filetype\">".wrapWithCData($file->getFileType())."</attr>\n";
echo $indent." <attr name=\"owner\">".$owner->getId()."</attr>\n";
echo $indent." <attr name=\"comment\">".wrapWithCData($file->getComment())."</attr>\n";
echo $indent." <attr name=\"orgfilename\">".wrapWithCData($file->getOriginalFileName())."</attr>\n";
echo $indent." </file>\n";
2012-01-12 16:46:56 +00:00
}
2012-12-13 21:35:07 +00:00
echo $indent." </files>\n";
2012-01-12 16:46:56 +00:00
}
$links = $document->getDocumentLinks();
if($links) {
2012-12-13 21:35:07 +00:00
echo $indent." <links>\n";
2012-01-12 16:46:56 +00:00
foreach($links as $link) {
$owner = $link->getUser();
$target = $link->getTarget();
2012-12-13 21:35:07 +00:00
echo $indent." <link id=\"".$link->getId()."\">\n";
echo $indent." <attr name=\"target\">".$target->getId()."</attr>\n";
echo $indent." <attr name=\"owner\">".$owner->getId()."</attr>\n";
echo $indent." <attr name=\"public\">".$link->isPublic()."</attr>\n";
echo $indent." </link>\n";
2012-01-12 16:46:56 +00:00
}
2012-12-13 21:35:07 +00:00
echo $indent." </links>\n";
2012-01-12 16:46:56 +00:00
}
$notifications = $document->getNotifyList();
if($notifications) {
if($notifications['groups'] || $notifications['users']) {
2012-12-13 21:35:07 +00:00
echo $indent." <notifications>\n";
2012-01-12 16:46:56 +00:00
if($notifications['users']) {
foreach($notifications['users'] as $user) {
2012-12-13 21:35:07 +00:00
echo $indent." <notification type=\"user\">\n";
echo $indent." <attr name=\"user\">".$user->getId()."</attr>\n";
echo $indent." </notification>\n";
2012-01-12 16:46:56 +00:00
}
}
if($notifications['groups']) {
foreach($notifications['groups'] as $group) {
2012-12-13 21:35:07 +00:00
echo $indent." <notification type=\"group\">\n";
echo $indent." <attr name=\"group\">".$group->getId()."</attr>\n";
echo $indent." </notification>\n";
2012-01-12 16:46:56 +00:00
}
}
2012-12-13 21:35:07 +00:00
echo $indent." </notification>\n";
2012-01-12 16:46:56 +00:00
}
}
2012-12-13 21:35:07 +00:00
echo $indent."</document>\n";
2012-01-12 16:46:56 +00:00
}
}
2012-12-13 21:35:07 +00:00
} /* }}} */
2012-01-12 16:46:56 +00:00
$db = new LetoDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase);
$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\"");
$dms = new LetoDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir);
$dms->setRootFolderID($settings->_rootFolderID);
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<dms>\n";
$users = $dms->getAllUsers();
if($users) {
echo "<users>\n";
foreach ($users as $user) {
echo " <user id=\"".$user->getId()."\">\n";
echo " <attr name=\"login\">".wrapWithCData($user->getLogin())."</attr>\n";
echo " <attr name=\"pwd\">".wrapWithCData($user->getPwd())."</attr>\n";
echo " <attr name=\"email\">".wrapWithCData($user->getEmail())."</attr>\n";
echo " <attr name=\"fullname\">".wrapWithCData($user->getFullName())."</attr>\n";
echo " <attr name=\"comment\">".wrapWithCData($user->getComment())."</attr>\n";
echo " <attr name=\"language\">".$user->getLanguage()."</attr>\n";
echo " <attr name=\"theme\">".$user->getTheme()."</attr>\n";
echo " <attr name=\"role\">".$user->getRole()."</attr>\n";
echo " <attr name=\"hidden\">".$user->isHidden()."</attr>\n";
2012-12-13 21:35:07 +00:00
echo " <attr name=\"disabled\">".$user->isDisabled()."</attr>\n";
echo " <attr name=\"pwdexpiration\">".$user->getPwdExpiration()."</attr>\n";
2012-01-12 16:46:56 +00:00
if($image = $user->getImage()) {
echo " <image id=\"".$image['id']."\">\n";
2012-12-13 21:35:07 +00:00
echo " <attr name=\"mimetype\">".$image['mimeType']."</attr>\n";
echo " <data>".base64_encode($image['image'])."</data>\n";
2012-01-12 16:46:56 +00:00
echo " </image>\n";
}
echo " </user>\n";
}
echo "</users>\n";
}
$groups = $dms->getAllGroups();
if($groups) {
echo "<groups>\n";
foreach ($groups as $group) {
echo " <group id=\"".$group->getId()."\">\n";
echo " <attr name=\"name\">".wrapWithCData($user->getFullName())."</attr>\n";
echo " <attr name=\"comment\">".wrapWithCData($user->getComment())."</attr>\n";
$users = $group->getUsers();
if($users) {
echo " <users>\n";
foreach ($users as $user) {
echo " <user>".$user->getId()."</user>\n";
}
echo " </users>\n";
}
echo " </group>\n";
}
echo "</groups>\n";
}
$categories = $dms->getAllKeywordCategories();
if($categories) {
echo "<keywordcategories>\n";
foreach($categories as $category) {
$owner = $category->getOwner();
echo " <keywordcategory id=\"".$category->getId()."\">\n";
echo " <attr name=\"name\">".wrapWithCData($category->getName())."</attr>\n";
echo " <attr name=\"owner\">".$owner->getId()."</attr>\n";
if($keywords = $category->getKeywordLists()) {
echo " <keywords>\n";
foreach($keywords as $keyword) {
echo " <keyword id=\"".$keyword['id']."\">\n";
echo " <attr name=\"name\">".wrapWithCData($keyword['keywords'])."</attr>\n";
echo " </keyword>\n";
}
echo " </keywords>\n";
}
echo " </keywordcategory>\n";
}
echo "</keywordcategories>\n";
}
$categories = $dms->getDocumentCategories();
if($categories) {
echo "<documentcategories>\n";
foreach($categories as $category) {
echo " <documentcategory id=\"".$category->getId()."\">\n";
echo " <attr name=\"name\">".wrapWithCData($category->getName())."</attr>\n";
echo " </documentcategory>\n";
}
echo "</documentcategories>\n";
}
2012-12-13 21:35:07 +00:00
$attrdefs = $dms->getAllAttributeDefinitions();
if($attrdefs) {
echo "<attrіbutedefinitions>\n";
foreach ($attrdefs as $attrdef) {
echo " <attributedefinition id=\"".$attrdef->getID()."\" objtype=\"";
switch($attrdef->getObjType()) {
case LetoDMS_Core_AttributeDefinition::objtype_all:
echo "all";
break;
case LetoDMS_Core_AttributeDefinition::objtype_folder:
echo "folder";
break;
case LetoDMS_Core_AttributeDefinition::objtype_document:
echo "document";
break;
case LetoDMS_Core_AttributeDefinition::objtype_documentcontent:
echo "documentcontent";
break;
}
echo "\">\n";
echo " <attr name=\"name\">".$attrdef->getName()."</attr>\n";
echo " <attr name=\"multiple\">".$attrdef->hasMultipleValues()."</attr>\n";
echo " <attr name=\"valueset\">".$attrdef->getValueSet()."</attr>\n";
echo " <attr name=\"type\">".$attrdef->getType()."</attr>\n";
echo " <attr name=\"minvalues\">".$attrdef->getMinValues()."</attr>\n";
echo " <attr name=\"maxvalues\">".$attrdef->getMaxValues()."</attr>\n";
echo " </attributedefinition>\n";
}
echo "</attrіbutedefinitions>\n";
}
$folder = $dms->getFolder($folderid);
if($folder) {
tree($folder);
}
2012-01-12 16:46:56 +00:00
echo "</dms>\n";
?>