]".PHP_EOL; echo PHP_EOL; echo "Description:".PHP_EOL; echo " This program creates an xml dump of the whole or parts of the dms.".PHP_EOL; echo PHP_EOL; echo "Options:".PHP_EOL; echo " -h, --help: print usage information and exit.".PHP_EOL; echo " -v, --version: print version and exit.".PHP_EOL; echo " --config: set alternative config file.".PHP_EOL; echo " --folder: set start folder.".PHP_EOL; echo " --skip-root: do not export the root folder itself.".PHP_EOL; echo " --sections : comma seperated list of sections to export.".PHP_EOL; echo " --maxsize: maximum size of files to be included in output".PHP_EOL; echo " (defaults to 100000)".PHP_EOL; echo " --contentdir: directory where all document versions are stored".PHP_EOL; echo " which are larger than maxsize.".PHP_EOL; } /* }}} */ function wrapWithCData($text) { /* {{{ */ if(preg_match("/[<>&]/", $text)) return(""); else return $text; } /* }}} */ $version = "0.0.1"; $shortoptions = "hv"; $longoptions = array('help', 'version', 'skip-root', 'config:', 'folder:', 'maxsize:', 'contentdir:', 'sections:'); 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.PHP_EOL; exit(0); } /* Set alternative config file */ if(isset($options['config'])) { define('SEEDDMS_CONFIG_FILE', $options['config']); } elseif(isset($_SERVER['SEEDDMS_CONFIG_FILE'])) { define('SEEDDMS_CONFIG_FILE', $_SERVER['SEEDDMS_CONFIG_FILE']); } /* Set maximum size of files included in xml file */ if(isset($options['maxsize'])) { $maxsize = intval($options['maxsize']); } else { $maxsize = 100000; } /* Set directory for file largen than maxsize */ if(isset($options['contentdir'])) { if(file_exists($options['contentdir'])) { $contentdir = $options['contentdir']; if(substr($contentdir, -1, 1) != DIRECTORY_SEPARATOR) $contentdir .= DIRECTORY_SEPARATOR; } else { echo "Directory ".$options['contentdir']." does not exists".PHP_EOL; exit(1); } } else { $contentdir = ''; } $sections = array(); if(isset($options['sections'])) { $sections = explode(',', $options['sections']); } if(isset($options['folder'])) { $folderid = intval($options['folder']); } else { $folderid = $settings->_rootFolderID; } $skiproot = false; if(isset($options['skip-root'])) { $skiproot = true; } $statistic = array( 'documents'=>0, 'folders'=>0, 'users'=>0, 'groups'=>0, 'attributedefinitions'=>0, 'keywordcategories'=>0, 'documentcategories'=>0, 'workflows'=>0, 'workflowactions'=>0, 'workflowstates'=>0, ); function dumplog($version, $type, $logs, $indent) { /* {{{ */ global $dms, $contentdir, $maxsize; $document = $version->getDocument(); switch($type) { case 'approval': $type2 = 'approve'; break; default: $type2 = $type; } echo $indent." <".$type."s>\n"; $curid = 0; foreach($logs as $a) { if($a[$type2.'ID'] != $curid) { if($curid != 0) { echo $indent." \n"; } echo $indent." <".$type." id=\"".$a[$type2.'ID']."\">\n"; echo $indent." ".$a['type']."\n"; echo $indent." ".$a['required']."\n"; } echo $indent." <".$type."log id=\"".$a[$type2.'LogID']."\">\n"; echo $indent." ".$a['userID']."\n"; echo $indent." ".$a['status']."\n"; echo $indent." ".wrapWithCData($a['comment'])."\n"; echo $indent." ".$a['date']."\n"; if(!empty($a['file'])) { $filename = $dms->contentDir . $document->getDir().'r'.(int) $a[$type2.'LogID']; if(file_exists($filename)) { echo $indent." \n"; echo chunk_split(base64_encode(file_get_contents($filename)), 76, "\n"); echo $indent." \n"; } else { echo " fileref=\"".$filename."\" />\n"; if($contentdir) { copy($filename, $contentdir.$document->getID()."-R-".$a[$type2.'LogID']); } else { echo "Warning: ".$type." log file (size=".filesize($filename).") will be missing from output\n"; } } } } echo $indent." \n"; $curid = $a[$type2.'ID']; } if($curid != 0) echo $indent." \n"; echo $indent." \n"; } /* }}} */ function dumpNotifications($notifications, $indent) { /* {{{ */ if($notifications) { if($notifications['groups'] || $notifications['users']) { echo $indent." \n"; if($notifications['users']) { foreach($notifications['users'] as $user) { echo $indent." getID()."\" />\n"; } } if($notifications['groups']) { foreach($notifications['groups'] as $group) { echo $indent." getID()."\" />\n"; } } echo $indent." \n"; } } } /* }}} */ function tree($folder, $parent=null, $indent='', $skipcurrent=false) { /* {{{ */ global $sections, $statistic, $index, $dms, $maxsize, $contentdir; if(!$sections || in_array('folders', $sections)) { if(!$skipcurrent) { echo $indent."getId()."\""; if($parent) echo " parent=\"".$parent->getID()."\""; echo ">\n"; echo $indent." ".wrapWithCData($folder->getName())."\n"; echo $indent." ".date('Y-m-d H:i:s', $folder->getDate())."\n"; echo $indent." ".$folder->getDefaultAccess()."\n"; echo $indent." ".$folder->inheritsAccess()."\n"; echo $indent." ".$folder->getSequence()."\n"; echo $indent." ".wrapWithCData($folder->getComment())."\n"; echo $indent." ".$folder->getOwner()->getId()."\n"; if($attributes = $folder->getAttributes()) { foreach($attributes as $attribute) { $attrdef = $attribute->getAttributeDefinition(); echo $indent." getID()."\">".wrapWithCData($attribute->getValue())."\n"; } } $notifications = $folder->getNotifyList(); dumpNotifications($notifications, $indent); /* getAccessList() returns also inherited access. So first check * if inheritsAccess is set and don't output any acls in that case. * There could be acls of the folder, which will be visible once the * inheritsAccess is turned off. Those entries will be lost in the * xml output. */ if(!$folder->inheritsAccess()) { $accesslist = $folder->getAccessList(); if($accesslist['users'] || $accesslist['groups']) { echo $indent." \n"; foreach($accesslist['users'] as $acl) { echo $indent." getUser(); echo " user=\"".$user->getID()."\""; echo " mode=\"".$acl->getMode()."\""; echo "/>\n"; } foreach($accesslist['groups'] as $acl) { echo $indent." getGroup(); echo $indent." group=\"".$group->getID()."\""; echo $indent." mode=\"".$acl->getMode()."\""; echo "/>\n"; } echo $indent." \n"; } } echo $indent."\n"; $statistic['folders']++; $parentfolder = $folder; } else { $parentfolder = null; } $subfolders = $folder->getSubFolders(); if($subfolders) { foreach($subfolders as $subfolder) { tree($subfolder, $parentfolder, $indent); } } } if(!$sections || in_array('documents', $sections)) { $documents = $folder->getDocuments(); if($documents) { foreach($documents as $document) { $owner = $document->getOwner(); /* parent folder is only set if it is no skipped */ echo $indent."getId()."\"".(!$skipcurrent ? " folder=\"".$folder->getID()."\"" : ""); if($document->isLocked()) echo " locked=\"true\""; echo ">\n"; echo $indent." ".wrapWithCData($document->getName())."\n"; echo $indent." ".date('Y-m-d H:i:s', $document->getDate())."\n"; if($document->getExpires()) echo $indent." ".date('Y-m-d H:i:s', $document->getExpires())."\n"; echo $indent." ".$owner->getId()."\n"; if($document->getKeywords()) echo $indent." ".wrapWithCData($document->getKeywords())."\n"; echo $indent." ".$document->getDefaultAccess()."\n"; echo $indent." ".$document->inheritsAccess()."\n"; echo $indent." ".$document->getSequence()."\n"; if($document->isLocked()) { $user = $document->getLockingUser(); echo $indent." ".$user->getId()."\n"; } echo $indent." ".wrapWithCData($document->getComment())."\n"; if($attributes = $document->getAttributes()) { foreach($attributes as $attribute) { $attrdef = $attribute->getAttributeDefinition(); echo $indent." getID()."\">".wrapWithCData($attribute->getValue())."\n"; } } /* getAccessList() returns also inherited access. So first check * if inheritsAccess is set and don't output any acls in that case. * There could be acls of the folder, which will be visible once the * inheritsAccess is turned off. Those entries will be lost in the * xml output. */ if(!$document->inheritsAccess()) { $accesslist = $document->getAccessList(); if($accesslist['users'] || $accesslist['groups']) { echo $indent." \n"; foreach($accesslist['users'] as $acl) { echo $indent." getUser(); echo " user=\"".$user->getID()."\""; echo " mode=\"".$acl->getMode()."\""; echo "/>\n"; } foreach($accesslist['groups'] as $acl) { echo $indent." getGroup(); echo $indent." group=\"".$group->getID()."\""; echo $indent." mode=\"".$acl->getMode()."\""; echo "/>\n"; } echo $indent." \n"; } } $cats = $document->getCategories(); if($cats) { echo $indent." \n"; foreach($cats as $cat) { echo $indent." getId()."\"/>\n"; } echo $indent." \n"; } $versions = $document->getContent(); if($versions) { echo $indent." \n"; foreach($versions as $version) { $owner = $version->getUser(); echo $indent." getVersion()."\">\n"; echo $indent." ".$version->getMimeType()."\n"; echo $indent." ".date('Y-m-d H:i:s', $version->getDate())."\n"; echo $indent." ".$version->getFileType()."\n"; echo $indent." ".wrapWithCData($version->getComment())."\n"; echo $indent." ".$owner->getId()."\n"; echo $indent." ".wrapWithCData($version->getOriginalFileName())."\n"; if($attributes = $version->getAttributes()) { foreach($attributes as $attribute) { $attrdef = $attribute->getAttributeDefinition(); echo $indent." getID()."\">".wrapWithCData($attribute->getValue())."\n"; } } if($statuslog = $version->getStatusLog()) { echo $indent." \n"; foreach($statuslog as $entry) { echo $indent." \n"; echo $indent." ".$entry['status']."\n"; echo $indent." ".wrapWithCData($entry['comment'])."\n"; echo $indent." ".$entry['date']."\n"; echo $indent." ".$entry['userID']."\n"; echo $indent." \n"; } echo $indent." \n"; } $approvalStatus = $version->getApprovalStatus(30); if($approvalStatus) { dumplog($version, 'approval', $approvalStatus, $indent); } $reviewStatus = $version->getReviewStatus(30); if($reviewStatus) { dumplog($version, 'review', $reviewStatus, $indent); } $workflow = $version->getWorkflow(); if($workflow) { $workflowstate = $version->getWorkflowState(); echo $indent." getID()."\" state=\"".$workflowstate->getID()."\">\n"; } $wkflogs = $version->getWorkflowLog(); if($wkflogs) { echo $indent." \n"; foreach($wkflogs as $wklog) { echo $indent." \n"; echo $indent." ".$wklog->getDate()."\n"; echo $indent." ".$wklog->getWorkflow()->getID()."\n"; echo $indent." ".$wklog->getTransition()->getID()."\n"; $loguser = $wklog->getUser(); echo $indent." ".$loguser->getID()."\n"; echo $indent." ".wrapWithCData($wklog->getComment())."\n"; echo $indent." \n"; } echo $indent." \n"; } if(file_exists($dms->contentDir . $version->getPath())) { echo $indent." contentDir . $version->getPath())."\""; if(filesize($dms->contentDir . $version->getPath()) < $maxsize) { echo ">\n"; echo chunk_split(base64_encode(file_get_contents($dms->contentDir . $version->getPath())), 76, "\n"); echo $indent." \n"; } else { echo " fileref=\"".$document->getID()."-".$version->getVersion().$version->getFileType()."\" />\n"; if($contentdir) { copy($dms->contentDir . $version->getPath(), $contentdir.$document->getID()."-".$version->getVersion().$version->getFileType()); } else { echo "Warning: version content (size=".filesize($dms->contentDir . $version->getPath()).") will be missing from output\n"; } } } else { echo $indent." \n"; echo $indent." \n"; } echo $indent." \n"; } echo $indent." \n"; } $files = $document->getDocumentFiles(); if($files) { echo $indent." \n"; foreach($files as $file) { $owner = $file->getUser(); echo $indent." getId()."\">\n"; echo $indent." ".wrapWithCData($file->getName())."\n"; echo $indent." ".$file->getMimeType()."\n"; echo $indent." ".date('Y-m-d H:i:s', $file->getDate())."\n"; echo $indent." ".wrapWithCData($file->getFileType())."\n"; echo $indent." ".$file->getVersion()."\n"; echo $indent." ".($file->isPublic() ? 1 : 0)."\n"; echo $indent." ".$owner->getId()."\n"; echo $indent." ".wrapWithCData($file->getComment())."\n"; echo $indent." ".wrapWithCData($file->getOriginalFileName())."\n"; if(file_exists($dms->contentDir . $file->getPath())) { echo $indent." contentDir . $file->getPath())."\""; if(filesize($dms->contentDir . $file->getPath()) < $maxsize) { echo ">\n"; echo chunk_split(base64_encode(file_get_contents($dms->contentDir . $file->getPath())), 76, "\n"); echo $indent." \n"; } else { echo " fileref=\"".$document->getID()."-A-".$file->getID().$file->getFileType()."\" />\n"; if($contentdir) { copy($dms->contentDir . $file->getPath(), $contentdir.$document->getID()."-A-".$file->getID().$file->getFileType()); } else { echo "Warning: file content (size=".filesize($dms->contentDir . $file->getPath()).") will be missing from output\n"; } } } else { echo $indent." \n"; } echo $indent." \n"; } echo $indent." \n"; } $links = $document->getDocumentLinks(); if($links) { echo $indent." \n"; foreach($links as $link) { $owner = $link->getUser(); $target = $link->getTarget(); echo $indent." getId()."\">\n"; echo $indent." ".$target->getId()."\n"; echo $indent." ".$owner->getId()."\n"; echo $indent." ".$link->isPublic()."\n"; echo $indent." \n"; } echo $indent." \n"; } $notifications = $document->getNotifyList(); dumpNotifications($notifications, $indent); echo $indent."\n"; $statistic['documents']++; } } } } /* }}} */ include($myincpath."/inc/inc.Settings.php"); include($myincpath."/inc/inc.Init.php"); include($myincpath."/inc/inc.Extension.php"); include($myincpath."/inc/inc.DBInit.php"); echo "\n"; echo "getDBVersion(), 1, 3))."\" date=\"".date('Y-m-d H:i:s')."\">\n"; /* Dump users {{{ */ if(!$sections || in_array('users', $sections)) { $users = $dms->getAllUsers(); if($users) { echo "\n"; foreach ($users as $user) { echo " getId()."\">\n"; echo " ".wrapWithCData($user->getLogin())."\n"; echo " ".wrapWithCData($user->getPwd())."\n"; echo " ".wrapWithCData($user->getEmail())."\n"; echo " ".wrapWithCData($user->getFullName())."\n"; echo " ".wrapWithCData($user->getComment())."\n"; echo " ".$user->getLanguage()."\n"; echo " ".$user->getTheme()."\n"; echo " ".$user->getRole()."\n"; echo " ".$user->isHidden()."\n"; echo " ".$user->isDisabled()."\n"; echo " ".$user->getPwdExpiration()."\n"; echo " ".$user->getHomeFolder()."\n"; if($image = $user->getImage()) { echo " \n"; echo " ".$image['mimeType']."\n"; /* image data is already base64 coded */ echo " ".$image['image']."\n"; echo " \n"; } if($mreviewers = $user->getMandatoryReviewers()) { echo " \n"; foreach($mreviewers as $mreviewer) { if((int) $mreviewer['reviewerUserID']) echo " \n"; elseif((int) $mreviewer['reviewerGroupID']) echo " \n"; } echo " \n"; } if($mapprovers = $user->getMandatoryApprovers()) { echo " \n"; foreach($mapprovers as $mapprover) { if((int) $mapprover['approverUserID']) echo " \n"; elseif((int) $mapprover['approverGroupID']) echo " \n"; } echo " \n"; } if($mworkflows = $user->getMandatoryWorkflows()) { echo " \n"; foreach($mworkflows as $mworkflow) { echo " getID()."\">\n"; } echo " \n"; } echo " \n"; $statistic['users']++; } echo "\n"; } } /* }}} */ /* Dump groups {{{ */ if(!$sections || in_array('groups', $sections)) { $groups = $dms->getAllGroups(); if($groups) { echo "\n"; foreach ($groups as $group) { echo " getId()."\">\n"; echo " ".wrapWithCData($group->getName())."\n"; echo " ".wrapWithCData($group->getComment())."\n"; $users = $group->getUsers(); if($users) { echo " \n"; foreach ($users as $user) { echo " getId()."\"/>\n"; } echo " \n"; } echo " \n"; $statistic['groups']++; } echo "\n"; } } /* }}} */ /* Dump keywordcategories {{{ */ if(!$sections || in_array('keywordcategories', $sections)) { $categories = $dms->getAllKeywordCategories(); if($categories) { echo "\n"; foreach($categories as $category) { $owner = $category->getOwner(); echo " getId()."\">\n"; echo " ".wrapWithCData($category->getName())."\n"; echo " ".$owner->getId()."\n"; if($keywords = $category->getKeywordLists()) { echo " \n"; foreach($keywords as $keyword) { echo " \n"; echo " ".wrapWithCData($keyword['keywords'])."\n"; echo " \n"; } echo " \n"; } echo " \n"; $statistic['keywordcategories']++; } echo "\n"; } } /* }}} */ /* Dump documentcategories {{{ */ if(!$sections || in_array('documentcategories', $sections)) { $categories = $dms->getDocumentCategories(); if($categories) { echo "\n"; foreach($categories as $category) { echo " getId()."\">\n"; echo " ".wrapWithCData($category->getName())."\n"; echo " \n"; $statistic['documentcategories']++; } echo "\n"; } } /* }}} */ /* Dump attributedefinition {{{ */ if(!$sections || in_array('attributedefinition', $sections)) { $attrdefs = $dms->getAllAttributeDefinitions(); if($attrdefs) { echo "\n"; foreach ($attrdefs as $attrdef) { echo " getID()."\" objtype=\""; switch($attrdef->getObjType()) { case SeedDMS_Core_AttributeDefinition::objtype_all: echo "all"; break; case SeedDMS_Core_AttributeDefinition::objtype_folder: echo "folder"; break; case SeedDMS_Core_AttributeDefinition::objtype_document: echo "document"; break; case SeedDMS_Core_AttributeDefinition::objtype_documentcontent: echo "documentcontent"; break; } echo "\">\n"; echo " ".$attrdef->getName()."\n"; echo " ".$attrdef->getMultipleValues()."\n"; echo " ".wrapWithCData($attrdef->getValueSet())."\n"; echo " ".$attrdef->getType()."\n"; echo " ".$attrdef->getMinValues()."\n"; echo " ".$attrdef->getMaxValues()."\n"; echo " ".wrapWithCData($attrdef->getRegex())."\n"; echo " \n"; $statistic['attributedefinitions']++; } echo "\n"; } } /* }}} */ /* Dump workflows {{{ */ if(!$sections || in_array('workflows', $sections)) { $workflowstates = $dms->getAllWorkflowStates(); if($workflowstates) { echo "\n"; foreach ($workflowstates as $workflowstate) { echo " getID()."\">\n"; echo " ".$workflowstate->getName()."\n"; echo " ".$workflowstate->getDocumentStatus()."\n"; echo " \n"; $statistic['workflowstates']++; } echo "\n"; } $workflowactions = $dms->getAllWorkflowActions(); if($workflowactions) { echo "\n"; foreach ($workflowactions as $workflowaction) { echo " getID()."\">\n"; echo " ".$workflowaction->getName()."\n"; echo " \n"; $statistic['workflowactions']++; } echo "\n"; } $workflows = $dms->getAllWorkflows(); if($workflows) { echo "\n"; foreach ($workflows as $workflow) { echo " getID()."\">\n"; echo " ".$workflow->getName()."\n"; echo " ".$workflow->getInitState()->getID()."\n"; if($transitions = $workflow->getTransitions()) { echo " \n"; foreach($transitions as $transition) { echo " getID()."\">\n"; echo " ".$transition->getState()->getID()."\n"; echo " ".$transition->getNextState()->getID()."\n"; echo " ".$transition->getAction()->getID()."\n"; echo " ".$transition->getMaxTime()."\n"; if($transusers = $transition->getUsers()) { echo " \n"; foreach($transusers as $transuser) { echo " getUser()->getID()."\">\n"; } echo " \n"; } if($transgroups = $transition->getGroups()) { echo " \n"; foreach($transgroups as $transgroup) { echo " getGroup()->getID()."\" numofusers=\"".$transgroup->getNumOfUsers()."\">\n"; } echo " \n"; } echo " \n"; } echo " \n"; } echo " \n"; $statistic['workflows']++; } echo "\n"; } } /* }}} */ /* Dump folders and documents {{{ */ $folder = $dms->getFolder($folderid); if($folder) { tree($folder, null, '', $skiproot); } /* }}} */ /* Dump statistics {{{ */ echo "\n"; echo " \n"; foreach($statistic as $type=>$count) echo " <".$type.">".$count."\n"; echo "\n"; /* }}} */ echo "\n"; ?>