use logger, lots of bug fixes

This commit is contained in:
Uwe Steinmann 2016-09-13 17:09:19 +02:00
parent 19c80748e3
commit 74277d9e76

View File

@ -1,5 +1,6 @@
<?php <?php
require_once("../inc/inc.ClassSettings.php"); require_once("../inc/inc.ClassSettings.php");
require("Log.php");
function usage() { /* {{{ */ function usage() { /* {{{ */
echo "Usage:\n"; echo "Usage:\n";
@ -30,7 +31,7 @@ function dateToTimestamp($date, $format='Y-m-d H:i:s') { /* {{{ */
} /* }}} */ } /* }}} */
function getRevAppLog($reviews) { /* {{{ */ function getRevAppLog($reviews) { /* {{{ */
global $dms, $objmap; global $logger, $dms, $objmap;
$newreviews = array(); $newreviews = array();
foreach($reviews as $i=>$review) { foreach($reviews as $i=>$review) {
@ -45,7 +46,7 @@ function getRevAppLog($reviews) { /* {{{ */
$newreview['logs'] = array(); $newreview['logs'] = array();
foreach($review['logs'] as $j=>$log) { foreach($review['logs'] as $j=>$log) {
if(!array_key_exists($log['attributes']['user'], $objmap['users'])) { if(!array_key_exists($log['attributes']['user'], $objmap['users'])) {
echo "Warning: user for review log cannot be mapped\n"; $logger->warning("User for review log cannot be mapped");
} else { } else {
$newlog = array(); $newlog = array();
$newlog['user'] = $dms->getUser($objmap['users'][$log['attributes']['user']]); $newlog['user'] = $dms->getUser($objmap['users'][$log['attributes']['user']]);
@ -61,12 +62,12 @@ function getRevAppLog($reviews) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_user($user) { /* {{{ */ function insert_user($user) { /* {{{ */
global $dms, $debug, $sections, $defaultUser, $objmap; global $logger, $dms, $debug, $sections, $defaultUser, $objmap;
if($debug) print_r($user); if($debug) print_r($user);
if ($newUser = $dms->getUserByLogin($user['attributes']['login'])) { if ($newUser = $dms->getUserByLogin($user['attributes']['login'])) {
echo "User '".$user['attributes']['login']."' already exists\n"; $logger->info("User '".$user['attributes']['login']."' already exists");
} else { } else {
if(in_array('users', $sections)) { if(in_array('users', $sections)) {
$newUser = $dms->addUser( $newUser = $dms->addUser(
@ -82,8 +83,17 @@ function insert_user($user) { /* {{{ */
$user['attributes']['disabled'], $user['attributes']['disabled'],
$user['attributes']['pwdexpiration']); $user['attributes']['pwdexpiration']);
if(!$newUser) { if(!$newUser) {
echo "Error: could not add user\n"; $logger->err("Could not add user");
return false; return false;
} else {
$logger->info("Added user '".$user['attributes']['login']."'");
if(isset($user['image']) && $user['image']) {
$filecontents = base64_decode($user['image']['data']);
$filename = tempnam('/tmp', 'FOO-User-Img');
file_put_contents($filename, $filecontents);
$newUser->setImage($filename, $user['image']['mimetype']);
unlink($filename);
}
} }
} else { } else {
$newUser = $defaultUser; $newUser = $defaultUser;
@ -95,16 +105,17 @@ function insert_user($user) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_group($group) { /* {{{ */ function insert_group($group) { /* {{{ */
global $dms, $debug, $objmap, $sections, $users; global $logger, $dms, $debug, $objmap, $sections, $users;
if($debug) print_r($group); if($debug) print_r($group);
if ($newGroup = $dms->getGroupByName($group['attributes']['name'])) { if ($newGroup = $dms->getGroupByName($group['attributes']['name'])) {
echo "Group already exists\n"; $logger->info("Group already exists");
} else { } else {
if(in_array('groups', $sections)) { if(in_array('groups', $sections)) {
$newGroup = $dms->addGroup($group['attributes']['name'], $group['attributes']['comment']); $newGroup = $dms->addGroup($group['attributes']['name'], $group['attributes']['comment']);
if($newGroup) { if($newGroup) {
$logger->info("Added group '".$group['attributes']['name']."'");
foreach($group['users'] as $guser) { foreach($group['users'] as $guser) {
/* Check if user is in array of users which has been previously filled /* Check if user is in array of users which has been previously filled
* by the users in the xml file. Alternative, we could check if the * by the users in the xml file. Alternative, we could check if the
@ -113,18 +124,20 @@ function insert_group($group) { /* {{{ */
if(isset($users[$guser])) { if(isset($users[$guser])) {
$user = $users[$guser]; $user = $users[$guser];
if($newMember = $dms->getUserByLogin($user['attributes']['login'])) { if($newMember = $dms->getUserByLogin($user['attributes']['login'])) {
$newGroup->addUser($newMember); if($newGroup->addUser($newMember)) {
$logger->info("Added user '".$newMember->getLogin()."' to group '".$group['attributes']['name']."'");
}
} else { } else {
echo "Error: could not find member of group\n"; $logger->err("Could not find member of group");
return false; return false;
} }
} else { } else {
echo "Error: group member is not contained in xml file\n"; $logger->err("Group member is not contained in xml file");
return false; return false;
} }
} }
} else { } else {
echo "Error: could not add group\n"; $logger->err("Could not add group");
return false; return false;
} }
} else { } else {
@ -137,17 +150,19 @@ function insert_group($group) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_attributedefinition($attrdef) { /* {{{ */ function insert_attributedefinition($attrdef) { /* {{{ */
global $dms, $debug, $objmap, $sections; global $logger, $dms, $debug, $objmap, $sections;
if($debug) if($debug)
print_r($attrdef); print_r($attrdef);
if($newAttrdef = $dms->getAttributeDefinitionByName($attrdef['attributes']['name'])) { if($newAttrdef = $dms->getAttributeDefinitionByName($attrdef['attributes']['name'])) {
echo "Attribute definition already exists\n"; $logger->info("Attribute definition already exists");
} else { } else {
if(in_array('attributedefinitions', $sections)) { if(in_array('attributedefinitions', $sections)) {
if(!$newAttrdef = $dms->addAttributeDefinition($attrdef['attributes']['name'], $attrdef['objecttype'], $attrdef['attributes']['type'], $attrdef['attributes']['multiple'], $attrdef['attributes']['minvalues'], $attrdef['attributes']['maxvalues'], $attrdef['attributes']['valueset'], $attrdef['attributes']['regex'])) { if(!$newAttrdef = $dms->addAttributeDefinition($attrdef['attributes']['name'], $attrdef['objecttype'], $attrdef['attributes']['type'], $attrdef['attributes']['multiple'], $attrdef['attributes']['minvalues'], $attrdef['attributes']['maxvalues'], $attrdef['attributes']['valueset'], $attrdef['attributes']['regex'])) {
echo "Error: could not add attribute definition\n"; $logger->err("Could not add attribute definition");
return false; return false;
} else {
$logger->info("Added attribute definition '".$attrdef['attributes']['name']."'");
} }
} else { } else {
$newAttrdef = null; $newAttrdef = null;
@ -159,17 +174,19 @@ function insert_attributedefinition($attrdef) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_documentcategory($documentcat) { /* {{{ */ function insert_documentcategory($documentcat) { /* {{{ */
global $dms, $debug, $objmap, $sections; global $logger, $dms, $debug, $objmap, $sections;
if($debug) print_r($documentcat); if($debug) print_r($documentcat);
if($newCategory = $dms->getDocumentCategoryByName($documentcat['attributes']['name'])) { if($newCategory = $dms->getDocumentCategoryByName($documentcat['attributes']['name'])) {
echo "Document category already exists\n"; $logger->info("Document category already exists");
} else { } else {
if(in_array('documentcategories', $sections)) { if(in_array('documentcategories', $sections)) {
if(!$newCategory = $dms->addDocumentCategory($documentcat['attributes']['name'])) { if(!$newCategory = $dms->addDocumentCategory($documentcat['attributes']['name'])) {
echo "Error: could not add document category\n"; $logger->err("Error: could not add document category");
return false; return false;
} else {
$logger->info("Added document category '".$documentcat['attributes']['name']."'");
} }
} else { } else {
$newCategory = null; $newCategory = null;
@ -182,27 +199,29 @@ function insert_documentcategory($documentcat) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_keywordcategory($keywordcat) { /* {{{ */ function insert_keywordcategory($keywordcat) { /* {{{ */
global $dms, $debug, $objmap, $sections; global $logger, $dms, $debug, $objmap, $sections;
if($debug) print_r($keywordcat); if($debug) print_r($keywordcat);
if(!array_key_exists((int) $keywordcat['attributes']['owner'], $objmap['users'])) { if(!array_key_exists((int) $keywordcat['attributes']['owner'], $objmap['users'])) {
echo "Error: owner of keyword category cannot be found\n"; $logger->err("Owner of keyword category cannot be found");
return false; return false;
} }
$owner = $objmap['users'][(int) $keywordcat['attributes']['owner']]; $owner = $objmap['users'][(int) $keywordcat['attributes']['owner']];
if($newCategory = $dms->getKeywordCategoryByName($keywordcat['attributes']['name'], $owner)) { if($newCategory = $dms->getKeywordCategoryByName($keywordcat['attributes']['name'], $owner)) {
echo "Document category already exists\n"; $logger->info("Document category already exists");
} else { } else {
if(in_array('keywordcategories', $sections)) { if(in_array('keywordcategories', $sections)) {
if(!$newCategory = $dms->addKeywordCategory($owner, $keywordcat['attributes']['name'])) { if(!$newCategory = $dms->addKeywordCategory($owner, $keywordcat['attributes']['name'])) {
echo "Error: could not add keyword category\n"; $logger->err("Could not add keyword category");
return false; return false;
} else {
$logger->info("Added keyword category '".$keywordcat['attributes']['name']."'");
} }
foreach($keywordcat['keywords'] as $keyword) { foreach($keywordcat['keywords'] as $keyword) {
if(!$newCategory->addKeywordList($keyword['attributes']['name'])) { if(!$newCategory->addKeywordList($keyword['attributes']['name'])) {
echo "Error: could not add keyword to keyword category\n"; $logger->err("Could not add keyword to keyword category");
return false; return false;
} }
} }
@ -217,41 +236,43 @@ function insert_keywordcategory($keywordcat) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_workflow($workflow) { /* {{{ */ function insert_workflow($workflow) { /* {{{ */
global $dms, $debug, $objmap, $sections; global $logger, $dms, $debug, $objmap, $sections;
if($debug) if($debug)
print_r($workflow); print_r($workflow);
if($newWorkflow = $dms->getWorkflowByName($workflow['attributes']['name'])) { if($newWorkflow = $dms->getWorkflowByName($workflow['attributes']['name'])) {
echo "Workflow already exists\n"; $logger->info("Workflow already exists");
} else { } else {
if(in_array('workflows', $sections)) { if(in_array('workflows', $sections)) {
if(!$initstate = $dms->getWorkflowState($objmap['workflowstates'][(int)$workflow['attributes']['initstate']])) { if(!$initstate = $dms->getWorkflowState($objmap['workflowstates'][(int)$workflow['attributes']['initstate']])) {
echo "Error: could not add workflow because initial state is missing\n"; $logger->err("Could not add workflow because initial state is missing");
return false; return false;
} }
if(!$newWorkflow = $dms->addWorkflow($workflow['attributes']['name'], $initstate)) { if(!$newWorkflow = $dms->addWorkflow($workflow['attributes']['name'], $initstate)) {
echo "Error: could not add workflow\n"; $logger->err("Could not add workflow");
return false; return false;
} else {
$logger->info("Added workflow '".$workflow['attributes']['name']."'");
} }
if($workflow['transitions']) { if($workflow['transitions']) {
foreach($workflow['transitions'] as $transition) { foreach($workflow['transitions'] as $transition) {
if(!$state = $dms->getWorkflowState($objmap['workflowstates'][(int) $transition['attributes']['startstate']])) { if(!$state = $dms->getWorkflowState($objmap['workflowstates'][(int) $transition['attributes']['startstate']])) {
echo "Error: could not add workflow because start state of transition is missing\n"; $logger->err("Could not add workflow because start state of transition is missing");
return false; return false;
} }
if(!$nextstate = $dms->getWorkflowState($objmap['workflowstates'][(int) $transition['attributes']['nextstate']])) { if(!$nextstate = $dms->getWorkflowState($objmap['workflowstates'][(int) $transition['attributes']['nextstate']])) {
echo "Error: could not add workflow because end state of transition is missing\n"; $logger->err("Could not add workflow because end state of transition is missing");
return false; return false;
} }
if(!$action = $dms->getWorkflowAction($objmap['workflowactions'][(int) $transition['attributes']['action']])) { if(!$action = $dms->getWorkflowAction($objmap['workflowactions'][(int) $transition['attributes']['action']])) {
echo "Error: could not add workflow because end state of transition is missing\n"; $logger->err("Could not add workflow because end state of transition is missing");
return false; return false;
} }
$tusers = array(); $tusers = array();
if($transition['users']) { if($transition['users']) {
foreach($transition['users'] as $tuserid) { foreach($transition['users'] as $tuserid) {
if(!$tusers[] = $dms->getUser($objmap['users'][(int) $tuserid])) { if(!$tusers[] = $dms->getUser($objmap['users'][(int) $tuserid])) {
echo "Error: could not add workflow because user of transition is missing\n"; $logger->err("Could not add workflow because user of transition is missing");
return false; return false;
} }
} }
@ -260,13 +281,13 @@ function insert_workflow($workflow) { /* {{{ */
if($transition['groups']) { if($transition['groups']) {
foreach($transition['groups'] as $tgroupid) { foreach($transition['groups'] as $tgroupid) {
if(!$tgroups[] = $dms->getGroup($objmap['groups'][(int) $tgroupid])) { if(!$tgroups[] = $dms->getGroup($objmap['groups'][(int) $tgroupid])) {
echo "Error: could not add workflow because group of transition is missing\n"; $logger->err("Could not add workflow because group of transition is missing");
return false; return false;
} }
} }
} }
if(!$newWorkflow->addTransition($state, $action, $nextstate, $tusers, $tgroups)) { if(!$newWorkflow->addTransition($state, $action, $nextstate, $tusers, $tgroups)) {
echo "Error: could not add workflow because transition could not be added\n"; $logger->err("Could not add workflow because transition could not be added");
return false; return false;
} }
} }
@ -281,17 +302,19 @@ function insert_workflow($workflow) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_workflowstate($workflowstate) { /* {{{ */ function insert_workflowstate($workflowstate) { /* {{{ */
global $dms, $debug, $objmap, $sections; global $logger, $dms, $debug, $objmap, $sections;
if($debug) if($debug)
print_r($workflowstate); print_r($workflowstate);
if($newWorkflowstate = $dms->getWorkflowStateByName($workflowstate['attributes']['name'])) { if($newWorkflowstate = $dms->getWorkflowStateByName($workflowstate['attributes']['name'])) {
echo "Workflow state already exists\n"; $logger->info("Workflow state already exists");
} else { } else {
if(in_array('workflows', $sections)) { if(in_array('workflows', $sections)) {
if(!$newWorkflowstate = $dms->addWorkflowState($workflowstate['attributes']['name'], isset($workflowstate['attributes']['documentstate']) ? $workflowstate['attributes']['documentstate'] : 0)) { if(!$newWorkflowstate = $dms->addWorkflowState($workflowstate['attributes']['name'], isset($workflowstate['attributes']['documentstate']) ? $workflowstate['attributes']['documentstate'] : 0)) {
echo "Error: could not add workflow state\n"; $logger->err("Could not add workflow state");
return false; return false;
} else {
$logger->info("Added workflow state '".$workflowstate['attributes']['name']."'");
} }
} else { } else {
$newWorkflowstate = null; $newWorkflowstate = null;
@ -303,17 +326,19 @@ function insert_workflowstate($workflowstate) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_workflowaction($workflowaction) { /* {{{ */ function insert_workflowaction($workflowaction) { /* {{{ */
global $dms, $debug, $objmap, $sections; global $logger, $dms, $debug, $objmap, $sections;
if($debug) if($debug)
print_r($workflowaction); print_r($workflowaction);
if($newWorkflowaction = $dms->getWorkflowActionByName($workflowaction['attributes']['name'])) { if($newWorkflowaction = $dms->getWorkflowActionByName($workflowaction['attributes']['name'])) {
echo "Workflow action already exists\n"; $logger->info("Workflow action already exists");
} else { } else {
if(in_array('workflows', $sections)) { if(in_array('workflows', $sections)) {
if(!$newWorkflowaction = $dms->addWorkflowAction($workflowaction['attributes']['name'])) { if(!$newWorkflowaction = $dms->addWorkflowAction($workflowaction['attributes']['name'])) {
echo "Error: could not add workflow action\n"; $logger->err("Could not add workflow action");
return false; return false;
} else {
$logger->info("Added workflow action '".$workflowaction['attributes']['name']."'");
} }
} else { } else {
$newWorkflowaction = null; $newWorkflowaction = null;
@ -325,12 +350,13 @@ function insert_workflowaction($workflowaction) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_document($document) { /* {{{ */ function insert_document($document) { /* {{{ */
global $dms, $debug, $defaultUser, $objmap, $sections, $rootfolder; global $logger, $dms, $debug, $defaultUser, $objmap, $sections, $rootfolder, $contentdir;
if($debug) print_r($document); if($debug)
print_r($document);
if(!array_key_exists((int) $document['attributes']['owner'], $objmap['users'])) { if(!array_key_exists((int) $document['attributes']['owner'], $objmap['users'])) {
echo "Warning: owner of document cannot be mapped using default user\n"; $logger->warning("Owner of document cannot be mapped using default user");
$owner = $defaultUser; $owner = $defaultUser;
} else { } else {
$owner = $dms->getUser($objmap['users'][(int) $document['attributes']['owner']]); $owner = $dms->getUser($objmap['users'][(int) $document['attributes']['owner']]);
@ -342,7 +368,7 @@ function insert_document($document) { /* {{{ */
if(array_key_exists((int) $orgid, $objmap['attributedefs'])) { if(array_key_exists((int) $orgid, $objmap['attributedefs'])) {
$attributes[$objmap['attributedefs'][$orgid]] = $value; $attributes[$objmap['attributedefs'][$orgid]] = $value;
} else { } else {
echo "Warning: User attribute ".$orgid." cannot be mapped\n"; $logger->warning("User attribute ".$orgid." cannot be mapped");
} }
} }
} }
@ -352,7 +378,7 @@ function insert_document($document) { /* {{{ */
if(array_key_exists((int) $catid, $objmap['documentcategories'])) { if(array_key_exists((int) $catid, $objmap['documentcategories'])) {
$categories[$objmap['documentcategories'][$catid]] = $dms->getDocumentCategory($objmap['documentcategories'][$catid]); $categories[$objmap['documentcategories'][$catid]] = $dms->getDocumentCategory($objmap['documentcategories'][$catid]);
} else { } else {
echo "Warning: Category ".$catid." cannot be mapped\n"; $logger->warning("Category ".$catid." cannot be mapped");
} }
} }
} }
@ -361,7 +387,7 @@ function insert_document($document) { /* {{{ */
if(array_key_exists($document['folder'], $objmap['folders'])) { if(array_key_exists($document['folder'], $objmap['folders'])) {
$folder = $dms->getFolder($objmap['folders'][$document['folder']]); $folder = $dms->getFolder($objmap['folders'][$document['folder']]);
} else { } else {
echo "Error: folder ".$document['folder']." cannot be mapped\n"; $logger->err("Folder ".$document['folder']." cannot be mapped");
return false; return false;
} }
} else } else
@ -372,11 +398,11 @@ function insert_document($document) { /* {{{ */
$initversion = array_shift($document['versions']); $initversion = array_shift($document['versions']);
if(!empty($initversion['fileref'])) { if(!empty($initversion['fileref'])) {
$filename = tempnam('/tmp', 'FOO'); $filename = tempnam('/tmp', 'FOO');
copy($initversion['fileref'], $filename); copy($contentdir.$initversion['fileref'], $filename);
} else { } else {
$filecontents = base64_decode($initversion['data']); $filecontents = base64_decode($initversion['data']);
if(strlen($filecontents) != $initversion['data_length']) { if(strlen($filecontents) != $initversion['data_length']) {
echo "Warning: file length (".strlen($filecontents).") doesn't match expected length (".$initversion['data_length'].").\n"; $logger->warning("File length (".strlen($filecontents).") doesn't match expected length (".$initversion['data_length'].").");
$newDocument = null; $newDocument = null;
$error = true; $error = true;
} }
@ -412,13 +438,28 @@ function insert_document($document) { /* {{{ */
} }
} }
*/ */
$workflow = null;
if(isset($initversion['workflow']) && $initversion['workflow']) {
if(array_key_exists((int) $initversion['workflow']['id'], $objmap['workflows'])) {
$workflow = $dms->getWorkflow($objmap['workflows'][(int) $initversion['workflow']['id']]);
if(!$workflow) {
$logger->warning("Workflow ".$orgid." cannot be mapped");
}
} else {
$logger->warning("Workflow ".$initversion['workflow']['id']." cannot be mapped");
}
}
if($initversion['workflowlogs']) {
}
$version_attributes = array(); $version_attributes = array();
if(isset($initversion['user_attributes'])) { if(isset($initversion['user_attributes'])) {
foreach($initversion['user_attributes'] as $orgid=>$value) { foreach($initversion['user_attributes'] as $orgid=>$value) {
if(array_key_exists((int) $orgid, $objmap['attributedefs'])) { if(array_key_exists((int) $orgid, $objmap['attributedefs'])) {
$version_attributes[$objmap['attributedefs'][$orgid]] = $value; $version_attributes[$objmap['attributedefs'][$orgid]] = $value;
} else { } else {
echo "Warning: User attribute ".$orgid." cannot be mapped\n"; $logger->warning("User attribute ".$orgid." cannot be mapped");
} }
} }
} }
@ -440,23 +481,34 @@ function insert_document($document) { /* {{{ */
isset($initversion['attributes']['comment']) ? $initversion['attributes']['comment'] : '', isset($initversion['attributes']['comment']) ? $initversion['attributes']['comment'] : '',
$attributes, $attributes,
$version_attributes, $version_attributes,
null //workflow $workflow
) )
) { ) {
unlink($filename); unlink($filename);
echo "Error: could not add document\n"; $logger->err("Could not add document '".$document['attributes']['name']."'");
return false; return false;
} else { } else {
$logger->info("Added document '".$document['attributes']['name']."'");
$newDocument = $result[0]; $newDocument = $result[0];
unlink($filename); unlink($filename);
if(isset($document['attributes']['lockedby'])) {
if(!array_key_exists($document['attributes']['lockedby'], $objmap['users'])) {
$logger->warning("User for document lock cannot be mapped");
} else {
if($lockuser = $dms->getUser($objmap['users'][$document['attributes']['lockedby']])) {
$newDocument->setLocked($lockuser);
}
}
}
$newVersion = $result[1]->getContent(); $newVersion = $result[1]->getContent();
$newVersion->setDate(dateToTimestamp($initversion['attributes']['date'])); $newVersion->setDate(dateToTimestamp($initversion['attributes']['date']));
$newlogs = array(); $newlogs = array();
foreach($initversion['statuslogs'] as $i=>$log) { foreach($initversion['statuslogs'] as $i=>$log) {
if(!array_key_exists($log['attributes']['user'], $objmap['users'])) { if(!array_key_exists($log['attributes']['user'], $objmap['users'])) {
unset($initversion['statuslogs'][$i]); unset($initversion['statuslogs'][$i]);
echo "Warning: user for status log cannot be mapped\n"; $logger->warning("User for status log cannot be mapped");
} else { } else {
$log['attributes']['user'] = $dms->getUser($objmap['users'][$log['attributes']['user']]); $log['attributes']['user'] = $dms->getUser($objmap['users'][$log['attributes']['user']]);
$newlogs[] = $log['attributes']; $newlogs[] = $log['attributes'];
@ -478,7 +530,7 @@ function insert_document($document) { /* {{{ */
$newDocument->setDefaultAccess($document['attributes']['defaultaccess']); $newDocument->setDefaultAccess($document['attributes']['defaultaccess']);
foreach($document['versions'] as $version) { foreach($document['versions'] as $version) {
if(!array_key_exists((int) $version['attributes']['owner'], $objmap['users'])) { if(!array_key_exists((int) $version['attributes']['owner'], $objmap['users'])) {
echo "Error: owner of document cannot be mapped\n"; $logger->err("Owner of document cannot be mapped");
return false; return false;
} }
$owner = $dms->getUser($objmap['users'][(int) $version['attributes']['owner']]); $owner = $dms->getUser($objmap['users'][(int) $version['attributes']['owner']]);
@ -517,17 +569,17 @@ function insert_document($document) { /* {{{ */
if(array_key_exists((int) $orgid, $objmap['attributedefs'])) { if(array_key_exists((int) $orgid, $objmap['attributedefs'])) {
$version_attributes[$objmap['attributedefs'][$orgid]] = $value; $version_attributes[$objmap['attributedefs'][$orgid]] = $value;
} else { } else {
echo "Warning: User attribute ".$orgid." cannot be mapped\n"; $logger->warning("User attribute ".$orgid." cannot be mapped");
} }
} }
} }
if(!empty($version['fileref'])) { if(!empty($version['fileref'])) {
$filename = tempnam('/tmp', 'FOO'); $filename = tempnam('/tmp', 'FOO');
copy($version['fileref'], $filename); copy($contentdir.$version['fileref'], $filename);
} else { } else {
$filecontents = base64_decode($version['data']); $filecontents = base64_decode($version['data']);
if(strlen($filecontents) != $version['data_length']) { if(strlen($filecontents) != $version['data_length']) {
echo "Warning: file length (".strlen($filecontents).") doesn't match expected length (".$version['data_length'].").\n"; $logger->warning("File length (".strlen($filecontents).") doesn't match expected length (".$version['data_length'].").");
} }
$filename = tempnam('/tmp', 'FOO'); $filename = tempnam('/tmp', 'FOO');
file_put_contents($filename, $filecontents); file_put_contents($filename, $filecontents);
@ -552,7 +604,7 @@ function insert_document($document) { /* {{{ */
foreach($version['statuslogs'] as $i=>$log) { foreach($version['statuslogs'] as $i=>$log) {
if(!array_key_exists($log['attributes']['user'], $objmap['users'])) { if(!array_key_exists($log['attributes']['user'], $objmap['users'])) {
unset($version['statuslogs'][$i]); unset($version['statuslogs'][$i]);
echo "Warning: user for status log cannot be mapped\n"; $logger->warning("User for status log cannot be mapped");
} else { } else {
$log['attributes']['user'] = $dms->getUser($objmap['users'][$log['attributes']['user']]); $log['attributes']['user'] = $dms->getUser($objmap['users'][$log['attributes']['user']]);
$newlogs[] = $log['attributes']; $newlogs[] = $log['attributes'];
@ -575,7 +627,7 @@ function insert_document($document) { /* {{{ */
if(isset($document['notifications']['users']) && $document['notifications']['users']) { if(isset($document['notifications']['users']) && $document['notifications']['users']) {
foreach($document['notifications']['users'] as $userid) { foreach($document['notifications']['users'] as $userid) {
if(!array_key_exists($userid, $objmap['users'])) { if(!array_key_exists($userid, $objmap['users'])) {
echo "Warning: user for notification cannot be mapped\n"; $logger->warning("User for notification cannot be mapped");
} else { } else {
$newDocument->addNotify($objmap['users'][$userid], 1); $newDocument->addNotify($objmap['users'][$userid], 1);
} }
@ -584,7 +636,7 @@ function insert_document($document) { /* {{{ */
if(isset($document['notifications']['groups']) && $document['notifications']['groups']) { if(isset($document['notifications']['groups']) && $document['notifications']['groups']) {
foreach($document['notifications']['groups'] as $groupid) { foreach($document['notifications']['groups'] as $groupid) {
if(!array_key_exists($groupid, $objmap['groups'])) { if(!array_key_exists($groupid, $objmap['groups'])) {
echo "Warning: user for notification cannot be mapped\n"; $logger->warning("User for notification cannot be mapped");
} else { } else {
$newDocument->addNotify($objmap['groups'][$groupid], 0); $newDocument->addNotify($objmap['groups'][$groupid], 0);
} }
@ -595,13 +647,13 @@ function insert_document($document) { /* {{{ */
foreach($document['acls'] as $acl) { foreach($document['acls'] as $acl) {
if($acl['type'] == 'user') { if($acl['type'] == 'user') {
if(!array_key_exists($acl['user'], $objmap['users'])) { if(!array_key_exists($acl['user'], $objmap['users'])) {
echo "Warning: user for notification cannot be mapped\n"; $logger->warning("User for notification cannot be mapped");
} else { } else {
$newDocument->addAccess($acl['mode'], $objmap['users'][$acl['user']], 1); $newDocument->addAccess($acl['mode'], $objmap['users'][$acl['user']], 1);
} }
} elseif($acl['type'] == 'group') { } elseif($acl['type'] == 'group') {
if(!array_key_exists($acl['group'], $objmap['groups'])) { if(!array_key_exists($acl['group'], $objmap['groups'])) {
echo "Warning: group for notification cannot be mapped\n"; $logger->warning("Group for notification cannot be mapped");
} else { } else {
$newDocument->addAccess($acl['mode'], $objmap['groups'][$acl['group']], 0); $newDocument->addAccess($acl['mode'], $objmap['groups'][$acl['group']], 0);
} }
@ -611,18 +663,18 @@ function insert_document($document) { /* {{{ */
if(isset($document['files']) && $document['files']) { if(isset($document['files']) && $document['files']) {
foreach($document['files'] as $file) { foreach($document['files'] as $file) {
if(!array_key_exists($file['attributes']['owner'], $objmap['users'])) { if(!array_key_exists($file['attributes']['owner'], $objmap['users'])) {
echo "Warning: user for file cannot be mapped\n"; $logger->warning("User for file cannot be mapped");
$owner = $defaultUser; $owner = $defaultUser;
} else { } else {
$owner = $dms->getUser($objmap['users'][$file['attributes']['owner']]); $owner = $dms->getUser($objmap['users'][$file['attributes']['owner']]);
} }
if(!empty($file['fileref'])) { if(!empty($file['fileref'])) {
$filename = tempnam('/tmp', 'FOO'); $filename = tempnam('/tmp', 'FOO');
copy($file['fileref'], $filename); copy($contentdir.$file['fileref'], $filename);
} else { } else {
$filecontents = base64_decode($file['data']); $filecontents = base64_decode($file['data']);
if(strlen($filecontents) != $file['data_length']) { if(strlen($filecontents) != $file['data_length']) {
echo "Warning: file length (".strlen($filecontents).") doesn't match expected length (".$file['data_length'].").\n"; $logger->warning("File length (".strlen($filecontents).") doesn't match expected length (".$file['data_length'].").");
} }
$filename = tempnam('/tmp', 'FOO'); $filename = tempnam('/tmp', 'FOO');
file_put_contents($filename, $filecontents); file_put_contents($filename, $filecontents);
@ -650,13 +702,13 @@ function insert_document($document) { /* {{{ */
} /* }}} */ } /* }}} */
function insert_folder($folder) { /* {{{ */ function insert_folder($folder) { /* {{{ */
global $dms, $debug, $objmap, $defaultUser, $sections, $rootfolder; global $logger, $dms, $debug, $objmap, $defaultUser, $sections, $rootfolder;
if($debug) print_r($folder); if($debug) print_r($folder);
if(in_array('folders', $sections)) { if(in_array('folders', $sections)) {
if(!array_key_exists($folder['attributes']['owner'], $objmap['users'])) { if(!array_key_exists($folder['attributes']['owner'], $objmap['users'])) {
echo "Warning: owner of folder cannot be mapped using default user\n"; $logger->warning("Owner of folder cannot be mapped using default user");
$owner = $defaultuser; $owner = $defaultuser;
} else { } else {
$owner = $dms->getUser($objmap['users'][(int) $folder['attributes']['owner']]); $owner = $dms->getUser($objmap['users'][(int) $folder['attributes']['owner']]);
@ -668,7 +720,7 @@ function insert_folder($folder) { /* {{{ */
if(array_key_exists((int) $orgid, $objmap['attributedefs'])) { if(array_key_exists((int) $orgid, $objmap['attributedefs'])) {
$attributes[$objmap['attributedefs'][$orgid]] = $value; $attributes[$objmap['attributedefs'][$orgid]] = $value;
} else { } else {
echo "Warning: User attribute ".$orgid." cannot be mapped\n"; $logger->warning("User attribute ".$orgid." cannot be mapped");
} }
} }
} }
@ -677,15 +729,17 @@ function insert_folder($folder) { /* {{{ */
if(array_key_exists($folder['folder'], $objmap['folders'])) { if(array_key_exists($folder['folder'], $objmap['folders'])) {
$parent = $dms->getFolder($objmap['folders'][$folder['folder']]); $parent = $dms->getFolder($objmap['folders'][$folder['folder']]);
} else { } else {
echo "Error: Folder ".$folder['folder']." cannot be mapped\n"; $logger->err("Folder ".$folder['folder']." cannot be mapped");
exit; exit;
} }
} else } else
$parent = $rootfolder; $parent = $rootfolder;
if(!$newFolder = $parent->addSubFolder($folder['attributes']['name'], $folder['attributes']['comment'], $owner, $folder['attributes']['sequence'], $attributes)) { if(!$newFolder = $parent->addSubFolder($folder['attributes']['name'], $folder['attributes']['comment'], $owner, $folder['attributes']['sequence'], $attributes)) {
echo "Error: could not add folder\n"; $logger->err("Could not add folder");
return false; return false;
} else {
$logger->info("Added folder '".$folder['attributes']['name']."'");
} }
$newFolder->setDate(dateToTimestamp($folder['attributes']['date'])); $newFolder->setDate(dateToTimestamp($folder['attributes']['date']));
@ -693,7 +747,7 @@ function insert_folder($folder) { /* {{{ */
if(isset($folder['notifications']['users']) && $folder['notifications']['users']) { if(isset($folder['notifications']['users']) && $folder['notifications']['users']) {
foreach($folder['notifications']['users'] as $userid) { foreach($folder['notifications']['users'] as $userid) {
if(!array_key_exists($userid, $objmap['users'])) { if(!array_key_exists($userid, $objmap['users'])) {
echo "Warning: user for notification cannot be mapped\n"; $logger->warning("User for notification cannot be mapped");
} else { } else {
$newFolder->addNotify($objmap['users'][$userid], 1); $newFolder->addNotify($objmap['users'][$userid], 1);
} }
@ -702,7 +756,7 @@ function insert_folder($folder) { /* {{{ */
if(isset($folder['notifications']['groups']) && $folder['notifications']['groups']) { if(isset($folder['notifications']['groups']) && $folder['notifications']['groups']) {
foreach($folder['notifications']['groups'] as $groupid) { foreach($folder['notifications']['groups'] as $groupid) {
if(!array_key_exists($groupid, $objmap['groups'])) { if(!array_key_exists($groupid, $objmap['groups'])) {
echo "Warning: user for notification cannot be mapped\n"; $logger->warning("User for notification cannot be mapped");
} else { } else {
$newFolder->addNotify($objmap['groups'][$groupid], 0); $newFolder->addNotify($objmap['groups'][$groupid], 0);
} }
@ -713,13 +767,13 @@ function insert_folder($folder) { /* {{{ */
foreach($folder['acls'] as $acl) { foreach($folder['acls'] as $acl) {
if($acl['type'] == 'user') { if($acl['type'] == 'user') {
if(!array_key_exists($acl['user'], $objmap['users'])) { if(!array_key_exists($acl['user'], $objmap['users'])) {
echo "Warning: user for notification cannot be mapped\n"; $logger->warning("User for notification cannot be mapped");
} else { } else {
$newFolder->addAccess($acl['mode'], $objmap['users'][$acl['user']], 1); $newFolder->addAccess($acl['mode'], $objmap['users'][$acl['user']], 1);
} }
} elseif($acl['type'] == 'group') { } elseif($acl['type'] == 'group') {
if(!array_key_exists($acl['group'], $objmap['groups'])) { if(!array_key_exists($acl['group'], $objmap['groups'])) {
echo "Warning: group for notification cannot be mapped\n"; $logger->warning("Group for notification cannot be mapped");
} else { } else {
$newFolder->addAccess($acl['mode'], $objmap['groups'][$acl['group']], 0); $newFolder->addAccess($acl['mode'], $objmap['groups'][$acl['group']], 0);
} }
@ -736,7 +790,7 @@ function insert_folder($folder) { /* {{{ */
} /* }}} */ } /* }}} */
function resolve_links() { /* {{{ */ function resolve_links() { /* {{{ */
global $dms, $debug, $defaultUser, $links, $objmap; global $logger, $dms, $debug, $defaultUser, $links, $objmap;
if(!$links) if(!$links)
return; return;
@ -750,32 +804,32 @@ function resolve_links() { /* {{{ */
if(array_key_exists($doclink['attributes']['target'], $objmap['documents'])) { if(array_key_exists($doclink['attributes']['target'], $objmap['documents'])) {
if($target = $dms->getDocument($objmap['documents'][$doclink['attributes']['target']])) { if($target = $dms->getDocument($objmap['documents'][$doclink['attributes']['target']])) {
if(!array_key_exists($doclink['attributes']['owner'], $objmap['users'])) { if(!array_key_exists($doclink['attributes']['owner'], $objmap['users'])) {
echo "Warning: user for link cannot be mapped using default user\n"; $logger->warning("User for link cannot be mapped using default user");
$owner = $defaultUser; $owner = $defaultUser;
} else { } else {
$owner = $dms->getUser($objmap['users'][$doclink['attributes']['owner']]); $owner = $dms->getUser($objmap['users'][$doclink['attributes']['owner']]);
} }
if(!$doc->addDocumentLink($target->getID(), $owner->getID(), $doclink['attributes']['public'])) { if(!$doc->addDocumentLink($target->getID(), $owner->getID(), $doclink['attributes']['public'])) {
echo "Error: could not add document link from ".$doc->getID()." to ".$target->getID()."\n"; $logger->err("Could not add document link from ".$doc->getID()." to ".$target->getID());
} }
} else { } else {
echo "Warning: target document not found in database\n"; $logger->warning("Target document not found in database");
} }
} else { } else {
echo "Warning: target document not found in object mapping\n"; $logger->warning("Target document not found in object mapping");
} }
} }
} else { } else {
echo "Warning: document not found in database\n"; $logger->warning("Document not found in database");
} }
} else { } else {
echo "Warning: document not found in object mapping\n"; $logger->warning("Document not found in object mapping");
} }
} }
} /* }}} */ } /* }}} */
function startElement($parser, $name, $attrs) { /* {{{ */ function startElement($parser, $name, $attrs) { /* {{{ */
global $dms, $noversioncheck, $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_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition; 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;
$parent = end($elementstack); $parent = end($elementstack);
array_push($elementstack, array('name'=>$name, 'attributes'=>$attrs)); array_push($elementstack, array('name'=>$name, 'attributes'=>$attrs));
@ -785,7 +839,7 @@ function startElement($parser, $name, $attrs) { /* {{{ */
$xdbversion = explode('.', $attrs['DBVERSION']); $xdbversion = explode('.', $attrs['DBVERSION']);
$dbversion = $dms->getDBVersion(); $dbversion = $dms->getDBVersion();
if(($xdbversion[0] != $dbversion['major']) || ($xdbversion[1] != $dbversion['minor'])) { if(($xdbversion[0] != $dbversion['major']) || ($xdbversion[1] != $dbversion['minor'])) {
echo "Error: Database version (".implode('.', array($dbversion['major'], $dbversion['minor'], $dbversion['subminor'])).") doesn't match version in input file (".implode('.', $xdbversion).").\n"; $logger->crit("Database version (".implode('.', array($dbversion['major'], $dbversion['minor'], $dbversion['subminor'])).") doesn't match version in input file (".implode('.', $xdbversion).").");
exit(1); exit(1);
} }
} }
@ -850,7 +904,11 @@ function startElement($parser, $name, $attrs) { /* {{{ */
case "DOCUMENT": case "DOCUMENT":
$cur_document = array(); $cur_document = array();
$cur_document['id'] = (int) $attrs['ID']; $cur_document['id'] = (int) $attrs['ID'];
if(isset($attrs['FOLDER']))
$cur_document['folder'] = (int) $attrs['FOLDER']; $cur_document['folder'] = (int) $attrs['FOLDER'];
if(isset($attrs['LOCKED']) && $attrs['LOCKED'] == 'true')
$cur_document['locked'] = true;
$cur_document['attributes'] = array(); $cur_document['attributes'] = array();
$cur_document['versions'] = array(); $cur_document['versions'] = array();
break; break;
@ -867,11 +925,20 @@ function startElement($parser, $name, $attrs) { /* {{{ */
$cur_version['attributes'] = array(); $cur_version['attributes'] = array();
$cur_version['approvals'] = array(); $cur_version['approvals'] = array();
$cur_version['reviews'] = array(); $cur_version['reviews'] = array();
$cur_version['statuslogs'] = array();
$cur_version['workflowlogs'] = array();
break; break;
case "STATUSLOG": case "STATUSLOG":
$cur_statuslog = array(); $cur_statuslog = array();
$cur_statuslog['attributes'] = array(); $cur_statuslog['attributes'] = array();
break; break;
case "WORKFLOWLOGS":
$cur_version['workflowlogs'] = array();
break;
case "WORKFLOWLOG":
$cur_workflowlog = array();
$cur_workflowlog['attributes'] = array();
break;
case "APPROVAL": case "APPROVAL":
$cur_approval = array(); $cur_approval = array();
$cur_approval['attributes'] = array(); $cur_approval['attributes'] = array();
@ -911,6 +978,8 @@ function startElement($parser, $name, $attrs) { /* {{{ */
} }
} elseif($parent['name'] == 'STATUSLOG') { } elseif($parent['name'] == 'STATUSLOG') {
$cur_statuslog['attributes'][$attrs['NAME']] = ''; $cur_statuslog['attributes'][$attrs['NAME']] = '';
} elseif($parent['name'] == 'WORKFLOWLOG') {
$cur_workflowlog['attributes'][$attrs['NAME']] = '';
} elseif($parent['name'] == 'APPROVAL') { } elseif($parent['name'] == 'APPROVAL') {
$cur_approval['attributes'][$attrs['NAME']] = ''; $cur_approval['attributes'][$attrs['NAME']] = '';
} elseif($parent['name'] == 'APPROVALLOG') { } elseif($parent['name'] == 'APPROVALLOG') {
@ -1075,6 +1144,8 @@ function startElement($parser, $name, $attrs) { /* {{{ */
$cur_workflow['id'] = (int) $attrs['ID']; $cur_workflow['id'] = (int) $attrs['ID'];
} elseif($parent['name'] == 'MANDATORY_WORKFLOWS') { } elseif($parent['name'] == 'MANDATORY_WORKFLOWS') {
$cur_user['workflows'][] = (int) $attrs['ID']; $cur_user['workflows'][] = (int) $attrs['ID'];
} elseif($parent['name'] == 'VERSION') {
$cur_version['workflow'] = array('id'=>(int) $attrs['ID'], 'state'=>(int) $attrs['STATE']);
} }
break; break;
case "WORKFLOWACTION": case "WORKFLOWACTION":
@ -1095,7 +1166,7 @@ function startElement($parser, $name, $attrs) { /* {{{ */
} /* }}} */ } /* }}} */
function endElement($parser, $name) { /* {{{ */ function endElement($parser, $name) { /* {{{ */
global $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_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition; 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;
array_pop($elementstack); array_pop($elementstack);
$parent = end($elementstack); $parent = end($elementstack);
@ -1114,6 +1185,9 @@ function endElement($parser, $name) { /* {{{ */
case "STATUSLOG": case "STATUSLOG":
$cur_version['statuslogs'][] = $cur_statuslog; $cur_version['statuslogs'][] = $cur_statuslog;
break; break;
case "WORKFLOWLOG":
$cur_version['workflowlogs'][] = $cur_workflowlog;
break;
case "APPROVAL": case "APPROVAL":
$cur_version['approvals'][] = $cur_approval; $cur_version['approvals'][] = $cur_approval;
break; break;
@ -1190,12 +1264,12 @@ function endElement($parser, $name) { /* {{{ */
foreach($users as $tuser) { foreach($users as $tuser) {
if($tuser['workflows']) { if($tuser['workflows']) {
if(!$user = $dms->getUser($objmap['users'][$tuser['id']])) { if(!$user = $dms->getUser($objmap['users'][$tuser['id']])) {
echo "Error: Cannot find user for adding mandatory workflows\n"; $logger->err("Cannot find user for adding mandatory workflows");
exit; exit;
} }
foreach($tuser['workflows'] as $tworkflowid) { foreach($tuser['workflows'] as $tworkflowid) {
if(!$wk = $dms->getWorkflow($objmap['workflows'][$tworkflowid])) { if(!$wk = $dms->getWorkflow($objmap['workflows'][$tworkflowid])) {
echo "Error: Cannot find workflow for adding mandatory workflows\n"; $logger->err("Cannot find workflow for adding mandatory workflows");
exit; exit;
} }
$user->setMandatoryWorkflow($wk); $user->setMandatoryWorkflow($wk);
@ -1219,7 +1293,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_workflowtransition, $cur_workflowaction, $cur_workflowstate, $cur_transition; 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;
$current = end($elementstack); $current = end($elementstack);
$parent = prev($elementstack); $parent = prev($elementstack);
@ -1228,40 +1302,73 @@ function characterData($parser, $data) { /* {{{ */
switch($parent['name']) { switch($parent['name']) {
case 'DOCUMENT': case 'DOCUMENT':
if(isset($current['attributes']['TYPE']) && $current['attributes']['TYPE'] == 'user') { if(isset($current['attributes']['TYPE']) && $current['attributes']['TYPE'] == 'user') {
if(isset($cur_document['user_attributes'][$current['attributes']['ATTRDEF']]))
$cur_document['user_attributes'][$current['attributes']['ATTRDEF']] .= $data;
else
$cur_document['user_attributes'][$current['attributes']['ATTRDEF']] = $data; $cur_document['user_attributes'][$current['attributes']['ATTRDEF']] = $data;
} else { } else {
if(isset($cur_document['attributes'][$current['attributes']['NAME']]))
$cur_document['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_document['attributes'][$current['attributes']['NAME']] = $data; $cur_document['attributes'][$current['attributes']['NAME']] = $data;
} }
break; break;
case 'FOLDER': case 'FOLDER':
if(isset($current['attributes']['TYPE']) && $current['attributes']['TYPE'] == 'user') { if(isset($current['attributes']['TYPE']) && $current['attributes']['TYPE'] == 'user') {
if(isset($cur_folder['user_attributes'][$current['attributes']['ATTRDEF']]))
$cur_folder['user_attributes'][$current['attributes']['ATTRDEF']] .= $data;
else
$cur_folder['user_attributes'][$current['attributes']['ATTRDEF']] = $data; $cur_folder['user_attributes'][$current['attributes']['ATTRDEF']] = $data;
} else { } else {
if(isset($cur_folder['attributes'][$current['attributes']['NAME']]))
$cur_folder['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_folder['attributes'][$current['attributes']['NAME']] = $data; $cur_folder['attributes'][$current['attributes']['NAME']] = $data;
} }
break; break;
case 'VERSION': case 'VERSION':
if(isset($current['attributes']['TYPE']) && $current['attributes']['TYPE'] == 'user') { if(isset($current['attributes']['TYPE']) && $current['attributes']['TYPE'] == 'user') {
if(isset($cur_version['user_attributes'][$current['attributes']['ATTRDEF']]))
$cur_version['user_attributes'][$current['attributes']['ATTRDEF']] .= $data;
else
$cur_version['user_attributes'][$current['attributes']['ATTRDEF']] = $data; $cur_version['user_attributes'][$current['attributes']['ATTRDEF']] = $data;
} else { } else {
if(isset($cur_version['attributes'][$current['attributes']['NAME']]))
$cur_version['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_version['attributes'][$current['attributes']['NAME']] = $data; $cur_version['attributes'][$current['attributes']['NAME']] = $data;
} }
break; break;
case 'STATUSLOG': case 'STATUSLOG':
if(isset($cur_statuslog['attributes'][$current['attributes']['NAME']]))
$cur_statuslog['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_statuslog['attributes'][$current['attributes']['NAME']] = $data; $cur_statuslog['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'APPROVAL': case 'APPROVAL':
$cur_approval['attributes'][$current['attributes']['NAME']] = $data; $cur_approval['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'APPROVALLOG': case 'APPROVALLOG':
if(isset($cur_approvallog['attributes'][$current['attributes']['NAME']]))
$cur_approvallog['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_approvallog['attributes'][$current['attributes']['NAME']] = $data; $cur_approvallog['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'REVIEW': case 'REVIEW':
$cur_review['attributes'][$current['attributes']['NAME']] = $data; $cur_review['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'REVIEWLOG': case 'REVIEWLOG':
if(isset($cur_reviewlog['attributes'][$current['attributes']['NAME']]))
$cur_reviewlog['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_reviewlog['attributes'][$current['attributes']['NAME']] = $data; $cur_reviewlog['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'WORKFLOWLOG':
if(isset($cur_workflowlog['attributes'][$current['attributes']['NAME']]))
$cur_workflowlog['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_workflowlog['attributes'][$current['attributes']['NAME']] = $data;
break;
case 'USER': case 'USER':
if(isset($cur_user['attributes'][$current['attributes']['NAME']])) if(isset($cur_user['attributes'][$current['attributes']['NAME']]))
$cur_user['attributes'][$current['attributes']['NAME']] .= $data; $cur_user['attributes'][$current['attributes']['NAME']] .= $data;
@ -1302,18 +1409,30 @@ function characterData($parser, $data) { /* {{{ */
$cur_user['image']['mimetype'] = $data; $cur_user['image']['mimetype'] = $data;
break; break;
case 'FILE': case 'FILE':
if(isset($cur_file['attributes'][$current['attributes']['NAME']]))
$cur_file['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_file['attributes'][$current['attributes']['NAME']] = $data; $cur_file['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'LINK': case 'LINK':
$cur_link['attributes'][$current['attributes']['NAME']] = $data; $cur_link['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'WORKFLOW': case 'WORKFLOW':
if(isset($cur_workflow['attributes'][$current['attributes']['NAME']]))
$cur_workflow['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_workflow['attributes'][$current['attributes']['NAME']] = $data; $cur_workflow['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'WORKFLOWSTATE': case 'WORKFLOWSTATE':
if(isset($cur_workflowstate['attributes'][$current['attributes']['NAME']]))
$cur_workflowstate['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_workflowstate['attributes'][$current['attributes']['NAME']] = $data; $cur_workflowstate['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'WORKFLOWACTION': case 'WORKFLOWACTION':
if(isset($cur_workflowaction['attributes'][$current['attributes']['NAME']]))
$cur_workflowaction['attributes'][$current['attributes']['NAME']] .= $data;
else
$cur_workflowaction['attributes'][$current['attributes']['NAME']] = $data; $cur_workflowaction['attributes'][$current['attributes']['NAME']] = $data;
break; break;
case 'TRANSITION': case 'TRANSITION':
@ -1364,6 +1483,12 @@ if(isset($options['v']) || isset($options['verѕion'])) {
exit(0); exit(0);
} }
$logfile = "xmlimport.log";
$logconf = array();
$logconf['timeformat'] = '%Y-%m-%d %H:%M:%S';
$logconf['lineFormat'] = '%{timestamp} %{priority} xmlimport: %{ident} %{message}';
$logger = Log::factory('file', $logfile, '', $logconf);
/* Check for debug mode */ /* Check for debug mode */
$debug = false; $debug = false;
if(isset($options['debug'])) { if(isset($options['debug'])) {
@ -1389,7 +1514,7 @@ if(isset($options['contentdir'])) {
if(substr($contentdir, -1, 1) != DIRECTORY_SEPARATOR) if(substr($contentdir, -1, 1) != DIRECTORY_SEPARATOR)
$contentdir .= DIRECTORY_SEPARATOR; $contentdir .= DIRECTORY_SEPARATOR;
} else { } else {
echo "Directory ".$options['contentdir']." does not exists\n"; $logger->crit("Directory ".$options['contentdir']." does not exists");
exit(1); exit(1);
} }
} else { } else {
@ -1435,7 +1560,7 @@ $db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostn
$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir); $dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir);
if(!$settings->_doNotCheckDBVersion && !$dms->checkVersion()) { if(!$settings->_doNotCheckDBVersion && !$dms->checkVersion()) {
echo "Database update needed."; $logger->crit("Database update needed.");
exit; exit;
} }
$dms->setRootFolderID($settings->_rootFolderID); $dms->setRootFolderID($settings->_rootFolderID);
@ -1447,7 +1572,7 @@ if(!$rootfolder) {
if($defaultuserid) { if($defaultuserid) {
if(!$defaultUser = $dms->getUser($defaultuserid)) { if(!$defaultUser = $dms->getUser($defaultuserid)) {
echo "Error: Could not find default user with id ".$defaultuserid."\n"; $logger->crit("Could not find default user with id ".$defaultuserid);
exit(1); exit(1);
} }
} else { } else {
@ -1495,7 +1620,7 @@ if($exportmapping) {
} }
fclose($fp); fclose($fp);
} else { } else {
echo "Error: could not open mapping file '".$exportmapping."'\n"; $logger->err("Could not open mapping file '".$exportmapping."'");
} }
} }
?> ?>