2012-12-13 21:35:32 +00:00
< ? php
2017-03-06 09:49:04 +00:00
if ( isset ( $_SERVER [ 'SEEDDMS_HOME' ])) {
require_once ( $_SERVER [ 'SEEDDMS_HOME' ] . " /inc/inc.ClassSettings.php " );
2017-03-06 09:56:16 +00:00
require_once ( $_SERVER [ 'SEEDDMS_HOME' ] . " /inc/inc.ClassAcl.php " );
2017-03-06 09:49:04 +00:00
} else {
require_once ( " ../inc/inc.ClassSettings.php " );
2017-03-06 09:56:16 +00:00
require_once ( " ../inc/inc.ClassAcl.php " );
2017-03-06 09:49:04 +00:00
}
2016-09-13 15:09:19 +00:00
require ( " Log.php " );
2012-12-13 21:35:32 +00:00
function usage () { /* {{{ */
echo " Usage: \n " ;
2013-02-14 11:10:53 +00:00
echo " seeddms-xmlimport [-h] [-v] [--config <file>] \n " ;
2012-12-13 21:35:32 +00:00
echo " \n " ;
echo " Description: \n " ;
echo " This program imports an xml dump into 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 " ;
2015-07-30 09:24:56 +00:00
echo " --config <config file>: set alternative config file. \n " ;
echo " --folder <folder id>: set import folder. \n " ;
echo " --file <file>: file containing the dump. \n " ;
echo " --sections <sections>: comma seperated list of sections to read from dump. \n " ;
2012-12-13 21:35:32 +00:00
echo " can be: users, groups, documents, folders, keywordcategories, or \n " ;
2015-08-06 04:25:06 +00:00
echo " documentcategories, transmittals \n " ;
2015-07-30 09:24:56 +00:00
echo " --contentdir <dir>: directory where all document versions are stored \n " ;
echo " which are not included in the xml file. \n " ;
echo " --default-user <user id>: use this user if user could not be found. \n " ;
echo " --export-mapping <file>: write object mapping into file \n " ;
echo " --debug: turn debug output on \n " ;
} /* }}} */
2015-08-04 05:41:53 +00:00
function dateToTimestamp ( $date , $format = 'Y-m-d H:i:s' ) { /* {{{ */
$p = date_parse_from_format ( $format , $date );
return mktime ( $p [ 'hour' ], $p [ 'minute' ], $p [ 'second' ], $p [ 'month' ], $p [ 'day' ], $p [ 'year' ]);
} /* }}} */
function getRevAppLog ( $reviews ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $objmap ;
2015-08-04 05:41:53 +00:00
$newreviews = array ();
foreach ( $reviews as $i => $review ) {
$newreview = array ( 'type' => $review [ 'attributes' ][ 'type' ]);
if ( $review [ 'attributes' ][ 'type' ] == 1 ) {
if ( isset ( $objmap [ 'groups' ][( int ) $review [ 'attributes' ][ 'required' ]]))
$newreview [ 'required' ] = $dms -> getGroup ( $objmap [ 'groups' ][( int ) $review [ 'attributes' ][ 'required' ]]);
2017-03-03 21:09:42 +00:00
else
$logger -> warning ( " Group " . ( int ) $review [ 'attributes' ][ 'required' ] . " for Log cannot be mapped " );
2015-08-04 05:41:53 +00:00
} else {
if ( isset ( $objmap [ 'users' ][( int ) $review [ 'attributes' ][ 'required' ]]))
$newreview [ 'required' ] = $dms -> getUser ( $objmap [ 'users' ][( int ) $review [ 'attributes' ][ 'required' ]]);
2017-03-03 21:09:42 +00:00
else
$logger -> warning ( " User " . ( int ) $review [ 'attributes' ][ 'required' ] . " for Log cannot be mapped " );
2015-08-04 05:41:53 +00:00
}
2017-03-03 21:09:42 +00:00
if ( isset ( $newreview [ 'required' ])) {
2015-08-04 05:41:53 +00:00
$newreview [ 'logs' ] = array ();
foreach ( $review [ 'logs' ] as $j => $log ) {
if ( ! array_key_exists ( $log [ 'attributes' ][ 'user' ], $objmap [ 'users' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User for review log cannot be mapped " );
2015-08-04 05:41:53 +00:00
} else {
$newlog = array ();
$newlog [ 'user' ] = $dms -> getUser ( $objmap [ 'users' ][ $log [ 'attributes' ][ 'user' ]]);
$newlog [ 'status' ] = $log [ 'attributes' ][ 'status' ];
$newlog [ 'comment' ] = $log [ 'attributes' ][ 'comment' ];
$newlog [ 'date' ] = $log [ 'attributes' ][ 'date' ];
2016-09-15 12:01:01 +00:00
if ( ! empty ( $log [ 'data' ])) {
$filecontents = base64_decode ( $log [ 'data' ]);
$filename = tempnam ( '/tmp' , 'FOO-revapp' );
file_put_contents ( $filename , $filecontents );
$newlog [ 'file' ] = $filename ;
}
2015-08-04 05:41:53 +00:00
$newreview [ 'logs' ][] = $newlog ;
}
}
$newreviews [] = $newreview ;
2017-03-03 21:09:42 +00:00
}
2015-08-04 05:41:53 +00:00
}
return $newreviews ;
2012-12-13 21:35:32 +00:00
} /* }}} */
2016-09-16 09:21:14 +00:00
function getWorkflowLog ( $workflowlogs ) { /* {{{ */
global $logger , $dms , $objmap ;
$newlogs = array ();
foreach ( $workflowlogs as $i => $log ) {
if ( ! array_key_exists ( $log [ 'attributes' ][ 'user' ], $objmap [ 'users' ])) {
unset ( $initversion [ 'workflowlogs' ][ $i ]);
$logger -> warning ( " User for workflow log cannot be mapped " );
} else {
$log [ 'attributes' ][ 'user' ] = $dms -> getUser ( $objmap [ 'users' ][ $log [ 'attributes' ][ 'user' ]]);
if ( ! array_key_exists ( $log [ 'attributes' ][ 'workflow' ], $objmap [ 'workflows' ])) {
unset ( $initversion [ 'workflowlogs' ][ $i ]);
$logger -> warning ( " Workflow for workflow log cannot be mapped " );
} else {
$log [ 'attributes' ][ 'workflow' ] = $dms -> getWorkflow ( $objmap [ 'workflows' ][ $log [ 'attributes' ][ 'workflow' ]]);
if ( ! array_key_exists ( $log [ 'attributes' ][ 'transition' ], $objmap [ 'workflowtransitions' ])) {
unset ( $initversion [ 'workflowlogs' ][ $i ]);
$logger -> warning ( " Workflow transition for workflow log cannot be mapped " );
} else {
$log [ 'attributes' ][ 'transition' ] = $dms -> getWorkflowTransition ( $objmap [ 'workflowtransitions' ][ $log [ 'attributes' ][ 'transition' ]]);
$newlogs [] = $log [ 'attributes' ];
}
}
}
}
return $newlogs ;
} /* }}} */
2012-12-13 21:35:32 +00:00
function insert_user ( $user ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $sections , $defaultUser , $objmap ;
2015-07-30 09:24:56 +00:00
if ( $debug ) print_r ( $user );
2012-12-13 21:35:32 +00:00
2016-09-15 19:40:38 +00:00
$roleobj = null ;
if ( isset ( $user [ 'attributes' ][ 'role' ]) && $user [ 'attributes' ][ 'role' ]) {
if ( array_key_exists ( $user [ 'attributes' ][ 'role' ], $objmap [ 'roles' ])) {
if ( ! $roleobj = $dms -> getRole ( $objmap [ 'roles' ][ $user [ 'attributes' ][ 'role' ]])) {
$logger -> warn ( " Role " . $user [ 'attributes' ][ 'role' ] . " cannot be found " );
}
}
}
2015-07-30 09:24:56 +00:00
if ( $newUser = $dms -> getUserByLogin ( $user [ 'attributes' ][ 'login' ])) {
2017-03-09 06:39:46 +00:00
$logger -> warning ( " User ' " . $user [ 'attributes' ][ 'login' ] . " ' already exists " );
2012-12-13 21:35:32 +00:00
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'users' , $sections )) {
2017-02-14 20:05:29 +00:00
if ( substr ( $user [ 'attributes' ][ 'pwdexpiration' ], 0 , 10 ) == '0000-00-00' )
$user [ 'attributes' ][ 'pwdexpiration' ] = '' ;
2015-07-30 09:24:56 +00:00
$newUser = $dms -> addUser (
$user [ 'attributes' ][ 'login' ],
$user [ 'attributes' ][ 'pwd' ],
$user [ 'attributes' ][ 'fullname' ],
$user [ 'attributes' ][ 'email' ],
$user [ 'attributes' ][ 'language' ],
$user [ 'attributes' ][ 'theme' ],
$user [ 'attributes' ][ 'comment' ],
2016-09-15 19:40:38 +00:00
$roleobj ,
2015-07-30 09:24:56 +00:00
$user [ 'attributes' ][ 'hidden' ],
$user [ 'attributes' ][ 'disabled' ],
$user [ 'attributes' ][ 'pwdexpiration' ]);
if ( ! $newUser ) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add user " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-07-30 09:24:56 +00:00
return false ;
2016-09-13 15:09:19 +00:00
} else {
2017-02-21 07:16:22 +00:00
if ( $user [ 'attributes' ][ 'secret' ])
$newUser -> setSecret ( $user [ 'attributes' ][ 'secret' ]);
2016-09-13 15:09:19 +00:00
$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 );
}
2015-07-30 09:24:56 +00:00
}
} else {
$newUser = $defaultUser ;
2012-12-13 21:35:32 +00:00
}
}
2015-07-30 09:24:56 +00:00
if ( $newUser )
$objmap [ 'users' ][ $user [ 'id' ]] = $newUser -> getID ();
return $newUser ;
2012-12-13 21:35:32 +00:00
} /* }}} */
2015-08-05 18:37:12 +00:00
function set_homefolders () { /* {{{ */
2016-09-15 19:40:38 +00:00
global $logger , $dms , $debug , $defaultUser , $users , $objmap ;
2015-08-05 18:37:12 +00:00
foreach ( $users as $user ) {
2015-08-05 20:47:39 +00:00
if ( isset ( $user [ 'attributes' ][ 'homefolder' ]) && $user [ 'attributes' ][ 'homefolder' ]) {
2015-08-05 18:37:12 +00:00
if ( array_key_exists ( $user [ 'id' ], $objmap [ 'users' ])) {
$userobj = $dms -> getUser ( $objmap [ 'users' ][ $user [ 'id' ]]);
if ( ! array_key_exists (( int ) $user [ 'attributes' ][ 'homefolder' ], $objmap [ 'folders' ])) {
2016-09-15 19:40:38 +00:00
$logger -> warning ( " Homefolder " . $user [ 'attributes' ][ 'homefolder' ] . " cannot be found " );
2015-08-05 18:37:12 +00:00
} else {
$userobj -> setHomeFolder ( $objmap [ 'folders' ][( int ) $user [ 'attributes' ][ 'homefolder' ]]);
}
}
}
}
} /* }}} */
2012-12-13 21:35:32 +00:00
function insert_group ( $group ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $objmap , $sections , $users ;
2015-07-30 09:24:56 +00:00
if ( $debug ) print_r ( $group );
2012-12-13 21:35:32 +00:00
2015-07-30 09:24:56 +00:00
if ( $newGroup = $dms -> getGroupByName ( $group [ 'attributes' ][ 'name' ])) {
2017-03-09 06:39:46 +00:00
$logger -> warning ( " Group already exists " );
2012-12-13 21:35:32 +00:00
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'groups' , $sections )) {
$newGroup = $dms -> addGroup ( $group [ 'attributes' ][ 'name' ], $group [ 'attributes' ][ 'comment' ]);
if ( $newGroup ) {
2016-09-13 15:09:19 +00:00
$logger -> info ( " Added group ' " . $group [ 'attributes' ][ 'name' ] . " ' " );
2015-07-30 09:24:56 +00:00
foreach ( $group [ 'users' ] as $guser ) {
/* 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
* id is a key of $objmap [ 'users' ] and use the new id in that array .
*/
if ( isset ( $users [ $guser ])) {
$user = $users [ $guser ];
if ( $newMember = $dms -> getUserByLogin ( $user [ 'attributes' ][ 'login' ])) {
2016-09-13 15:09:19 +00:00
if ( $newGroup -> addUser ( $newMember )) {
$logger -> info ( " Added user ' " . $newMember -> getLogin () . " ' to group ' " . $group [ 'attributes' ][ 'name' ] . " ' " );
}
2015-07-30 09:24:56 +00:00
} else {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not find member of group " );
2015-07-30 09:24:56 +00:00
return false ;
}
2012-12-13 21:35:32 +00:00
} else {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Group member is not contained in xml file " );
2015-07-30 09:24:56 +00:00
return false ;
2012-12-13 21:35:32 +00:00
}
}
2015-07-30 09:24:56 +00:00
} else {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add group " );
2015-07-30 09:24:56 +00:00
return false ;
2012-12-13 21:35:32 +00:00
}
} else {
2015-07-30 09:24:56 +00:00
$newGroup = null ;
2012-12-13 21:35:32 +00:00
}
}
2015-07-30 09:24:56 +00:00
if ( $newGroup )
$objmap [ 'groups' ][ $group [ 'id' ]] = $newGroup -> getID ();
return $newGroup ;
2012-12-13 21:35:32 +00:00
} /* }}} */
2016-09-15 19:40:38 +00:00
function insert_role ( $role ) { /* {{{ */
global $logger , $dms , $debug , $objmap , $sections , $users ;
if ( $debug ) print_r ( $role );
if ( $newRole = $dms -> getRoleByName ( $role [ 'attributes' ][ 'name' ])) {
$logger -> info ( " Role already exists " );
} else {
if ( in_array ( 'roles' , $sections )) {
$newRole = $dms -> addRole ( $role [ 'attributes' ][ 'name' ], $role [ 'attributes' ][ 'role' ]);
if ( $newRole ) {
$logger -> info ( " Added role ' " . $role [ 'attributes' ][ 'name' ] . " ' " );
if ( ! empty ( $role [ 'attributes' ][ 'noaccess' ])) {
$newRole -> setNoAccess ( explode ( ',' , $role [ 'attributes' ][ 'noaccess' ]));
}
} else {
$logger -> err ( " Could not add role " );
return false ;
}
2017-02-14 20:05:29 +00:00
/*
2016-09-22 06:48:28 +00:00
if ( $aro = SeedDMS_Aro :: getInstance ( $newRole , $dms )) {
$logger -> info ( " Added aro " );
if ( $role [ 'acos' ]) {
$acl = new SeedDMS_Acl ( $dms );
foreach ( $role [ 'acos' ] as $alias => $perm ) {
if ( $aco = SeedDMS_Aco :: getInstance ( $alias , $dms )) {
$logger -> info ( " Added aco with alias ' " . $alias . " ' " );
if ( isset ( $perm [ 'attributes' ][ 'permission' ])) {
if ( $acl -> add ( $aro , $aco , $perm [ 'attributes' ][ 'permission' ])) {
}
}
} else {
$logger -> err ( " Could not add Aco " );
return false ;
}
}
}
} else {
$logger -> err ( " Could not add Aro " );
return false ;
}
2017-02-14 20:05:29 +00:00
*/
2016-09-15 19:40:38 +00:00
} else {
$newRole = null ;
}
}
if ( $newRole )
$objmap [ 'roles' ][ $role [ 'id' ]] = $newRole -> getID ();
return $newRole ;
} /* }}} */
2012-12-13 21:35:32 +00:00
function insert_attributedefinition ( $attrdef ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $objmap , $sections ;
2012-12-13 21:35:32 +00:00
2015-07-30 09:24:56 +00:00
if ( $debug )
print_r ( $attrdef );
if ( $newAttrdef = $dms -> getAttributeDefinitionByName ( $attrdef [ 'attributes' ][ 'name' ])) {
2017-03-09 06:39:46 +00:00
$logger -> warning ( " Attribute definition already exists " );
2012-12-13 21:35:32 +00:00
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'attributedefinitions' , $sections )) {
2017-03-06 12:47:38 +00:00
$objtype = ( $attrdef [ 'objecttype' ] == 'folder' ? SeedDMS_Core_AttributeDefinition :: objtype_folder : ( $attrdef [ 'objecttype' ] == 'document' ? SeedDMS_Core_AttributeDefinition :: objtype_document : ( $attrdef [ 'objecttype' ] == 'documentcontent' ? SeedDMS_Core_AttributeDefinition :: objtype_documentcontent : 0 )));
if ( ! $newAttrdef = $dms -> addAttributeDefinition ( $attrdef [ 'attributes' ][ 'name' ], $objtype , $attrdef [ 'attributes' ][ 'type' ], $attrdef [ 'attributes' ][ 'multiple' ], $attrdef [ 'attributes' ][ 'minvalues' ], $attrdef [ 'attributes' ][ 'maxvalues' ], $attrdef [ 'attributes' ][ 'valueset' ], $attrdef [ 'attributes' ][ 'regex' ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add attribute definition " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-07-30 09:24:56 +00:00
return false ;
2016-09-13 15:09:19 +00:00
} else {
$logger -> info ( " Added attribute definition ' " . $attrdef [ 'attributes' ][ 'name' ] . " ' " );
2015-07-30 09:24:56 +00:00
}
} else {
$newAttrdef = null ;
2012-12-13 21:35:32 +00:00
}
}
2015-07-30 09:24:56 +00:00
if ( $newAttrdef )
$objmap [ 'attributedefs' ][ $attrdef [ 'id' ]] = $newAttrdef -> getID ();
return $newAttrdef ;
2012-12-13 21:35:32 +00:00
} /* }}} */
function insert_documentcategory ( $documentcat ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $objmap , $sections ;
2015-07-30 09:24:56 +00:00
if ( $debug ) print_r ( $documentcat );
2012-12-13 21:35:32 +00:00
2015-07-30 09:24:56 +00:00
if ( $newCategory = $dms -> getDocumentCategoryByName ( $documentcat [ 'attributes' ][ 'name' ])) {
2017-03-09 06:39:46 +00:00
$logger -> warning ( " Document category already exists " );
2012-12-13 21:35:32 +00:00
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'documentcategories' , $sections )) {
if ( ! $newCategory = $dms -> addDocumentCategory ( $documentcat [ 'attributes' ][ 'name' ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Error: could not add document category " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-07-30 09:24:56 +00:00
return false ;
2016-09-13 15:09:19 +00:00
} else {
$logger -> info ( " Added document category ' " . $documentcat [ 'attributes' ][ 'name' ] . " ' " );
2015-07-30 09:24:56 +00:00
}
} else {
$newCategory = null ;
2012-12-13 21:35:32 +00:00
}
}
2015-07-30 09:24:56 +00:00
if ( $newCategory )
$objmap [ 'documentcategories' ][ $documentcat [ 'id' ]] = $newCategory -> getID ();
return $newCategory ;
2012-12-13 21:35:32 +00:00
} /* }}} */
function insert_keywordcategory ( $keywordcat ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $objmap , $sections ;
2012-12-13 21:35:32 +00:00
2015-07-30 09:24:56 +00:00
if ( $debug ) print_r ( $keywordcat );
if ( ! array_key_exists (( int ) $keywordcat [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Owner of keyword category cannot be found " );
2015-07-30 09:24:56 +00:00
return false ;
}
$owner = $objmap [ 'users' ][( int ) $keywordcat [ 'attributes' ][ 'owner' ]];
if ( $newCategory = $dms -> getKeywordCategoryByName ( $keywordcat [ 'attributes' ][ 'name' ], $owner )) {
2017-03-09 06:39:46 +00:00
$logger -> warning ( " Keyword category already exists " );
2012-12-13 21:35:32 +00:00
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'keywordcategories' , $sections )) {
if ( ! $newCategory = $dms -> addKeywordCategory ( $owner , $keywordcat [ 'attributes' ][ 'name' ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add keyword category " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-07-30 09:24:56 +00:00
return false ;
2016-09-13 15:09:19 +00:00
} else {
$logger -> info ( " Added keyword category ' " . $keywordcat [ 'attributes' ][ 'name' ] . " ' " );
2015-07-30 09:24:56 +00:00
}
foreach ( $keywordcat [ 'keywords' ] as $keyword ) {
if ( ! $newCategory -> addKeywordList ( $keyword [ 'attributes' ][ 'name' ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add keyword to keyword category " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-07-30 09:24:56 +00:00
return false ;
}
}
} else {
$newCategory = null ;
2012-12-13 21:35:32 +00:00
}
}
2015-07-30 09:24:56 +00:00
if ( $newCategory )
$objmap [ 'keywordcategories' ][ $keywordcat [ 'id' ]] = $newCategory -> getID ();
return $newCategory ;
2012-12-13 21:35:32 +00:00
} /* }}} */
2016-09-08 13:20:13 +00:00
function insert_workflow ( $workflow ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $objmap , $sections ;
2016-09-08 13:20:13 +00:00
if ( $debug )
print_r ( $workflow );
if ( $newWorkflow = $dms -> getWorkflowByName ( $workflow [ 'attributes' ][ 'name' ])) {
2017-03-09 06:39:46 +00:00
$logger -> warning ( " Workflow already exists " );
2016-09-08 13:20:13 +00:00
} else {
if ( in_array ( 'workflows' , $sections )) {
if ( ! $initstate = $dms -> getWorkflowState ( $objmap [ 'workflowstates' ][( int ) $workflow [ 'attributes' ][ 'initstate' ]])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow because initial state is missing " );
2016-09-08 13:20:13 +00:00
return false ;
}
if ( ! $newWorkflow = $dms -> addWorkflow ( $workflow [ 'attributes' ][ 'name' ], $initstate )) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2016-09-08 13:20:13 +00:00
return false ;
2016-09-13 15:09:19 +00:00
} else {
$logger -> info ( " Added workflow ' " . $workflow [ 'attributes' ][ 'name' ] . " ' " );
2016-09-08 13:20:13 +00:00
}
2016-09-15 19:40:38 +00:00
if ( ! empty ( $workflow [ 'layoutdata' ]))
$newWorkflow -> setLayoutData ( $workflow [ 'layoutdata' ]);
2016-09-08 13:20:13 +00:00
if ( $workflow [ 'transitions' ]) {
foreach ( $workflow [ 'transitions' ] as $transition ) {
if ( ! $state = $dms -> getWorkflowState ( $objmap [ 'workflowstates' ][( int ) $transition [ 'attributes' ][ 'startstate' ]])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow because start state of transition is missing " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2016-09-08 13:20:13 +00:00
return false ;
}
if ( ! $nextstate = $dms -> getWorkflowState ( $objmap [ 'workflowstates' ][( int ) $transition [ 'attributes' ][ 'nextstate' ]])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow because end state of transition is missing " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2016-09-08 13:20:13 +00:00
return false ;
}
if ( ! $action = $dms -> getWorkflowAction ( $objmap [ 'workflowactions' ][( int ) $transition [ 'attributes' ][ 'action' ]])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow because end state of transition is missing " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2016-09-08 13:20:13 +00:00
return false ;
}
$tusers = array ();
if ( $transition [ 'users' ]) {
foreach ( $transition [ 'users' ] as $tuserid ) {
if ( ! $tusers [] = $dms -> getUser ( $objmap [ 'users' ][( int ) $tuserid ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow because user of transition is missing " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2016-09-08 13:20:13 +00:00
return false ;
}
}
}
$tgroups = array ();
if ( $transition [ 'groups' ]) {
foreach ( $transition [ 'groups' ] as $tgroupid ) {
if ( ! $tgroups [] = $dms -> getGroup ( $objmap [ 'groups' ][( int ) $tgroupid ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow because group of transition is missing " );
2016-09-08 13:20:13 +00:00
return false ;
}
}
}
2016-09-16 09:21:14 +00:00
if ( ! ( $newWorkflowTransition = $newWorkflow -> addTransition ( $state , $action , $nextstate , $tusers , $tgroups ))) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow because transition could not be added " );
2016-09-08 13:20:13 +00:00
return false ;
}
2016-09-16 09:21:14 +00:00
if ( $newWorkflowTransition )
$objmap [ 'workflowtransitions' ][ $transition [ 'id' ]] = $newWorkflowTransition -> getID ();
2016-09-08 13:20:13 +00:00
}
}
} else {
$newWorkflow = null ;
}
}
if ( $newWorkflow )
$objmap [ 'workflows' ][ $workflow [ 'id' ]] = $newWorkflow -> getID ();
return $newWorkflow ;
} /* }}} */
function insert_workflowstate ( $workflowstate ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $objmap , $sections ;
2016-09-08 13:20:13 +00:00
if ( $debug )
print_r ( $workflowstate );
if ( $newWorkflowstate = $dms -> getWorkflowStateByName ( $workflowstate [ 'attributes' ][ 'name' ])) {
2017-03-09 06:39:46 +00:00
$logger -> warning ( " Workflow state already exists " );
2016-09-08 13:20:13 +00:00
} else {
if ( in_array ( 'workflows' , $sections )) {
if ( ! $newWorkflowstate = $dms -> addWorkflowState ( $workflowstate [ 'attributes' ][ 'name' ], isset ( $workflowstate [ 'attributes' ][ 'documentstate' ]) ? $workflowstate [ 'attributes' ][ 'documentstate' ] : 0 )) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow state " );
2016-09-08 13:20:13 +00:00
return false ;
2016-09-13 15:09:19 +00:00
} else {
$logger -> info ( " Added workflow state ' " . $workflowstate [ 'attributes' ][ 'name' ] . " ' " );
2016-09-08 13:20:13 +00:00
}
} else {
$newWorkflowstate = null ;
}
}
if ( $newWorkflowstate )
$objmap [ 'workflowstates' ][ $workflowstate [ 'id' ]] = $newWorkflowstate -> getID ();
return $newWorkflowstate ;
} /* }}} */
function insert_workflowaction ( $workflowaction ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $objmap , $sections ;
2016-09-08 13:20:13 +00:00
if ( $debug )
print_r ( $workflowaction );
if ( $newWorkflowaction = $dms -> getWorkflowActionByName ( $workflowaction [ 'attributes' ][ 'name' ])) {
2017-03-09 06:39:46 +00:00
$logger -> warning ( " Workflow action already exists " );
2016-09-08 13:20:13 +00:00
} else {
if ( in_array ( 'workflows' , $sections )) {
if ( ! $newWorkflowaction = $dms -> addWorkflowAction ( $workflowaction [ 'attributes' ][ 'name' ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add workflow action " );
2016-09-08 13:20:13 +00:00
return false ;
2016-09-13 15:09:19 +00:00
} else {
$logger -> info ( " Added workflow action ' " . $workflowaction [ 'attributes' ][ 'name' ] . " ' " );
2016-09-08 13:20:13 +00:00
}
} else {
$newWorkflowaction = null ;
}
}
if ( $newWorkflowaction )
$objmap [ 'workflowactions' ][ $workflowaction [ 'id' ]] = $newWorkflowaction -> getID ();
return $newWorkflowaction ;
} /* }}} */
2012-12-13 21:35:32 +00:00
function insert_document ( $document ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $defaultUser , $objmap , $sections , $rootfolder , $contentdir ;
2015-07-30 09:24:56 +00:00
2016-09-13 15:09:19 +00:00
if ( $debug )
print_r ( $document );
2015-07-31 13:31:34 +00:00
2015-07-30 09:24:56 +00:00
if ( ! array_key_exists (( int ) $document [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " Owner of document cannot be mapped using default user " );
2015-07-30 09:24:56 +00:00
$owner = $defaultUser ;
} else {
$owner = $dms -> getUser ( $objmap [ 'users' ][( int ) $document [ 'attributes' ][ 'owner' ]]);
}
$attributes = array ();
if ( isset ( $document [ 'user_attributes' ])) {
foreach ( $document [ 'user_attributes' ] as $orgid => $value ) {
if ( array_key_exists (( int ) $orgid , $objmap [ 'attributedefs' ])) {
$attributes [ $objmap [ 'attributedefs' ][ $orgid ]] = $value ;
} else {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User attribute " . $orgid . " cannot be mapped " );
2015-07-30 09:24:56 +00:00
}
}
}
$categories = array ();
if ( isset ( $document [ 'categories' ])) {
foreach ( $document [ 'categories' ] as $catid ) {
if ( array_key_exists (( int ) $catid , $objmap [ 'documentcategories' ])) {
$categories [ $objmap [ 'documentcategories' ][ $catid ]] = $dms -> getDocumentCategory ( $objmap [ 'documentcategories' ][ $catid ]);
} else {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " Category " . $catid . " cannot be mapped " );
2015-07-30 09:24:56 +00:00
}
}
}
if ( isset ( $document [ 'folder' ]) && $document [ 'folder' ]) {
if ( array_key_exists ( $document [ 'folder' ], $objmap [ 'folders' ])) {
$folder = $dms -> getFolder ( $objmap [ 'folders' ][ $document [ 'folder' ]]);
} else {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Folder " . $document [ 'folder' ] . " cannot be mapped " );
2015-07-30 09:24:56 +00:00
return false ;
}
} else
$folder = $rootfolder ;
if ( in_array ( 'documents' , $sections )) {
$initversion = array_shift ( $document [ 'versions' ]);
2016-09-16 15:23:43 +00:00
if ( ! $initversion ) {
$logger -> err ( " Document ' " . $document [ 'attributes' ][ 'name' ] . " ' missing initial version " );
return false ;
2016-09-15 12:01:01 +00:00
}
2016-09-16 15:23:43 +00:00
/* Rewriting the review/approval log will set reviewers/approvers */
$reviews = array ( 'i' => array (), 'g' => array ());
2016-09-15 12:01:01 +00:00
$approvals = array ( 'i' => array (), 'g' => array ());
$workflow = null ;
$workflowstate = 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 " . $initversion [ 'workflow' ][ 'id' ] . " cannot be mapped " );
}
} else {
$logger -> warning ( " Workflow " . $initversion [ 'workflow' ][ 'id' ] . " cannot be mapped " );
}
if ( array_key_exists (( int ) $initversion [ 'workflow' ][ 'state' ], $objmap [ 'workflowstates' ])) {
2016-09-15 19:44:21 +00:00
$workflowstate = $dms -> getWorkflowState ( $objmap [ 'workflowstates' ][( int ) $initversion [ 'workflow' ][ 'state' ]]);
2016-09-15 12:01:01 +00:00
if ( ! $workflowstate ) {
$logger -> warning ( " Workflowstate " . $initversion [ 'workflow' ][ 'state' ] . " cannot be mapped " );
}
} else {
$logger -> warning ( " Workflowstate " . $initversion [ 'workflow' ][ 'state' ] . " cannot be mapped " );
}
}
$version_attributes = array ();
if ( isset ( $initversion [ 'user_attributes' ])) {
foreach ( $initversion [ 'user_attributes' ] as $orgid => $value ) {
if ( array_key_exists (( int ) $orgid , $objmap [ 'attributedefs' ])) {
$version_attributes [ $objmap [ 'attributedefs' ][ $orgid ]] = $value ;
} else {
$logger -> warning ( " User attribute " . $orgid . " cannot be mapped " );
}
}
}
2015-07-30 09:24:56 +00:00
if ( ! empty ( $initversion [ 'fileref' ])) {
$filename = tempnam ( '/tmp' , 'FOO' );
2016-09-13 15:09:19 +00:00
copy ( $contentdir . $initversion [ 'fileref' ], $filename );
2015-07-30 09:24:56 +00:00
} else {
2016-09-16 15:23:43 +00:00
if ( ! isset ( $initversion [ 'data' ]))
echo $document [ 'attributes' ][ 'name' ] . " \n " ;
2015-07-30 09:24:56 +00:00
$filecontents = base64_decode ( $initversion [ 'data' ]);
if ( strlen ( $filecontents ) != $initversion [ 'data_length' ]) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " File length ( " . strlen ( $filecontents ) . " ) doesn't match expected length ( " . $initversion [ 'data_length' ] . " ). " );
2015-07-30 09:24:56 +00:00
}
$filename = tempnam ( '/tmp' , 'FOO' );
file_put_contents ( $filename , $filecontents );
}
2016-09-15 12:01:01 +00:00
if ( ! $result = $folder -> addDocument (
$document [ 'attributes' ][ 'name' ],
$document [ 'attributes' ][ 'comment' ],
isset ( $document [ 'attributes' ][ 'expires' ]) ? dateToTimestamp ( $document [ 'attributes' ][ 'expires' ]) : 0 ,
$owner ,
2017-03-06 10:37:18 +00:00
isset ( $document [ 'attributes' ][ 'keywords' ]) ? $document [ 'attributes' ][ 'keywords' ] : '' ,
2016-09-15 12:01:01 +00:00
$categories ,
$filename ,
$initversion [ 'attributes' ][ 'orgfilename' ],
$initversion [ 'attributes' ][ 'filetype' ],
$initversion [ 'attributes' ][ 'mimetype' ],
$document [ 'attributes' ][ 'sequence' ],
$reviews , //reviewers
$approvals , //approvers
$initversion [ 'version' ],
isset ( $initversion [ 'attributes' ][ 'comment' ]) ? $initversion [ 'attributes' ][ 'comment' ] : '' ,
$attributes ,
$version_attributes ,
$workflow
)
) {
unlink ( $filename );
$logger -> err ( " Could not add document ' " . $document [ 'attributes' ][ 'name' ] . " ' " );
return false ;
}
/* The document and its initial version was added */
$logger -> info ( " Added document ' " . $document [ 'attributes' ][ 'name' ] . " ' " );
$newDocument = $result [ 0 ];
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 -> setDate ( dateToTimestamp ( $initversion [ 'attributes' ][ 'date' ]));
2017-12-12 06:26:24 +00:00
if ( $initversion [ 'attributes' ][ 'revisiondate' ] && substr ( $initversion [ 'attributes' ][ 'revisiondate' ], 0 , 4 ) != '0000' )
$newVersion -> setRevisionDate ( $initversion [ 'attributes' ][ 'revisiondate' ]);
2016-09-15 12:01:01 +00:00
if ( $workflowstate )
$newVersion -> setWorkflowState ( $workflowstate );
$newlogs = array ();
foreach ( $initversion [ 'statuslogs' ] as $i => $log ) {
if ( ! array_key_exists ( $log [ 'attributes' ][ 'user' ], $objmap [ 'users' ])) {
unset ( $initversion [ 'statuslogs' ][ $i ]);
$logger -> warning ( " User for status log cannot be mapped " );
} else {
$log [ 'attributes' ][ 'user' ] = $dms -> getUser ( $objmap [ 'users' ][ $log [ 'attributes' ][ 'user' ]]);
$newlogs [] = $log [ 'attributes' ];
}
}
$newVersion -> rewriteStatusLog ( $newlogs );
/* Set reviewers and review log */
if ( $initversion [ 'reviews' ]) {
// print_r($initversion['reviews']);
$newreviews = getRevAppLog ( $initversion [ 'reviews' ]);
$newVersion -> rewriteReviewLog ( $newreviews );
}
if ( $initversion [ 'approvals' ]) {
$newapprovals = getRevAppLog ( $initversion [ 'approvals' ]);
$newVersion -> rewriteApprovalLog ( $newapprovals );
}
2017-03-03 21:09:42 +00:00
if ( $initversion [ 'receipts' ]) {
$newreceipts = getRevAppLog ( $initversion [ 'receipts' ]);
$newVersion -> rewriteReceiptLog ( $newreceipts );
}
2017-07-27 19:17:11 +00:00
if ( $initversion [ 'revisions' ]) {
$newrevisions = getRevAppLog ( $initversion [ 'revisions' ]);
$newVersion -> rewriteRevisionLog ( $newrevisions );
}
2016-09-15 12:01:01 +00:00
2016-09-16 09:21:14 +00:00
if ( $initversion [ 'workflowlogs' ]) {
$newworkflowlogs = getWorkflowLog ( $initversion [ 'workflowlogs' ]);
if ( ! $newVersion -> rewriteWorkflowLog ( $newworkflowlogs )) {
$logger -> err ( " Could not rewrite workflow log of version ' " . $newVersion -> getVersion () . " ' of document ' " . $newDocument -> getName () . " ' " );
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
return false ;
}
}
2016-09-15 12:01:01 +00:00
$newDocument -> setDate ( dateToTimestamp ( $document [ 'attributes' ][ 'date' ]));
$newDocument -> setDefaultAccess ( $document [ 'attributes' ][ 'defaultaccess' ]);
$newDocument -> setInheritAccess ( $document [ 'attributes' ][ 'inheritaccess' ]);
foreach ( $document [ 'versions' ] as $version ) {
if ( ! array_key_exists (( int ) $version [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
$logger -> err ( " Owner of document cannot be mapped " );
return false ;
}
$owner = $dms -> getUser ( $objmap [ 'users' ][( int ) $version [ 'attributes' ][ 'owner' ]]);
2016-09-16 15:23:43 +00:00
/* Rewriting the review/approval log will set reviewers/approvers */
2015-07-30 09:24:56 +00:00
$reviews = array ( 'i' => array (), 'g' => array ());
$approvals = array ( 'i' => array (), 'g' => array ());
2016-09-13 15:09:19 +00:00
$workflow = null ;
2016-09-15 12:01:01 +00:00
$workflowstate = null ;
if ( isset ( $version [ 'workflow' ]) && $version [ 'workflow' ]) {
if ( array_key_exists (( int ) $version [ 'workflow' ][ 'id' ], $objmap [ 'workflows' ])) {
$workflow = $dms -> getWorkflow ( $objmap [ 'workflows' ][( int ) $version [ 'workflow' ][ 'id' ]]);
2016-09-13 15:09:19 +00:00
if ( ! $workflow ) {
2016-09-15 12:01:01 +00:00
$logger -> warning ( " Workflow " . $version [ 'workflow' ][ 'id' ] . " cannot be mapped " );
2016-09-13 15:09:19 +00:00
}
} else {
2016-09-15 12:01:01 +00:00
$logger -> warning ( " Workflow " . $version [ 'workflow' ][ 'id' ] . " cannot be mapped " );
}
if ( array_key_exists (( int ) $version [ 'workflow' ][ 'state' ], $objmap [ 'workflowstates' ])) {
2016-09-15 19:44:21 +00:00
$workflowstate = $dms -> getWorkflowState ( $objmap [ 'workflowstates' ][( int ) $version [ 'workflow' ][ 'state' ]]);
2016-09-15 12:01:01 +00:00
if ( ! $workflowstate ) {
$logger -> warning ( " Workflowstate " . $version [ 'workflow' ][ 'state' ] . " cannot be mapped " );
}
} else {
$logger -> warning ( " Workflowstate " . $version [ 'workflow' ][ 'state' ] . " cannot be mapped " );
2016-09-13 15:09:19 +00:00
}
}
2015-07-30 19:05:06 +00:00
$version_attributes = array ();
2016-09-15 12:01:01 +00:00
if ( isset ( $version [ 'user_attributes' ])) {
foreach ( $version [ 'user_attributes' ] as $orgid => $value ) {
2015-07-30 19:05:06 +00:00
if ( array_key_exists (( int ) $orgid , $objmap [ 'attributedefs' ])) {
$version_attributes [ $objmap [ 'attributedefs' ][ $orgid ]] = $value ;
} else {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User attribute " . $orgid . " cannot be mapped " );
2015-07-30 19:05:06 +00:00
}
}
}
2016-09-15 12:01:01 +00:00
if ( ! empty ( $version [ 'fileref' ])) {
$filename = tempnam ( '/tmp' , 'FOO' );
copy ( $contentdir . $version [ 'fileref' ], $filename );
} else {
$filecontents = base64_decode ( $version [ 'data' ]);
if ( strlen ( $filecontents ) != $version [ 'data_length' ]) {
$logger -> warning ( " File length ( " . strlen ( $filecontents ) . " ) doesn't match expected length ( " . $version [ 'data_length' ] . " ). " );
}
$filename = tempnam ( '/tmp' , 'FOO' );
file_put_contents ( $filename , $filecontents );
}
if ( ! ( $result = $newDocument -> addContent (
$version [ 'attributes' ][ 'comment' ],
2015-07-30 09:24:56 +00:00
$owner ,
$filename ,
2016-09-15 12:01:01 +00:00
$version [ 'attributes' ][ 'orgfilename' ],
$version [ 'attributes' ][ 'filetype' ],
$version [ 'attributes' ][ 'mimetype' ],
2015-07-30 09:24:56 +00:00
$reviews , //reviewers
$approvals , //approvers
2016-09-15 12:01:01 +00:00
$version [ 'version' ],
2015-07-30 19:05:06 +00:00
$version_attributes ,
2016-09-13 15:09:19 +00:00
$workflow
2016-09-15 12:01:01 +00:00
))) {
2015-07-30 09:24:56 +00:00
unlink ( $filename );
2016-09-15 12:01:01 +00:00
$logger -> err ( " Could not add version ' " . $version [ 'version' ] . " ' of document ' " . $document [ 'attributes' ][ 'name' ] . " ' " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-07-30 09:24:56 +00:00
return false ;
2016-09-15 12:01:01 +00:00
}
2015-08-04 05:41:53 +00:00
2016-09-15 12:01:01 +00:00
$logger -> info ( " Added version ' " . $version [ 'version' ] . " ' of document ' " . $document [ 'attributes' ][ 'name' ] . " ' " );
$newVersion = $result -> getContent ();
2016-09-16 09:21:14 +00:00
unlink ( $filename );
2016-09-15 12:01:01 +00:00
if ( $workflowstate )
$newVersion -> setWorkflowState ( $workflowstate );
$newVersion -> setDate ( dateToTimestamp ( $version [ 'attributes' ][ 'date' ]));
2017-12-12 06:26:24 +00:00
if ( $version [ 'attributes' ][ 'revisiondate' ] && substr ( $version [ 'attributes' ][ 'revisiondate' ], 0 , 4 ) != '0000' )
$newVersion -> setRevisionDate ( $version [ 'attributes' ][ 'revisiondate' ]);
2016-09-15 12:01:01 +00:00
$newlogs = array ();
foreach ( $version [ 'statuslogs' ] as $i => $log ) {
if ( ! array_key_exists ( $log [ 'attributes' ][ 'user' ], $objmap [ 'users' ])) {
unset ( $version [ 'statuslogs' ][ $i ]);
$logger -> warning ( " User for status log cannot be mapped " );
} else {
$log [ 'attributes' ][ 'user' ] = $dms -> getUser ( $objmap [ 'users' ][ $log [ 'attributes' ][ 'user' ]]);
$newlogs [] = $log [ 'attributes' ];
2015-08-04 05:41:53 +00:00
}
2016-09-15 12:01:01 +00:00
}
$newVersion -> rewriteStatusLog ( $newlogs );
2015-08-04 05:41:53 +00:00
2016-09-15 12:01:01 +00:00
if ( $version [ 'reviews' ]) {
$newreviews = getRevAppLog ( $version [ 'reviews' ]);
$newVersion -> rewriteReviewLog ( $newreviews );
}
if ( $version [ 'approvals' ]) {
$newapprovals = getRevAppLog ( $version [ 'approvals' ]);
$newVersion -> rewriteApprovalLog ( $newapprovals );
}
2017-03-03 21:09:42 +00:00
if ( $version [ 'receipts' ]) {
$newreceipts = getRevAppLog ( $version [ 'receipts' ]);
$newVersion -> rewriteReceiptLog ( $newreceipts );
}
2017-07-27 19:17:11 +00:00
if ( $version [ 'revisions' ]) {
$newrevisions = getRevAppLog ( $version [ 'revisions' ]);
$newVersion -> rewriteRevisionLog ( $newrevisions );
}
2015-08-04 05:41:53 +00:00
2016-09-16 09:21:14 +00:00
if ( $version [ 'workflowlogs' ]) {
$newworkflowlogs = getWorkflowLog ( $version [ 'workflowlogs' ]);
if ( ! $newVersion -> rewriteWorkflowLog ( $newworkflowlogs )) {
$logger -> err ( " Could not rewrite workflow log of version ' " . $newVersion -> getVersion () . " ' of document ' " . $newDocument -> getName () . " ' " );
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
return false ;
}
}
2016-09-15 12:01:01 +00:00
}
2015-08-04 05:41:53 +00:00
2016-09-15 12:01:01 +00:00
if ( isset ( $document [ 'notifications' ][ 'users' ]) && $document [ 'notifications' ][ 'users' ]) {
foreach ( $document [ 'notifications' ][ 'users' ] as $userid ) {
if ( ! array_key_exists ( $userid , $objmap [ 'users' ])) {
$logger -> warning ( " User for notification cannot be mapped " );
} else {
$newDocument -> addNotify ( $objmap [ 'users' ][ $userid ], 1 );
2015-08-04 05:41:53 +00:00
}
2015-07-30 09:24:56 +00:00
}
2016-09-15 12:01:01 +00:00
}
if ( isset ( $document [ 'notifications' ][ 'groups' ]) && $document [ 'notifications' ][ 'groups' ]) {
foreach ( $document [ 'notifications' ][ 'groups' ] as $groupid ) {
if ( ! array_key_exists ( $groupid , $objmap [ 'groups' ])) {
$logger -> warning ( " User for notification cannot be mapped " );
} else {
$newDocument -> addNotify ( $objmap [ 'groups' ][ $groupid ], 0 );
2015-07-30 09:24:56 +00:00
}
}
2016-09-15 12:01:01 +00:00
}
if ( isset ( $document [ 'acls' ]) && $document [ 'acls' ]) {
foreach ( $document [ 'acls' ] as $acl ) {
if ( $acl [ 'type' ] == 'user' ) {
if ( ! array_key_exists ( $acl [ 'user' ], $objmap [ 'users' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User for notification cannot be mapped " );
2015-07-30 09:24:56 +00:00
} else {
2016-09-15 12:01:01 +00:00
$newDocument -> addAccess ( $acl [ 'mode' ], $objmap [ 'users' ][ $acl [ 'user' ]], 1 );
2015-07-30 09:24:56 +00:00
}
2016-09-15 12:01:01 +00:00
} elseif ( $acl [ 'type' ] == 'group' ) {
if ( ! array_key_exists ( $acl [ 'group' ], $objmap [ 'groups' ])) {
$logger -> warning ( " Group for notification cannot be mapped " );
2015-07-30 09:24:56 +00:00
} else {
2016-09-15 12:01:01 +00:00
$newDocument -> addAccess ( $acl [ 'mode' ], $objmap [ 'groups' ][ $acl [ 'group' ]], 0 );
2015-07-30 09:24:56 +00:00
}
}
}
2016-09-15 12:01:01 +00:00
}
if ( isset ( $document [ 'files' ]) && $document [ 'files' ]) {
foreach ( $document [ 'files' ] as $file ) {
if ( ! array_key_exists ( $file [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
$logger -> warning ( " User for file cannot be mapped " );
$owner = $defaultUser ;
} else {
$owner = $dms -> getUser ( $objmap [ 'users' ][ $file [ 'attributes' ][ 'owner' ]]);
2015-07-30 09:24:56 +00:00
}
2016-09-15 12:01:01 +00:00
if ( ! empty ( $file [ 'fileref' ])) {
$filename = tempnam ( '/tmp' , 'FOO' );
copy ( $contentdir . $file [ 'fileref' ], $filename );
} else {
$filecontents = base64_decode ( $file [ 'data' ]);
if ( strlen ( $filecontents ) != $file [ 'data_length' ]) {
$logger -> warning ( " File length ( " . strlen ( $filecontents ) . " ) doesn't match expected length ( " . $file [ 'data_length' ] . " ). " );
2015-07-30 09:24:56 +00:00
}
2016-09-15 12:01:01 +00:00
$filename = tempnam ( '/tmp' , 'FOO' );
file_put_contents ( $filename , $filecontents );
2015-07-30 09:24:56 +00:00
}
2017-12-12 08:48:32 +00:00
$newfile = $newDocument -> addDocumentFile (
2016-09-15 12:01:01 +00:00
$file [ 'attributes' ][ 'name' ],
$file [ 'attributes' ][ 'comment' ],
$owner ,
$filename ,
$file [ 'attributes' ][ 'orgfilename' ],
$file [ 'attributes' ][ 'filetype' ],
2017-03-09 08:34:16 +00:00
$file [ 'attributes' ][ 'mimetype' ],
$file [ 'attributes' ][ 'version' ],
2017-03-09 06:57:39 +00:00
$file [ 'attributes' ][ 'public' ]
2016-09-15 12:01:01 +00:00
);
2017-12-12 08:48:32 +00:00
$newfile -> setDate ( dateToTimestamp ( $file [ 'attributes' ][ 'date' ]));
2016-09-15 12:01:01 +00:00
unlink ( $filename );
2015-07-30 09:24:56 +00:00
}
}
} else {
$newDocument = null ;
}
if ( $newDocument )
$objmap [ 'documents' ][ $document [ 'id' ]] = $newDocument -> getID ();
return $newDocument ;
2012-12-13 21:35:32 +00:00
} /* }}} */
function insert_folder ( $folder ) { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $objmap , $defaultUser , $sections , $rootfolder ;
2015-07-30 09:24:56 +00:00
if ( $debug ) print_r ( $folder );
if ( in_array ( 'folders' , $sections )) {
if ( ! array_key_exists ( $folder [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " Owner of folder cannot be mapped using default user " );
2015-07-30 09:24:56 +00:00
$owner = $defaultuser ;
} else {
$owner = $dms -> getUser ( $objmap [ 'users' ][( int ) $folder [ 'attributes' ][ 'owner' ]]);
}
$attributes = array ();
if ( isset ( $folder [ 'user_attributes' ])) {
foreach ( $folder [ 'user_attributes' ] as $orgid => $value ) {
if ( array_key_exists (( int ) $orgid , $objmap [ 'attributedefs' ])) {
$attributes [ $objmap [ 'attributedefs' ][ $orgid ]] = $value ;
} else {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User attribute " . $orgid . " cannot be mapped " );
2015-07-30 09:24:56 +00:00
}
}
}
if ( isset ( $folder [ 'folder' ]) && $folder [ 'folder' ]) {
if ( array_key_exists ( $folder [ 'folder' ], $objmap [ 'folders' ])) {
$parent = $dms -> getFolder ( $objmap [ 'folders' ][ $folder [ 'folder' ]]);
} else {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Folder " . $folder [ 'folder' ] . " cannot be mapped " );
2015-07-30 09:24:56 +00:00
exit ;
}
} else
$parent = $rootfolder ;
if ( ! $newFolder = $parent -> addSubFolder ( $folder [ 'attributes' ][ 'name' ], $folder [ 'attributes' ][ 'comment' ], $owner , $folder [ 'attributes' ][ 'sequence' ], $attributes )) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add folder " );
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-07-30 09:24:56 +00:00
return false ;
2016-09-13 15:09:19 +00:00
} else {
$logger -> info ( " Added folder ' " . $folder [ 'attributes' ][ 'name' ] . " ' " );
2015-07-30 09:24:56 +00:00
}
2015-08-04 05:41:53 +00:00
$newFolder -> setDate ( dateToTimestamp ( $folder [ 'attributes' ][ 'date' ]));
2015-07-30 09:24:56 +00:00
$newFolder -> setDefaultAccess ( $folder [ 'attributes' ][ 'defaultaccess' ]);
2016-09-15 12:01:01 +00:00
$newFolder -> setInheritAccess ( $folder [ 'attributes' ][ 'inheritaccess' ]);
2015-07-30 09:24:56 +00:00
if ( isset ( $folder [ 'notifications' ][ 'users' ]) && $folder [ 'notifications' ][ 'users' ]) {
foreach ( $folder [ 'notifications' ][ 'users' ] as $userid ) {
if ( ! array_key_exists ( $userid , $objmap [ 'users' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User for notification cannot be mapped " );
2015-07-30 09:24:56 +00:00
} else {
$newFolder -> addNotify ( $objmap [ 'users' ][ $userid ], 1 );
}
}
}
if ( isset ( $folder [ 'notifications' ][ 'groups' ]) && $folder [ 'notifications' ][ 'groups' ]) {
foreach ( $folder [ 'notifications' ][ 'groups' ] as $groupid ) {
if ( ! array_key_exists ( $groupid , $objmap [ 'groups' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User for notification cannot be mapped " );
2015-07-30 09:24:56 +00:00
} else {
$newFolder -> addNotify ( $objmap [ 'groups' ][ $groupid ], 0 );
}
}
}
if ( isset ( $folder [ 'acls' ]) && $folder [ 'acls' ]) {
foreach ( $folder [ 'acls' ] as $acl ) {
if ( $acl [ 'type' ] == 'user' ) {
if ( ! array_key_exists ( $acl [ 'user' ], $objmap [ 'users' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User for notification cannot be mapped " );
2015-07-30 09:24:56 +00:00
} else {
$newFolder -> addAccess ( $acl [ 'mode' ], $objmap [ 'users' ][ $acl [ 'user' ]], 1 );
}
} elseif ( $acl [ 'type' ] == 'group' ) {
if ( ! array_key_exists ( $acl [ 'group' ], $objmap [ 'groups' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " Group for notification cannot be mapped " );
2015-07-30 09:24:56 +00:00
} else {
$newFolder -> addAccess ( $acl [ 'mode' ], $objmap [ 'groups' ][ $acl [ 'group' ]], 0 );
}
}
}
}
} else {
$newFolder = null ;
}
if ( $newFolder )
$objmap [ 'folders' ][ $folder [ 'id' ]] = $newFolder -> getID ();
return $newFolder ;
} /* }}} */
2015-08-05 20:46:30 +00:00
function insert_transmittal ( $transmittal ) { /* {{{ */
2016-09-15 19:40:38 +00:00
global $logger , $dms , $debug , $objmap , $sections ;
2015-08-05 20:46:30 +00:00
2016-09-15 19:40:38 +00:00
if ( $debug ) print_r ( $transmittal );
2015-08-05 20:46:30 +00:00
if ( ! array_key_exists (( int ) $transmittal [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
2016-09-15 19:40:38 +00:00
$logger -> err ( " Owner of transmittal cannot be found " );
2015-08-05 20:46:30 +00:00
return false ;
}
$owner = $dms -> getUser ( $objmap [ 'users' ][( int ) $transmittal [ 'attributes' ][ 'owner' ]]);
if ( in_array ( 'transmittals' , $sections )) {
if ( ! $newTransmittal = $dms -> addTransmittal ( $transmittal [ 'attributes' ][ 'name' ], $transmittal [ 'attributes' ][ 'comment' ], $owner )) {
2016-09-15 19:40:38 +00:00
$logger -> err ( " Could not add transmittal " );
2016-09-16 10:48:43 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-08-05 20:46:30 +00:00
return false ;
}
foreach ( $transmittal [ 'items' ] as $item ) {
if ( ! array_key_exists (( int ) $item [ 'attributes' ][ 'document' ], $objmap [ 'documents' ])) {
2016-09-15 19:40:38 +00:00
$logger -> warning ( " Document mapping of transmittal item cannot be found " );
2015-08-05 20:46:30 +00:00
} else {
if ( $document = $dms -> getDocument ( $objmap [ 'documents' ][( int ) $item [ 'attributes' ][ 'document' ]])) {
if ( $content = $document -> getContentByVersion (( int ) $item [ 'attributes' ][ 'version' ])) {
$newTransmittal -> addContent ( $content );
} else {
2016-09-15 19:40:38 +00:00
$logger -> warning ( " Document version of transmittal item cannot be found " );
2015-08-05 20:46:30 +00:00
}
} else {
2016-09-15 19:40:38 +00:00
$logger -> warning ( " Document of transmittal item cannot be found " );
2015-08-05 20:46:30 +00:00
}
}
}
} else {
$newTransmittal = null ;
}
if ( $newTransmittal )
2015-08-06 04:25:06 +00:00
$objmap [ 'transmittals' ][ $transmittal [ 'id' ]] = $newTransmittal -> getID ();
2016-09-16 10:48:43 +00:00
return $newTransmittal ;
2015-08-05 20:46:30 +00:00
} /* }}} */
2015-07-30 09:24:56 +00:00
function resolve_links () { /* {{{ */
2016-09-13 15:09:19 +00:00
global $logger , $dms , $debug , $defaultUser , $links , $objmap ;
2015-07-30 09:24:56 +00:00
2016-09-08 13:20:13 +00:00
if ( ! $links )
return ;
2015-07-30 09:24:56 +00:00
if ( $debug )
print_r ( $links );
foreach ( $links as $documentid => $doclinks ) {
if ( array_key_exists ( $documentid , $objmap [ 'documents' ])) {
if ( $doc = $dms -> getDocument ( $objmap [ 'documents' ][ $documentid ])) {
foreach ( $doclinks as $doclink ) {
if ( array_key_exists ( $doclink [ 'attributes' ][ 'target' ], $objmap [ 'documents' ])) {
if ( $target = $dms -> getDocument ( $objmap [ 'documents' ][ $doclink [ 'attributes' ][ 'target' ]])) {
if ( ! array_key_exists ( $doclink [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " User for link cannot be mapped using default user " );
2015-07-30 09:24:56 +00:00
$owner = $defaultUser ;
} else {
$owner = $dms -> getUser ( $objmap [ 'users' ][ $doclink [ 'attributes' ][ 'owner' ]]);
}
if ( ! $doc -> addDocumentLink ( $target -> getID (), $owner -> getID (), $doclink [ 'attributes' ][ 'public' ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not add document link from " . $doc -> getID () . " to " . $target -> getID ());
2016-09-15 19:44:21 +00:00
$logger -> debug ( $dms -> getDB () -> getErrorMsg ());
2015-07-30 09:24:56 +00:00
}
} else {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " Target document not found in database " );
2015-07-30 09:24:56 +00:00
}
} else {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " Target document not found in object mapping " );
2015-07-30 09:24:56 +00:00
}
}
} else {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " Document not found in database " );
2015-07-30 09:24:56 +00:00
}
} else {
2016-09-13 15:09:19 +00:00
$logger -> warning ( " Document not found in object mapping " );
2015-07-30 09:24:56 +00:00
}
}
2012-12-13 21:35:32 +00:00
} /* }}} */
2016-09-15 12:01:01 +00:00
function set_mandatory () { /* {{{ */
global $logger , $dms , $users , $objmap ;
if ( ! $users )
return ;
foreach ( $users as $user ) {
if ( $newUser = $dms -> getUserByLogin ( $user [ 'attributes' ][ 'login' ])) {
if ( $user [ 'individual' ][ 'reviewers' ]) {
foreach ( $user [ 'individual' ][ 'reviewers' ] as $u ) {
if ( $uobj = $dms -> getUser ( $objmap [ 'users' ][ $u ])) {
$newUser -> setMandatoryReviewer ( $uobj -> getID (), false );
}
}
}
if ( $user [ 'individual' ][ 'approvers' ]) {
foreach ( $user [ 'individual' ][ 'approvers' ] as $u ) {
if ( $uobj = $dms -> getUser ( $objmap [ 'users' ][ $u ])) {
$newUser -> setMandatoryApprover ( $uobj -> getID (), false );
}
}
}
if ( $user [ 'group' ][ 'reviewers' ]) {
foreach ( $user [ 'group' ][ 'reviewers' ] as $u ) {
if ( $uobj = $dms -> getGroup ( $objmap [ 'groups' ][ $u ])) {
$newUser -> setMandatoryReviewer ( $uobj -> getID (), true );
}
}
}
if ( $user [ 'group' ][ 'approvers' ]) {
foreach ( $user [ 'group' ][ 'approvers' ] as $u ) {
if ( $uobj = $dms -> getGroup ( $objmap [ 'groups' ][ $u ])) {
$newUser -> setMandatoryApprover ( $uobj -> getID (), true );
}
}
}
2015-07-30 09:24:56 +00:00
}
}
2012-12-13 21:35:32 +00:00
} /* }}} */
function startElement ( $parser , $name , $attrs ) { /* {{{ */
2017-07-27 19:17:11 +00:00
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_receipt , $cur_receiptlog , $cur_revision , $cur_revisionlog , $cur_attrdef , $cur_documentcat , $cur_keyword , $cur_keywordcat , $cur_file , $cur_link , $cur_workflow , $cur_workflowtransition , $cur_workflowaction , $cur_workflowstate , $cur_transition , $cur_transmittal , $cur_transmittalitem , $cur_role , $cur_acopath , $cur_acos ;
2012-12-13 21:35:32 +00:00
$parent = end ( $elementstack );
array_push ( $elementstack , array ( 'name' => $name , 'attributes' => $attrs ));
switch ( $name ) {
2015-08-06 04:43:43 +00:00
case " DMS " :
if ( ! $noversioncheck ) {
$xdbversion = explode ( '.' , $attrs [ 'DBVERSION' ]);
$dbversion = $dms -> getDBVersion ();
if (( $xdbversion [ 0 ] != $dbversion [ 'major' ]) || ( $xdbversion [ 1 ] != $dbversion [ 'minor' ])) {
2016-09-13 15:09:19 +00:00
$logger -> crit ( " Database version ( " . implode ( '.' , array ( $dbversion [ 'major' ], $dbversion [ 'minor' ], $dbversion [ 'subminor' ])) . " ) doesn't match version in input file ( " . implode ( '.' , $xdbversion ) . " ). " );
2015-08-06 04:43:43 +00:00
exit ( 1 );
}
}
break ;
2012-12-13 21:35:32 +00:00
case " USER " :
2015-07-30 09:24:56 +00:00
/* users can be the users data , the member of a group , a mandatory
2016-09-08 13:20:13 +00:00
* reviewer or approver , a workflow transition
2015-07-30 09:24:56 +00:00
*/
2012-12-13 21:35:32 +00:00
$first = $elementstack [ 1 ];
2016-09-08 13:20:13 +00:00
$second = $elementstack [ 2 ];
2012-12-13 21:35:32 +00:00
if ( $first [ 'name' ] == 'USERS' ) {
2015-07-30 09:24:56 +00:00
if ( $parent [ 'name' ] == 'MANDATORY_REVIEWERS' ) {
$cur_user [ 'individual' ][ 'reviewers' ][] = ( int ) $attrs [ 'ID' ];
} elseif ( $parent [ 'name' ] == 'MANDATORY_APPROVERS' ) {
$cur_user [ 'individual' ][ 'approvers' ][] = ( int ) $attrs [ 'ID' ];
} else {
$cur_user = array ();
$cur_user [ 'id' ] = ( int ) $attrs [ 'ID' ];
$cur_user [ 'attributes' ] = array ();
$cur_user [ 'individual' ][ 'reviewers' ] = array ();
$cur_user [ 'individual' ][ 'approvers' ] = array ();
2016-09-08 13:20:13 +00:00
$cur_user [ 'group' ][ 'reviewers' ] = array ();
$cur_user [ 'group' ][ 'approvers' ] = array ();
$cur_user [ 'workflows' ] = array ();
2015-07-30 09:24:56 +00:00
}
2012-12-13 21:35:32 +00:00
} elseif ( $first [ 'name' ] == 'GROUPS' ) {
2015-07-30 09:24:56 +00:00
$cur_group [ 'users' ][] = ( int ) $attrs [ 'USER' ];
} elseif ( $parent [ 'name' ] == 'NOTIFICATIONS' ) {
if ( $first [ 'name' ] == 'FOLDER' ) {
$cur_folder [ 'notifications' ][ 'users' ][] = ( int ) $attrs [ 'ID' ];
} elseif ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'notifications' ][ 'users' ][] = ( int ) $attrs [ 'ID' ];
}
2016-09-08 13:20:13 +00:00
} elseif ( $second [ 'name' ] == 'WORKFLOW' ) {
$cur_transition [ 'users' ][] = ( int ) $attrs [ 'ID' ];
2012-12-13 21:35:32 +00:00
}
break ;
case " GROUP " :
$first = $elementstack [ 1 ];
2016-09-08 13:20:13 +00:00
$second = $elementstack [ 2 ];
2012-12-13 21:35:32 +00:00
if ( $first [ 'name' ] == 'GROUPS' ) {
$cur_group = array ();
2015-07-30 09:24:56 +00:00
$cur_group [ 'id' ] = ( int ) $attrs [ 'ID' ];
2012-12-13 21:35:32 +00:00
$cur_group [ 'attributes' ] = array ();
2015-07-30 09:24:56 +00:00
$cur_group [ 'users' ] = array ();
} elseif ( $first [ 'name' ] == 'USERS' ) {
if ( $parent [ 'name' ] == 'MANDATORY_REVIEWERS' ) {
$cur_user [ 'group' ][ 'reviewers' ][] = ( int ) $attrs [ 'ID' ];
} elseif ( $parent [ 'name' ] == 'MANDATORY_APPROVERS' ) {
$cur_user [ 'group' ][ 'approvers' ][] = ( int ) $attrs [ 'ID' ];
}
} elseif ( $parent [ 'name' ] == 'NOTIFICATIONS' ) {
if ( $first [ 'name' ] == 'FOLDER' ) {
$cur_folder [ 'notifications' ][ 'groups' ][] = ( int ) $attrs [ 'ID' ];
} elseif ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'notifications' ][ 'groups' ][] = ( int ) $attrs [ 'ID' ];
}
2016-09-08 13:20:13 +00:00
} elseif ( $second [ 'name' ] == 'WORKFLOW' ) {
$cur_transition [ 'groups' ][] = ( int ) $attrs [ 'ID' ];
2012-12-13 21:35:32 +00:00
}
break ;
2016-09-22 06:48:28 +00:00
case " ACO " :
array_push ( $cur_acopath , $attrs [ 'ALIAS' ]);
$cur_acos [ implode ( '/' , $cur_acopath )] = array ();
break ;
2016-09-15 19:40:38 +00:00
case " ROLE " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'ROLES' ) {
$cur_role = array ();
$cur_role [ 'id' ] = ( int ) $attrs [ 'ID' ];
$cur_role [ 'attributes' ] = array ();
2016-09-22 06:48:28 +00:00
$cur_role [ 'acos' ] = array ();
$cur_acopath = array ();
$cur_acos = array ();
2016-09-15 19:40:38 +00:00
}
break ;
2015-08-05 20:46:30 +00:00
case " TRANSMITTAL " :
$cur_transmittal = array ();
$cur_transmittal [ 'id' ] = ( int ) $attrs [ 'ID' ];
$cur_transmittal [ 'attributes' ] = array ();
$cur_transmittal [ 'items' ] = array ();
break ;
2016-09-16 10:48:43 +00:00
case " ITEM " :
2015-08-05 20:46:30 +00:00
$cur_transmittalitem = array ();
$cur_transmittalitem [ 'id' ] = ( int ) $attrs [ 'ID' ];
$cur_transmittalitem [ 'attributes' ] = array ();
break ;
2012-12-13 21:35:32 +00:00
case " DOCUMENT " :
$cur_document = array ();
2015-07-30 09:24:56 +00:00
$cur_document [ 'id' ] = ( int ) $attrs [ 'ID' ];
2016-09-13 15:09:19 +00:00
if ( isset ( $attrs [ 'FOLDER' ]))
$cur_document [ 'folder' ] = ( int ) $attrs [ 'FOLDER' ];
if ( isset ( $attrs [ 'LOCKED' ]) && $attrs [ 'LOCKED' ] == 'true' )
$cur_document [ 'locked' ] = true ;
2012-12-13 21:35:32 +00:00
$cur_document [ 'attributes' ] = array ();
$cur_document [ 'versions' ] = array ();
break ;
case " FOLDER " :
$cur_folder = array ();
2015-07-30 09:24:56 +00:00
$cur_folder [ 'id' ] = ( int ) $attrs [ 'ID' ];
2012-12-13 21:35:32 +00:00
if ( isset ( $attrs [ 'PARENT' ]))
2015-07-30 09:24:56 +00:00
$cur_folder [ 'folder' ] = ( int ) $attrs [ 'PARENT' ];
2012-12-13 21:35:32 +00:00
$cur_folder [ 'attributes' ] = array ();
break ;
case " VERSION " :
$cur_version = array ();
2015-07-30 09:24:56 +00:00
$cur_version [ 'version' ] = ( int ) $attrs [ 'VERSION' ];
2012-12-13 21:35:32 +00:00
$cur_version [ 'attributes' ] = array ();
$cur_version [ 'approvals' ] = array ();
$cur_version [ 'reviews' ] = array ();
2017-03-03 21:09:42 +00:00
$cur_version [ 'receipts' ] = array ();
2017-07-27 19:17:11 +00:00
$cur_version [ 'revisions' ] = array ();
2016-09-13 15:09:19 +00:00
$cur_version [ 'statuslogs' ] = array ();
$cur_version [ 'workflowlogs' ] = array ();
2012-12-13 21:35:32 +00:00
break ;
2015-07-31 13:31:34 +00:00
case " STATUSLOG " :
$cur_statuslog = array ();
$cur_statuslog [ 'attributes' ] = array ();
break ;
2016-09-13 15:09:19 +00:00
case " WORKFLOWLOGS " :
$cur_version [ 'workflowlogs' ] = array ();
break ;
case " WORKFLOWLOG " :
$cur_workflowlog = array ();
$cur_workflowlog [ 'attributes' ] = array ();
break ;
2012-12-13 21:35:32 +00:00
case " APPROVAL " :
$cur_approval = array ();
$cur_approval [ 'attributes' ] = array ();
2015-07-30 09:24:56 +00:00
$cur_approval [ 'logs' ] = array ();
break ;
case " APPROVALLOG " :
$cur_approvallog = array ();
$cur_approvallog [ 'attributes' ] = array ();
2012-12-13 21:35:32 +00:00
break ;
case " REVIEW " :
$cur_review = array ();
$cur_review [ 'attributes' ] = array ();
2015-07-30 09:24:56 +00:00
$cur_review [ 'logs' ] = array ();
break ;
case " REVIEWLOG " :
$cur_reviewlog = array ();
$cur_reviewlog [ 'attributes' ] = array ();
2012-12-13 21:35:32 +00:00
break ;
2017-03-03 21:09:42 +00:00
case " RECEIPT " :
$cur_receipt = array ();
$cur_receipt [ 'attributes' ] = array ();
$cur_receipt [ 'logs' ] = array ();
break ;
case " RECEIPTLOG " :
$cur_receiptlog = array ();
$cur_receiptlog [ 'attributes' ] = array ();
break ;
2017-07-27 19:17:11 +00:00
case " REVISION " :
$cur_revision = array ();
$cur_revision [ 'attributes' ] = array ();
$cur_revision [ 'logs' ] = array ();
break ;
case " REVISIONLOG " :
$cur_revisionlog = array ();
$cur_revisionlog [ 'attributes' ] = array ();
break ;
2012-12-13 21:35:32 +00:00
case 'ATTRIBUTEDEFINITION' :
$cur_attrdef = array ();
2015-07-30 09:24:56 +00:00
$cur_attrdef [ 'id' ] = ( int ) $attrs [ 'ID' ];
2012-12-13 21:35:32 +00:00
$cur_attrdef [ 'attributes' ] = array ();
$cur_attrdef [ 'objecttype' ] = $attrs [ 'OBJTYPE' ];
break ;
case " ATTR " :
if ( $parent [ 'name' ] == 'DOCUMENT' ) {
if ( isset ( $attrs [ 'TYPE' ]) && $attrs [ 'TYPE' ] == 'user' ) {
$cur_document [ 'user_attributes' ][ $attrs [ 'ATTRDEF' ]] = '' ;
} else {
$cur_document [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
}
} elseif ( $parent [ 'name' ] == 'VERSION' ) {
if ( isset ( $attrs [ 'TYPE' ]) && $attrs [ 'TYPE' ] == 'user' ) {
$cur_version [ 'user_attributes' ][ $attrs [ 'ATTRDEF' ]] = '' ;
} else {
$cur_version [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
}
2015-07-31 13:31:34 +00:00
} elseif ( $parent [ 'name' ] == 'STATUSLOG' ) {
$cur_statuslog [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2016-09-13 15:09:19 +00:00
} elseif ( $parent [ 'name' ] == 'WORKFLOWLOG' ) {
$cur_workflowlog [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2012-12-13 21:35:32 +00:00
} elseif ( $parent [ 'name' ] == 'APPROVAL' ) {
$cur_approval [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2015-07-30 09:24:56 +00:00
} elseif ( $parent [ 'name' ] == 'APPROVALLOG' ) {
$cur_approvallog [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2012-12-13 21:35:32 +00:00
} elseif ( $parent [ 'name' ] == 'REVIEW' ) {
$cur_review [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2015-07-30 09:24:56 +00:00
} elseif ( $parent [ 'name' ] == 'REVIEWLOG' ) {
$cur_reviewlog [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2017-03-03 21:09:42 +00:00
} elseif ( $parent [ 'name' ] == 'RECEIPT' ) {
$cur_receipt [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
} elseif ( $parent [ 'name' ] == 'RECEIPTLOG' ) {
$cur_receiptlog [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2017-07-27 19:17:11 +00:00
} elseif ( $parent [ 'name' ] == 'REVISION' ) {
$cur_revision [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
} elseif ( $parent [ 'name' ] == 'REVISIONLOG' ) {
$cur_revisionlog [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2012-12-13 21:35:32 +00:00
} elseif ( $parent [ 'name' ] == 'FOLDER' ) {
if ( isset ( $attrs [ 'TYPE' ]) && $attrs [ 'TYPE' ] == 'user' ) {
$cur_folder [ 'user_attributes' ][ $attrs [ 'ATTRDEF' ]] = '' ;
} else {
$cur_folder [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
}
} elseif ( $parent [ 'name' ] == 'USER' ) {
$cur_user [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2015-07-30 09:24:56 +00:00
} elseif ( $parent [ 'name' ] == 'GROUP' ) {
$cur_group [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2016-09-15 19:40:38 +00:00
} elseif ( $parent [ 'name' ] == 'ROLE' ) {
$cur_role [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2016-09-22 06:48:28 +00:00
} elseif ( $parent [ 'name' ] == 'ACO' ) {
$cur_acos [ implode ( '/' , $cur_acopath )][ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2015-07-30 09:24:56 +00:00
} elseif ( $parent [ 'name' ] == 'KEYWORD' ) {
$cur_keyword [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
} elseif ( $parent [ 'name' ] == 'ATTRIBUTEDEFINITION' ) {
$cur_attrdef [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
} elseif ( $parent [ 'name' ] == 'FILE' ) {
$cur_file [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
} elseif ( $parent [ 'name' ] == 'LINK' ) {
$cur_link [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2015-08-05 20:46:30 +00:00
} elseif ( $parent [ 'name' ] == 'TRANSMITTAL' ) {
$cur_transmittal [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2016-09-16 10:48:43 +00:00
} elseif ( $parent [ 'name' ] == 'ITEM' ) {
2015-08-05 20:46:30 +00:00
$cur_transmittalitem [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2016-09-08 13:20:13 +00:00
} elseif ( $parent [ 'name' ] == 'WORKFLOW' ) {
$cur_workflow [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
} elseif ( $parent [ 'name' ] == 'WORKFLOWTRANSITION' ) {
$cur_workflowtransition [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
} elseif ( $parent [ 'name' ] == 'WORKFLOWACTION' ) {
$cur_workflowaction [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
} elseif ( $parent [ 'name' ] == 'TRANSITION' ) {
$cur_transition [ 'attributes' ][ $attrs [ 'NAME' ]] = '' ;
2015-07-30 09:24:56 +00:00
}
break ;
case " CATEGORIES " :
if ( $parent [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'categories' ] = array ();
}
break ;
case " CATEGORY " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'categories' ][] = ( int ) $attrs [ 'ID' ];
}
break ;
case " ACLS " :
if ( $parent [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'acls' ] = array ();
} elseif ( $parent [ 'name' ] == 'FOLDER' ) {
$cur_folder [ 'acls' ] = array ();
2012-12-13 21:35:32 +00:00
}
break ;
case " ACL " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'FOLDER' ) {
$acl = array ( 'type' => $attrs [ 'TYPE' ], 'mode' => $attrs [ 'MODE' ]);
if ( $attrs [ 'TYPE' ] == 'user' ) {
$acl [ 'user' ] = $attrs [ 'USER' ];
} elseif ( $attrs [ 'TYPE' ] == 'group' ) {
$acl [ 'group' ] = $attrs [ 'GROUP' ];
}
$cur_folder [ 'acls' ][] = $acl ;
} elseif ( $first [ 'name' ] == 'DOCUMENT' ) {
$acl = array ( 'type' => $attrs [ 'TYPE' ], 'mode' => $attrs [ 'MODE' ]);
if ( $attrs [ 'TYPE' ] == 'user' ) {
$acl [ 'user' ] = $attrs [ 'USER' ];
} elseif ( $attrs [ 'TYPE' ] == 'group' ) {
$acl [ 'group' ] = $attrs [ 'GROUP' ];
}
$cur_document [ 'acls' ][] = $acl ;
}
break ;
case " DATA " :
if ( $parent [ 'name' ] == 'IMAGE' ) {
$cur_user [ 'image' ][ 'id' ] = $parent [ 'attributes' ][ 'ID' ];
$cur_user [ 'image' ][ 'data' ] = " " ;
} elseif ( $parent [ 'name' ] == 'VERSION' ) {
2015-07-30 09:24:56 +00:00
$cur_version [ 'data_length' ] = ( int ) $attrs [ 'LENGTH' ];
if ( isset ( $attrs [ 'FILEREF' ]))
$cur_version [ 'fileref' ] = $attrs [ 'FILEREF' ];
else
$cur_version [ 'data' ] = " " ;
} elseif ( $parent [ 'name' ] == 'FILE' ) {
$cur_file [ 'data_length' ] = ( int ) $attrs [ 'LENGTH' ];
if ( isset ( $attrs [ 'FILEREF' ]))
$cur_file [ 'fileref' ] = $attrs [ 'FILEREF' ];
else
$cur_file [ 'data' ] = " " ;
2016-09-15 12:01:01 +00:00
} elseif ( $parent [ 'name' ] == 'REVIEWLOG' ) {
$cur_reviewlog [ 'data_length' ] = ( int ) $attrs [ 'LENGTH' ];
if ( isset ( $attrs [ 'FILEREF' ]))
$cur_reviewlog [ 'fileref' ] = $attrs [ 'FILEREF' ];
else
$cur_reviewlog [ 'data' ] = " " ;
2012-12-13 21:35:32 +00:00
}
break ;
case " KEYWORD " :
$cur_keyword = array ();
2015-07-30 09:24:56 +00:00
$cur_keyword [ 'id' ] = ( int ) $attrs [ 'ID' ];
2012-12-13 21:35:32 +00:00
$cur_keyword [ 'attributes' ] = array ();
break ;
case " KEYWORDCATEGORY " :
$cur_keywordcat = array ();
2015-07-30 09:24:56 +00:00
$cur_keywordcat [ 'id' ] = ( int ) $attrs [ 'ID' ];
2012-12-13 21:35:32 +00:00
$cur_keywordcat [ 'attributes' ] = array ();
$cur_keywordcat [ 'keywords' ] = array ();
break ;
case " DOCUMENTCATEGORY " :
$cur_documentcat = array ();
2015-07-30 09:24:56 +00:00
$cur_documentcat [ 'id' ] = ( int ) $attrs [ 'ID' ];
2012-12-13 21:35:32 +00:00
$cur_documentcat [ 'attributes' ] = array ();
break ;
2015-07-30 09:24:56 +00:00
case " NOTIFICATIONS " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'FOLDER' ) {
$cur_folder [ 'notifications' ] = array ( 'users' => array (), 'groups' => array ());
} elseif ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'notifications' ] = array ( 'users' => array (), 'groups' => array ());
}
break ;
case " FILES " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'files' ] = array ();
}
break ;
case " FILE " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_file = array ();
$cur_file [ 'id' ] = ( int ) $attrs [ 'ID' ];
}
break ;
case " LINKS " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'links' ] = array ();
}
break ;
case " LINK " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_link = array ();
$cur_link [ 'id' ] = ( int ) $attrs [ 'ID' ];
}
break ;
2016-09-08 13:20:13 +00:00
case " TRANSITIONS " :
$first = $elementstack [ 2 ];
if ( $first [ 'name' ] == 'WORKFLOW' ) {
$cur_workflow [ 'transitions' ] = array ();
}
break ;
case " TRANSITION " :
$first = $elementstack [ 2 ];
if ( $first [ 'name' ] == 'WORKFLOW' ) {
$cur_transition = array ();
$cur_transition [ 'id' ] = ( int ) $attrs [ 'ID' ];
$cur_transition [ 'users' ] = array ();
$cur_transition [ 'groups' ] = array ();
}
break ;
case " WORKFLOW " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'WORKFLOWS' ) {
$cur_workflow = array ();
$cur_workflow [ 'id' ] = ( int ) $attrs [ 'ID' ];
} elseif ( $parent [ 'name' ] == 'MANDATORY_WORKFLOWS' ) {
$cur_user [ 'workflows' ][] = ( int ) $attrs [ 'ID' ];
2016-09-13 15:09:19 +00:00
} elseif ( $parent [ 'name' ] == 'VERSION' ) {
$cur_version [ 'workflow' ] = array ( 'id' => ( int ) $attrs [ 'ID' ], 'state' => ( int ) $attrs [ 'STATE' ]);
2016-09-08 13:20:13 +00:00
}
break ;
case " WORKFLOWACTION " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'WORKFLOWACTIONS' ) {
$cur_workflowaction = array ();
$cur_workflowaction [ 'id' ] = ( int ) $attrs [ 'ID' ];
}
break ;
case " WORKFLOWSTATE " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'WORKFLOWSTATES' ) {
$cur_workflowstate = array ();
$cur_workflowstate [ 'id' ] = ( int ) $attrs [ 'ID' ];
}
break ;
2012-12-13 21:35:32 +00:00
}
} /* }}} */
function endElement ( $parser , $name ) { /* {{{ */
2017-07-27 19:17:11 +00:00
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_receipt , $cur_receiptlog , $cur_revision , $cur_revisionlog , $cur_attrdef , $cur_documentcat , $cur_keyword , $cur_keywordcat , $cur_file , $cur_link , $cur_workflow , $cur_workflowlog , $cur_workflowtransition , $cur_workflowaction , $cur_workflowstate , $cur_transition , $cur_transmittal , $cur_transmittalitem , $cur_role , $cur_acopath , $cur_acos ;
2012-12-13 21:35:32 +00:00
array_pop ( $elementstack );
$parent = end ( $elementstack );
switch ( $name ) {
case " DOCUMENT " :
2015-07-30 09:24:56 +00:00
insert_document ( $cur_document );
if ( ! empty ( $cur_document [ 'links' ]))
$links [ $cur_document [ 'id' ]] = $cur_document [ 'links' ];
2012-12-13 21:35:32 +00:00
break ;
case " FOLDER " :
2015-07-30 09:24:56 +00:00
insert_folder ( $cur_folder );
2012-12-13 21:35:32 +00:00
break ;
case " VERSION " :
$cur_document [ 'versions' ][] = $cur_version ;
break ;
2015-07-31 13:31:34 +00:00
case " STATUSLOG " :
$cur_version [ 'statuslogs' ][] = $cur_statuslog ;
break ;
2016-09-13 15:09:19 +00:00
case " WORKFLOWLOG " :
$cur_version [ 'workflowlogs' ][] = $cur_workflowlog ;
break ;
2012-12-13 21:35:32 +00:00
case " APPROVAL " :
$cur_version [ 'approvals' ][] = $cur_approval ;
break ;
2015-07-30 09:24:56 +00:00
case " APPROVALLOG " :
$cur_approval [ 'logs' ][] = $cur_approvallog ;
break ;
2012-12-13 21:35:32 +00:00
case " REVIEW " :
$cur_version [ 'reviews' ][] = $cur_review ;
break ;
2015-07-30 09:24:56 +00:00
case " REVIEWLOG " :
$cur_review [ 'logs' ][] = $cur_reviewlog ;
break ;
2017-03-03 21:09:42 +00:00
case " RECEIPT " :
$cur_version [ 'receipts' ][] = $cur_receipt ;
break ;
case " RECEIPTLOG " :
$cur_receipt [ 'logs' ][] = $cur_receiptlog ;
break ;
2017-07-27 19:17:11 +00:00
case " REVISION " :
$cur_version [ 'revisions' ][] = $cur_revision ;
break ;
case " REVISIONLOG " :
$cur_revision [ 'logs' ][] = $cur_revisionlog ;
break ;
2012-12-13 21:35:32 +00:00
case " USER " :
/* users can be the users data or the member of a group */
$first = $elementstack [ 1 ];
2015-07-31 13:31:34 +00:00
if ( $first [ 'name' ] == 'USERS' && $parent [ 'name' ] == 'USERS' ) {
2012-12-13 21:35:32 +00:00
$users [ $cur_user [ 'id' ]] = $cur_user ;
2015-07-30 09:24:56 +00:00
insert_user ( $cur_user );
2012-12-13 21:35:32 +00:00
}
break ;
case " GROUP " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'GROUPS' ) {
$groups [ $cur_group [ 'id' ]] = $cur_group ;
2015-07-30 09:24:56 +00:00
insert_group ( $cur_group );
2012-12-13 21:35:32 +00:00
}
break ;
2016-09-22 06:48:28 +00:00
case 'ACO' :
array_pop ( $cur_acopath );
break ;
2016-09-15 19:40:38 +00:00
case 'ROLE' :
2016-09-22 06:48:28 +00:00
$cur_role [ 'acos' ] = $cur_acos ;
2016-09-15 19:40:38 +00:00
insert_role ( $cur_role );
break ;
2012-12-13 21:35:32 +00:00
case 'ATTRIBUTEDEFINITION' :
2015-07-30 09:24:56 +00:00
insert_attributedefinition ( $cur_attrdef );
2012-12-13 21:35:32 +00:00
break ;
case 'KEYWORD' :
$cur_keywordcat [ 'keywords' ][] = $cur_keyword ;
break ;
case 'KEYWORDCATEGORY' :
2015-07-30 09:24:56 +00:00
insert_keywordcategory ( $cur_keywordcat );
2012-12-13 21:35:32 +00:00
break ;
case 'DOCUMENTCATEGORY' :
2015-07-30 09:24:56 +00:00
insert_documentcategory ( $cur_documentcat );
break ;
case " FILE " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'files' ][] = $cur_file ;
}
break ;
case " LINK " :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'DOCUMENT' ) {
$cur_document [ 'links' ][] = $cur_link ;
2012-12-13 21:35:32 +00:00
}
break ;
2016-09-16 10:48:43 +00:00
case " ITEM " :
2015-08-05 20:46:30 +00:00
$cur_transmittal [ 'items' ][] = $cur_transmittalitem ;
break ;
case 'TRANSMITTAL' :
insert_transmittal ( $cur_transmittal );
break ;
2016-09-08 13:20:13 +00:00
case " TRANSITION " :
$second = $elementstack [ 2 ];
if ( $second [ 'name' ] == 'WORKFLOW' ) {
$cur_workflow [ 'transitions' ][] = $cur_transition ;
}
break ;
case 'WORKFLOW' :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'WORKFLOWS' ) {
insert_workflow ( $cur_workflow );
}
break ;
case 'WORKFLOWACTION' :
insert_workflowaction ( $cur_workflowaction );
break ;
case 'WORKFLOWSTATE' :
insert_workflowstate ( $cur_workflowstate );
break ;
case 'WORKFLOWS' :
/* Workflows has all been added . It ' s time to set the mandatory workflows
* of each user .
*/
foreach ( $users as $tuser ) {
if ( $tuser [ 'workflows' ]) {
if ( ! $user = $dms -> getUser ( $objmap [ 'users' ][ $tuser [ 'id' ]])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Cannot find user for adding mandatory workflows " );
2016-09-08 13:20:13 +00:00
exit ;
}
foreach ( $tuser [ 'workflows' ] as $tworkflowid ) {
if ( ! $wk = $dms -> getWorkflow ( $objmap [ 'workflows' ][ $tworkflowid ])) {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Cannot find workflow for adding mandatory workflows " );
2016-09-08 13:20:13 +00:00
exit ;
}
$user -> setMandatoryWorkflow ( $wk );
}
foreach ( $tuser [ 'individual' ][ 'reviewers' ] as $userid ) {
$user -> setMandatoryReviewer ( $objmap [ 'users' ][ $userid ], false );
}
foreach ( $tuser [ 'individual' ][ 'approvers' ] as $userid ) {
$user -> setMandatoryApprover ( $objmap [ 'users' ][ $userid ], false );
}
foreach ( $tuser [ 'group' ][ 'reviewers' ] as $groupid ) {
$user -> setMandatoryReviewer ( $objmap [ 'groups' ][ $groupid ], true );
}
foreach ( $tuser [ 'group' ][ 'approvers' ] as $userid ) {
$user -> setMandatoryApprover ( $objmap [ 'groups' ][ $groupid ], true );
}
}
}
break ;
2012-12-13 21:35:32 +00:00
}
} /* }}} */
function characterData ( $parser , $data ) { /* {{{ */
2017-07-27 19:17:11 +00:00
global $elementstack , $objmap , $cur_user , $cur_group , $cur_folder , $cur_document , $cur_version , $cur_statuslog , $cur_approval , $cur_approvallog , $cur_review , $cur_reviewlog , $cur_receipt , $cur_receiptlog , $cur_revision , $cur_revisionlog , $cur_attrdef , $cur_documentcat , $cur_keyword , $cur_keywordcat , $cur_file , $cur_link , $cur_workflow , $cur_workflowlog , $cur_workflowtransition , $cur_workflowaction , $cur_workflowstate , $cur_transition , $cur_transmittal , $cur_transmittalitem , $cur_role , $cur_acopath , $cur_acos ;
2012-12-13 21:35:32 +00:00
$current = end ( $elementstack );
$parent = prev ( $elementstack );
switch ( $current [ 'name' ]) {
case 'ATTR' :
switch ( $parent [ 'name' ]) {
case 'DOCUMENT' :
if ( isset ( $current [ 'attributes' ][ 'TYPE' ]) && $current [ 'attributes' ][ 'TYPE' ] == 'user' ) {
2016-09-13 15:09:19 +00:00
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 ;
2012-12-13 21:35:32 +00:00
} else {
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_document [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_document [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_document [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
}
break ;
case 'FOLDER' :
if ( isset ( $current [ 'attributes' ][ 'TYPE' ]) && $current [ 'attributes' ][ 'TYPE' ] == 'user' ) {
2016-09-13 15:09:19 +00:00
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 ;
2012-12-13 21:35:32 +00:00
} else {
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_folder [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_folder [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_folder [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
}
break ;
case 'VERSION' :
if ( isset ( $current [ 'attributes' ][ 'TYPE' ]) && $current [ 'attributes' ][ 'TYPE' ] == 'user' ) {
2016-09-13 15:09:19 +00:00
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 ;
2012-12-13 21:35:32 +00:00
} else {
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_version [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_version [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_version [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
}
break ;
2015-07-31 13:31:34 +00:00
case 'STATUSLOG' :
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_statuslog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_statuslog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_statuslog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2015-07-31 13:31:34 +00:00
break ;
2012-12-13 21:35:32 +00:00
case 'APPROVAL' :
$cur_approval [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2015-07-30 09:24:56 +00:00
case 'APPROVALLOG' :
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_approvallog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_approvallog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_approvallog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2015-07-30 09:24:56 +00:00
break ;
2012-12-13 21:35:32 +00:00
case 'REVIEW' :
$cur_review [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2015-07-30 09:24:56 +00:00
case 'REVIEWLOG' :
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_reviewlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_reviewlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_reviewlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2017-03-03 21:09:42 +00:00
case 'RECEIPT' :
$cur_receipt [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
case 'RECEIPTLOG' :
if ( isset ( $cur_receiptlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_receiptlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_receiptlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2017-07-27 19:17:11 +00:00
case 'REVISION' :
$cur_revision [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
case 'REVISIONLOG' :
if ( isset ( $cur_revisionlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_revisionlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_revisionlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2016-09-13 15:09:19 +00:00
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 ;
2015-07-30 09:24:56 +00:00
break ;
2012-12-13 21:35:32 +00:00
case 'USER' :
2015-07-30 19:05:06 +00:00
if ( isset ( $cur_user [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_user [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_user [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
break ;
case 'GROUP' :
2015-07-30 19:05:06 +00:00
if ( isset ( $cur_group [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_group [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_group [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
break ;
2016-09-15 19:40:38 +00:00
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 ;
2016-09-22 06:48:28 +00:00
case 'ACO' :
if ( isset ( $cur_acos [ implode ( '/' , $cur_acopath )][ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_acos [ implode ( '/' , $cur_acopath )][ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_acos [ implode ( '/' , $cur_acopath )][ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2012-12-13 21:35:32 +00:00
case 'ATTRIBUTEDEFINITION' :
2015-07-30 19:05:06 +00:00
if ( isset ( $cur_attrdef [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_attrdef [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_attrdef [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
break ;
case 'DOCUMENTCATEGORY' :
2015-07-30 19:05:06 +00:00
if ( isset ( $cur_documentcat [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_documentcat [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_documentcat [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
break ;
case 'KEYWORDCATEGORY' :
2015-07-30 19:05:06 +00:00
if ( isset ( $cur_keywordcat [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_keywordcat [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_keywordcat [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
break ;
case 'KEYWORD' :
2015-07-30 19:05:06 +00:00
if ( isset ( $cur_keyword [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_keyword [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_keyword [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2012-12-13 21:35:32 +00:00
break ;
case 'IMAGE' :
$cur_user [ 'image' ][ 'mimetype' ] = $data ;
break ;
2015-07-30 09:24:56 +00:00
case 'FILE' :
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_file [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_file [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_file [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2015-07-30 09:24:56 +00:00
break ;
case 'LINK' :
$cur_link [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2015-08-05 20:46:30 +00:00
case 'TRANSMITTAL' :
if ( isset ( $cur_transmittal [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_transmittal [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_transmittal [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2016-09-16 10:48:43 +00:00
case 'ITEM' :
2015-08-05 20:46:30 +00:00
if ( isset ( $cur_transmittalitem [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_transmittalitem [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_transmittalitem [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2016-09-08 13:20:13 +00:00
case 'WORKFLOW' :
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_workflow [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_workflow [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_workflow [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2016-09-08 13:20:13 +00:00
break ;
case 'WORKFLOWSTATE' :
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_workflowstate [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_workflowstate [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_workflowstate [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2016-09-08 13:20:13 +00:00
break ;
case 'WORKFLOWACTION' :
2016-09-13 15:09:19 +00:00
if ( isset ( $cur_workflowaction [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]]))
$cur_workflowaction [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] .= $data ;
else
$cur_workflowaction [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
2016-09-08 13:20:13 +00:00
break ;
case 'TRANSITION' :
$cur_transition [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
2012-12-13 21:35:32 +00:00
}
break ;
case 'DATA' :
switch ( $parent [ 'name' ]) {
case 'IMAGE' :
$cur_user [ 'image' ][ 'data' ] .= $data ;
break ;
case 'VERSION' :
$cur_version [ 'data' ] .= $data ;
break ;
2015-07-30 09:24:56 +00:00
case 'FILE' :
$cur_file [ 'data' ] .= $data ;
break ;
2016-09-15 12:01:01 +00:00
case 'REVIEWLOG' :
$cur_reviewlog [ 'data' ] .= $data ;
break ;
2012-12-13 21:35:32 +00:00
}
break ;
case 'USER' :
$first = $elementstack [ 1 ];
if ( $first [ 'name' ] == 'GROUPS' ) {
$cur_group [ 'users' ][] = $data ;
}
break ;
}
} /* }}} */
$version = " 0.0.1 " ;
$shortoptions = " hv " ;
2015-08-06 04:43:43 +00:00
$longoptions = array ( 'help' , 'version' , 'debug' , 'config:' , 'sections:' , 'folder:' , 'file:' , 'contentdir:' , 'default-user:' , 'export-mapping:' , 'no-version-check' );
2012-12-13 21:35:32 +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 );
}
2016-09-13 15:09:19 +00:00
$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 );
2015-07-30 09:24:56 +00:00
/* Check for debug mode */
$debug = false ;
if ( isset ( $options [ 'debug' ])) {
$debug = true ;
}
2012-12-13 21:35:32 +00:00
/* Set alternative config file */
if ( isset ( $options [ 'config' ])) {
$settings = new Settings ( $options [ 'config' ]);
} else {
$settings = new Settings ();
}
if ( isset ( $options [ 'folder' ])) {
$folderid = intval ( $options [ 'folder' ]);
} else {
$folderid = $settings -> _rootFolderID ;
}
2015-07-30 09:24:56 +00:00
if ( isset ( $options [ 'contentdir' ])) {
if ( file_exists ( $options [ 'contentdir' ])) {
$contentdir = $options [ 'contentdir' ];
if ( substr ( $contentdir , - 1 , 1 ) != DIRECTORY_SEPARATOR )
$contentdir .= DIRECTORY_SEPARATOR ;
} else {
2016-09-13 15:09:19 +00:00
$logger -> crit ( " Directory " . $options [ 'contentdir' ] . " does not exists " );
2015-07-30 09:24:56 +00:00
exit ( 1 );
}
} else {
$contentdir = '' ;
}
if ( isset ( $options [ 'default-user' ])) {
$defaultuserid = intval ( $options [ 'default-user' ]);
} else {
$defaultuserid = 0 ;
}
2012-12-13 21:35:32 +00:00
$filename = '' ;
if ( isset ( $options [ 'file' ])) {
$filename = $options [ 'file' ];
} else {
usage ();
exit ( 1 );
}
2015-07-30 09:24:56 +00:00
$exportmapping = '' ;
if ( isset ( $options [ 'export-mapping' ])) {
$exportmapping = $options [ 'export-mapping' ];
}
2015-08-06 04:43:43 +00:00
$noversioncheck = false ;
if ( isset ( $options [ 'no-version-check' ])) {
$noversioncheck = true ;
}
2016-09-15 19:40:38 +00:00
$sections = array ( 'documents' , 'folders' , 'groups' , 'users' , 'roles' , 'keywordcategories' , 'documentcategories' , 'attributedefinitions' , 'workflows' , 'transmittals' );
2012-12-13 21:35:32 +00:00
if ( isset ( $options [ 'sections' ])) {
$sections = explode ( ',' , $options [ 'sections' ]);
}
2013-06-06 12:42:56 +00:00
if ( isset ( $settings -> _extraPath ))
ini_set ( 'include_path' , $settings -> _extraPath . PATH_SEPARATOR . ini_get ( 'include_path' ));
require_once ( " SeedDMS/Core.php " );
2013-02-14 11:10:53 +00:00
$db = new SeedDMS_Core_DatabaseAccess ( $settings -> _dbDriver , $settings -> _dbHostname , $settings -> _dbUser , $settings -> _dbPass , $settings -> _dbDatabase );
2012-12-13 21:35:32 +00:00
$db -> connect () or die ( " Could not connect to db-server \" " . $settings -> _dbHostname . " \" " );
2017-02-14 20:05:29 +00:00
$db -> _debug = 1 ;
2012-12-13 21:35:32 +00:00
2013-02-14 11:10:53 +00:00
$dms = new SeedDMS_Core_DMS ( $db , $settings -> _contentDir . $settings -> _contentOffsetDir );
2015-07-30 09:24:56 +00:00
if ( ! $settings -> _doNotCheckDBVersion && ! $dms -> checkVersion ()) {
2016-09-13 15:09:19 +00:00
$logger -> crit ( " Database update needed. " );
2013-06-06 12:42:56 +00:00
exit ;
}
2012-12-13 21:35:32 +00:00
$dms -> setRootFolderID ( $settings -> _rootFolderID );
$rootfolder = $dms -> getFolder ( $folderid );
if ( ! $rootfolder ) {
exit ( 1 );
}
2015-07-30 09:24:56 +00:00
if ( $defaultuserid ) {
if ( ! $defaultUser = $dms -> getUser ( $defaultuserid )) {
2016-09-13 15:09:19 +00:00
$logger -> crit ( " Could not find default user with id " . $defaultuserid );
2015-07-30 09:24:56 +00:00
exit ( 1 );
}
} else {
$defaultUser = null ;
}
2016-09-22 06:48:28 +00:00
$users = array ();
2012-12-13 21:35:32 +00:00
$elementstack = array ();
2015-07-30 09:24:56 +00:00
$objmap = array (
'attributedefs' => array (),
'keywordcategories' => array (),
'documentcategories' => array (),
'users' => array (),
'groups' => array (),
'folders' => array (),
'documents' => array (),
2015-08-06 04:25:06 +00:00
'transmittals' => array (),
2016-09-08 13:20:13 +00:00
'workflows' => array (),
'workflowstates' => array (),
'workflowactions' => array (),
2015-07-30 09:24:56 +00:00
);
2012-12-13 21:35:32 +00:00
$xml_parser = xml_parser_create ( " UTF-8 " );
xml_parser_set_option ( $xml_parser , XML_OPTION_SKIP_WHITE , true );
xml_set_element_handler ( $xml_parser , " startElement " , " endElement " );
xml_set_character_data_handler ( $xml_parser , " characterData " );
if ( ! ( $fp = fopen ( $filename , " r " ))) {
die ( " could not open XML input " );
}
while ( $data = fread ( $fp , 65535 )) {
if ( ! xml_parse ( $xml_parser , $data , feof ( $fp ))) {
die ( sprintf ( " XML error: %s at line %d " ,
xml_error_string ( xml_get_error_code ( $xml_parser )),
xml_get_current_line_number ( $xml_parser )));
}
}
2015-07-30 09:24:56 +00:00
resolve_links ();
2016-09-15 12:01:01 +00:00
set_mandatory ();
2015-07-30 09:24:56 +00:00
2015-08-05 18:37:12 +00:00
set_homefolders ();
2015-07-30 09:24:56 +00:00
if ( $exportmapping ) {
if ( $fp = fopen ( $exportmapping , 'w' )) {
fputcsv ( $fp , array ( 'object type' , 'old id' , 'new id' ));
foreach ( $objmap as $section => $map ) {
foreach ( $map as $old => $new ) {
fputcsv ( $fp , array ( $section , $old , $new ));
}
}
fclose ( $fp );
} else {
2016-09-13 15:09:19 +00:00
$logger -> err ( " Could not open mapping file ' " . $exportmapping . " ' " );
2015-07-30 09:24:56 +00:00
}
}
2012-12-13 21:35:32 +00:00
?>