2012-12-13 21:35:32 +00:00
< ? php
2015-07-30 09:24:56 +00:00
require_once ( " ../inc/inc.ClassSettings.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 " ;
echo " documentcategories \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 ) { /* {{{ */
global $dms , $objmap ;
$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' ]]);
} else {
if ( isset ( $objmap [ 'users' ][( int ) $review [ 'attributes' ][ 'required' ]]))
$newreview [ 'required' ] = $dms -> getUser ( $objmap [ 'users' ][( int ) $review [ 'attributes' ][ 'required' ]]);
}
$newreview [ 'logs' ] = array ();
foreach ( $review [ 'logs' ] as $j => $log ) {
if ( ! array_key_exists ( $log [ 'attributes' ][ 'user' ], $objmap [ 'users' ])) {
echo " Warning: user for review log cannot be mapped \n " ;
} 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' ];
$newreview [ 'logs' ][] = $newlog ;
}
}
$newreviews [] = $newreview ;
}
return $newreviews ;
2012-12-13 21:35:32 +00:00
} /* }}} */
function insert_user ( $user ) { /* {{{ */
2015-07-30 09:24:56 +00:00
global $dms , $debug , $sections , $defaultUser , $objmap ;
if ( $debug ) print_r ( $user );
2012-12-13 21:35:32 +00:00
2015-07-30 09:24:56 +00:00
if ( $newUser = $dms -> getUserByLogin ( $user [ 'attributes' ][ 'login' ])) {
echo " User ' " . $user [ 'attributes' ][ 'login' ] . " ' already exists \n " ;
2012-12-13 21:35:32 +00:00
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'users' , $sections )) {
$newUser = $dms -> addUser (
$user [ 'attributes' ][ 'login' ],
$user [ 'attributes' ][ 'pwd' ],
$user [ 'attributes' ][ 'fullname' ],
$user [ 'attributes' ][ 'email' ],
$user [ 'attributes' ][ 'language' ],
$user [ 'attributes' ][ 'theme' ],
$user [ 'attributes' ][ 'comment' ],
$user [ 'attributes' ][ 'role' ],
$user [ 'attributes' ][ 'hidden' ],
$user [ 'attributes' ][ 'disabled' ],
$user [ 'attributes' ][ 'pwdexpiration' ]);
if ( ! $newUser ) {
echo " Error: could not add user \n " ;
return false ;
}
} 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 () { /* {{{ */
global $dms , $debug , $defaultUser , $users , $objmap ;
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' ])) {
2015-08-05 20:47:39 +00:00
echo " Warning: homefolder " . $user [ 'attributes' ][ 'homefolder' ] . " cannot be found \n " ;
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 ) { /* {{{ */
2015-07-30 09:24:56 +00:00
global $dms , $debug , $objmap , $sections , $users ;
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' ])) {
2012-12-13 21:35:32 +00:00
echo " Group already exists \n " ;
} 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 ) {
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' ])) {
$newGroup -> addUser ( $newMember );
} else {
echo " Error: could not find member of group \n " ;
return false ;
}
2012-12-13 21:35:32 +00:00
} else {
2015-07-30 09:24:56 +00:00
echo " Error: group member is not contained in xml file \n " ;
return false ;
2012-12-13 21:35:32 +00:00
}
}
2015-07-30 09:24:56 +00:00
} else {
echo " Error: could not add group \n " ;
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
} /* }}} */
function insert_attributedefinition ( $attrdef ) { /* {{{ */
2015-07-30 09:24:56 +00:00
global $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' ])) {
2012-12-13 21:35:32 +00:00
echo " Attribute definition already exists \n " ;
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'attributedefinitions' , $sections )) {
if ( ! $newAttrdef = $dms -> addAttributeDefinition ( $attrdef [ 'attributes' ][ 'name' ], $attrdef [ 'objecttype' ], $attrdef [ 'attributes' ][ 'type' ], $attrdef [ 'attributes' ][ 'multiple' ], $attrdef [ 'attributes' ][ 'minvalues' ], $attrdef [ 'attributes' ][ 'maxvalues' ], $attrdef [ 'attributes' ][ 'valueset' ], $attrdef [ 'attributes' ][ 'regex' ])) {
echo " Error: could not add attribute definition \n " ;
return false ;
}
} 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 ) { /* {{{ */
2015-07-30 09:24:56 +00:00
global $dms , $debug , $objmap , $sections ;
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' ])) {
2012-12-13 21:35:32 +00:00
echo " Document category already exists \n " ;
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'documentcategories' , $sections )) {
if ( ! $newCategory = $dms -> addDocumentCategory ( $documentcat [ 'attributes' ][ 'name' ])) {
echo " Error: could not add document category \n " ;
return false ;
}
} 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 ) { /* {{{ */
2015-07-30 09:24:56 +00:00
global $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' ])) {
echo " Error: owner of keyword category cannot be found \n " ;
return false ;
}
$owner = $objmap [ 'users' ][( int ) $keywordcat [ 'attributes' ][ 'owner' ]];
if ( $newCategory = $dms -> getKeywordCategoryByName ( $keywordcat [ 'attributes' ][ 'name' ], $owner )) {
2012-12-13 21:35:32 +00:00
echo " Document category already exists \n " ;
} else {
2015-07-30 09:24:56 +00:00
if ( in_array ( 'keywordcategories' , $sections )) {
if ( ! $newCategory = $dms -> addKeywordCategory ( $owner , $keywordcat [ 'attributes' ][ 'name' ])) {
echo " Error: could not add keyword category \n " ;
return false ;
}
foreach ( $keywordcat [ 'keywords' ] as $keyword ) {
if ( ! $newCategory -> addKeywordList ( $keyword [ 'attributes' ][ 'name' ])) {
echo " Error: could not add keyword to keyword category \n " ;
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
} /* }}} */
function insert_document ( $document ) { /* {{{ */
2015-07-30 09:24:56 +00:00
global $dms , $debug , $defaultUser , $objmap , $sections , $rootfolder ;
2015-07-31 13:31:34 +00:00
if ( $debug ) print_r ( $document );
2015-07-30 09:24:56 +00:00
if ( ! array_key_exists (( int ) $document [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
echo " Warning: owner of document cannot be mapped using default user \n " ;
$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 {
echo " Warning: User attribute " . $orgid . " cannot be mapped \n " ;
}
}
}
$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 {
echo " Warning: Category " . $catid . " cannot be mapped \n " ;
}
}
}
if ( isset ( $document [ 'folder' ]) && $document [ 'folder' ]) {
if ( array_key_exists ( $document [ 'folder' ], $objmap [ 'folders' ])) {
$folder = $dms -> getFolder ( $objmap [ 'folders' ][ $document [ 'folder' ]]);
} else {
echo " Error: folder " . $document [ 'folder' ] . " cannot be mapped \n " ;
return false ;
}
} else
$folder = $rootfolder ;
if ( in_array ( 'documents' , $sections )) {
$error = false ;
$initversion = array_shift ( $document [ 'versions' ]);
if ( ! empty ( $initversion [ 'fileref' ])) {
$filename = tempnam ( '/tmp' , 'FOO' );
copy ( $initversion [ 'fileref' ], $filename );
} else {
$filecontents = base64_decode ( $initversion [ 'data' ]);
if ( strlen ( $filecontents ) != $initversion [ 'data_length' ]) {
echo " Warning: file length ( " . strlen ( $filecontents ) . " ) doesn't match expected length ( " . $initversion [ 'data_length' ] . " ). \n " ;
$newDocument = null ;
$error = true ;
}
$filename = tempnam ( '/tmp' , 'FOO' );
file_put_contents ( $filename , $filecontents );
}
if ( ! $error ) {
$reviews = array ( 'i' => array (), 'g' => array ());
2015-08-04 05:41:53 +00:00
/*
2015-07-30 09:24:56 +00:00
if ( $initversion [ 'reviews' ]) {
foreach ( $initversion [ 'reviews' ] as $review ) {
if ( $review [ 'attributes' ][ 'type' ] == 1 ) {
if ( isset ( $objmap [ 'groups' ][( int ) $review [ 'attributes' ][ 'required' ]]))
$reviews [ 'g' ][] = $objmap [ 'groups' ][( int ) $review [ 'attributes' ][ 'required' ]];
} else {
if ( isset ( $objmap [ 'users' ][( int ) $review [ 'attributes' ][ 'required' ]]))
$reviews [ 'i' ][] = $objmap [ 'users' ][( int ) $review [ 'attributes' ][ 'required' ]];
}
}
}
2015-08-04 05:41:53 +00:00
*/
2015-07-30 09:24:56 +00:00
$approvals = array ( 'i' => array (), 'g' => array ());
2015-08-04 05:41:53 +00:00
/*
2015-07-30 09:24:56 +00:00
if ( $initversion [ 'approvals' ]) {
foreach ( $initversion [ 'approvals' ] as $approval ) {
if ( $approval [ 'attributes' ][ 'type' ] == 1 ) {
if ( isset ( $objmap [ 'groups' ][( int ) $approval [ 'attributes' ][ 'required' ]]))
$approvals [ 'g' ][] = $objmap [ 'groups' ][( int ) $approval [ 'attributes' ][ 'required' ]];
} else {
if ( isset ( $objmap [ 'users' ][( int ) $approval [ 'attributes' ][ 'required' ]]))
$approvals [ 'i' ][] = $objmap [ 'users' ][( int ) $approval [ 'attributes' ][ 'required' ]];
}
}
}
2015-08-04 05:41:53 +00:00
*/
2015-07-30 19:05:06 +00:00
$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 {
echo " Warning: User attribute " . $orgid . " cannot be mapped \n " ;
}
}
}
2015-07-30 09:24:56 +00:00
if ( ! $result = $folder -> addDocument (
$document [ 'attributes' ][ 'name' ],
$document [ 'attributes' ][ 'comment' ],
isset ( $document [ 'attributes' ][ 'expires' ]) ? dateToTimestamp ( $document [ 'attributes' ][ 'expires' ]) : 0 ,
$owner ,
isset ( $document [ 'attributes' ][ 'keywords' ]) ? $document [ 'attributes' ][ 'keywords' ] : 0 ,
$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 ,
2015-07-30 19:05:06 +00:00
$version_attributes ,
2015-07-30 09:24:56 +00:00
null //workflow
)
) {
unlink ( $filename );
echo " Error: could not add document \n " ;
return false ;
} else {
$newDocument = $result [ 0 ];
unlink ( $filename );
2015-08-04 05:41:53 +00:00
$newVersion = $result [ 1 ] -> getContent ();
$newVersion -> setDate ( dateToTimestamp ( $initversion [ 'attributes' ][ 'date' ]));
$newlogs = array ();
foreach ( $initversion [ 'statuslogs' ] as $i => $log ) {
if ( ! array_key_exists ( $log [ 'attributes' ][ 'user' ], $objmap [ 'users' ])) {
unset ( $initversion [ 'statuslogs' ][ $i ]);
echo " Warning: user for status log cannot be mapped \n " ;
} 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' ]) {
$newreviews = getRevAppLog ( $initversion [ 'reviews' ]);
$newVersion -> rewriteReviewLog ( $newreviews );
}
if ( $initversion [ 'approvals' ]) {
$newapprovals = getRevAppLog ( $initversion [ 'approvals' ]);
$newVersion -> rewriteApprovalLog ( $newapprovals );
}
$newDocument -> setDate ( dateToTimestamp ( $document [ 'attributes' ][ 'date' ]));
2015-07-30 09:24:56 +00:00
$newDocument -> setDefaultAccess ( $document [ 'attributes' ][ 'defaultaccess' ]);
foreach ( $document [ 'versions' ] as $version ) {
if ( ! array_key_exists (( int ) $version [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
echo " Error: owner of document cannot be mapped \n " ;
return false ;
}
$owner = $dms -> getUser ( $objmap [ 'users' ][( int ) $version [ 'attributes' ][ 'owner' ]]);
2012-12-13 21:35:32 +00:00
2015-07-30 09:24:56 +00:00
$reviews = array ( 'i' => array (), 'g' => array ());
2015-08-04 05:41:53 +00:00
/*
2015-07-30 09:24:56 +00:00
if ( $version [ 'reviews' ]) {
foreach ( $version [ 'reviews' ] as $review ) {
if ( $review [ 'attributes' ][ 'type' ] == 1 ) {
if ( isset ( $objmap [ 'groups' ][( int ) $review [ 'attributes' ][ 'required' ]]))
$reviews [ 'g' ][] = $objmap [ 'groups' ][( int ) $review [ 'attributes' ][ 'required' ]];
} else {
if ( isset ( $objmap [ 'users' ][( int ) $review [ 'attributes' ][ 'required' ]]))
$reviews [ 'i' ][] = $objmap [ 'users' ][( int ) $review [ 'attributes' ][ 'required' ]];
}
}
}
2015-08-04 05:41:53 +00:00
*/
2015-07-30 09:24:56 +00:00
$approvals = array ( 'i' => array (), 'g' => array ());
2015-08-04 05:41:53 +00:00
/*
2015-07-30 09:24:56 +00:00
if ( $version [ 'approvals' ]) {
foreach ( $version [ 'approvals' ] as $approval ) {
if ( $approval [ 'attributes' ][ 'type' ] == 1 ) {
if ( isset ( $objmap [ 'groups' ][( int ) $approval [ 'attributes' ][ 'required' ]]))
$approvals [ 'g' ][] = $objmap [ 'groups' ][( int ) $approval [ 'attributes' ][ 'required' ]];
} else {
if ( isset ( $objmap [ 'users' ][( int ) $approval [ 'attributes' ][ 'required' ]]))
$approvals [ 'i' ][] = $objmap [ 'users' ][( int ) $approval [ 'attributes' ][ 'required' ]];
}
}
}
2015-08-04 05:41:53 +00:00
*/
2015-07-30 19:05:06 +00:00
$version_attributes = array ();
if ( isset ( $version [ 'user_attributes' ])) {
foreach ( $version [ 'user_attributes' ] as $orgid => $value ) {
if ( array_key_exists (( int ) $orgid , $objmap [ 'attributedefs' ])) {
$version_attributes [ $objmap [ 'attributedefs' ][ $orgid ]] = $value ;
} else {
echo " Warning: User attribute " . $orgid . " cannot be mapped \n " ;
}
}
}
2015-07-30 09:24:56 +00:00
if ( ! empty ( $version [ 'fileref' ])) {
$filename = tempnam ( '/tmp' , 'FOO' );
copy ( $version [ 'fileref' ], $filename );
} else {
$filecontents = base64_decode ( $version [ 'data' ]);
if ( strlen ( $filecontents ) != $version [ 'data_length' ]) {
echo " Warning: file length ( " . strlen ( $filecontents ) . " ) doesn't match expected length ( " . $version [ 'data_length' ] . " ). \n " ;
}
$filename = tempnam ( '/tmp' , 'FOO' );
file_put_contents ( $filename , $filecontents );
}
2015-08-04 05:41:53 +00:00
if ( ! ( $result = $newDocument -> addContent (
2015-07-30 09:24:56 +00:00
$version [ 'attributes' ][ 'comment' ],
$owner ,
$filename ,
$version [ 'attributes' ][ 'orgfilename' ],
$version [ 'attributes' ][ 'filetype' ],
$version [ 'attributes' ][ 'mimetype' ],
$reviews , //reviewers
$approvals , //approvers
$version [ 'version' ],
2015-07-30 19:05:06 +00:00
$version_attributes ,
2015-07-30 09:24:56 +00:00
null //workflow
2015-08-04 05:41:53 +00:00
))) {
}
$newVersion = $result -> getContent ();
$newVersion -> setDate ( dateToTimestamp ( $version [ 'attributes' ][ 'date' ]));
$newlogs = array ();
foreach ( $version [ 'statuslogs' ] as $i => $log ) {
if ( ! array_key_exists ( $log [ 'attributes' ][ 'user' ], $objmap [ 'users' ])) {
unset ( $version [ 'statuslogs' ][ $i ]);
echo " Warning: user for status log cannot be mapped \n " ;
} else {
$log [ 'attributes' ][ 'user' ] = $dms -> getUser ( $objmap [ 'users' ][ $log [ 'attributes' ][ 'user' ]]);
$newlogs [] = $log [ 'attributes' ];
}
}
$newVersion -> rewriteStatusLog ( $newlogs );
if ( $version [ 'reviews' ]) {
$newreviews = getRevAppLog ( $version [ 'reviews' ]);
$newVersion -> rewriteReviewLog ( $newreviews );
2015-07-30 09:24:56 +00:00
}
2015-08-04 05:41:53 +00:00
if ( $version [ 'approvals' ]) {
$newapprovals = getRevAppLog ( $version [ 'approvals' ]);
$newVersion -> rewriteApprovalLog ( $newapprovals );
}
2015-07-30 09:24:56 +00:00
unlink ( $filename );
}
}
if ( isset ( $document [ 'notifications' ][ 'users' ]) && $document [ 'notifications' ][ 'users' ]) {
foreach ( $document [ 'notifications' ][ 'users' ] as $userid ) {
if ( ! array_key_exists ( $userid , $objmap [ 'users' ])) {
echo " Warning: user for notification cannot be mapped \n " ;
} else {
$newDocument -> addNotify ( $objmap [ 'users' ][ $userid ], 1 );
}
}
}
if ( isset ( $document [ 'notifications' ][ 'groups' ]) && $document [ 'notifications' ][ 'groups' ]) {
foreach ( $document [ 'notifications' ][ 'groups' ] as $groupid ) {
if ( ! array_key_exists ( $groupid , $objmap [ 'groups' ])) {
echo " Warning: user for notification cannot be mapped \n " ;
} else {
$newDocument -> addNotify ( $objmap [ 'groups' ][ $groupid ], 0 );
}
}
}
if ( isset ( $document [ 'acls' ]) && $document [ 'acls' ]) {
$newDocument -> setInheritAccess ( false );
foreach ( $document [ 'acls' ] as $acl ) {
if ( $acl [ 'type' ] == 'user' ) {
if ( ! array_key_exists ( $acl [ 'user' ], $objmap [ 'users' ])) {
echo " Warning: user for notification cannot be mapped \n " ;
} else {
$newDocument -> addAccess ( $acl [ 'mode' ], $objmap [ 'users' ][ $acl [ 'user' ]], 1 );
}
} elseif ( $acl [ 'type' ] == 'group' ) {
if ( ! array_key_exists ( $acl [ 'group' ], $objmap [ 'groups' ])) {
echo " Warning: group for notification cannot be mapped \n " ;
} else {
$newDocument -> addAccess ( $acl [ 'mode' ], $objmap [ 'groups' ][ $acl [ 'group' ]], 0 );
}
}
}
}
if ( isset ( $document [ 'files' ]) && $document [ 'files' ]) {
foreach ( $document [ 'files' ] as $file ) {
if ( ! array_key_exists ( $file [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
echo " Warning: user for file cannot be mapped \n " ;
$owner = $defaultUser ;
} else {
$owner = $dms -> getUser ( $objmap [ 'users' ][ $file [ 'attributes' ][ 'owner' ]]);
}
if ( ! empty ( $file [ 'fileref' ])) {
$filename = tempnam ( '/tmp' , 'FOO' );
copy ( $file [ 'fileref' ], $filename );
} else {
$filecontents = base64_decode ( $file [ 'data' ]);
if ( strlen ( $filecontents ) != $file [ 'data_length' ]) {
echo " Warning: file length ( " . strlen ( $filecontents ) . " ) doesn't match expected length ( " . $file [ 'data_length' ] . " ). \n " ;
}
$filename = tempnam ( '/tmp' , 'FOO' );
file_put_contents ( $filename , $filecontents );
}
$newDocument -> addDocumentFile (
$file [ 'attributes' ][ 'name' ],
$file [ 'attributes' ][ 'comment' ],
$owner ,
$filename ,
$file [ 'attributes' ][ 'orgfilename' ],
$file [ 'attributes' ][ 'filetype' ],
$file [ 'attributes' ][ 'mimetype' ]
);
unlink ( $filename );
}
}
}
} 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 ) { /* {{{ */
2015-07-30 09:24:56 +00:00
global $dms , $debug , $objmap , $defaultUser , $sections , $rootfolder ;
if ( $debug ) print_r ( $folder );
if ( in_array ( 'folders' , $sections )) {
if ( ! array_key_exists ( $folder [ 'attributes' ][ 'owner' ], $objmap [ 'users' ])) {
echo " Warning: owner of folder cannot be mapped using default user \n " ;
$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 {
echo " Warning: User attribute " . $orgid . " cannot be mapped \n " ;
}
}
}
if ( isset ( $folder [ 'folder' ]) && $folder [ 'folder' ]) {
if ( array_key_exists ( $folder [ 'folder' ], $objmap [ 'folders' ])) {
$parent = $dms -> getFolder ( $objmap [ 'folders' ][ $folder [ 'folder' ]]);
} else {
echo " Error: Folder " . $folder [ 'folder' ] . " cannot be mapped \n " ;
exit ;
}
} else
$parent = $rootfolder ;
if ( ! $newFolder = $parent -> addSubFolder ( $folder [ 'attributes' ][ 'name' ], $folder [ 'attributes' ][ 'comment' ], $owner , $folder [ 'attributes' ][ 'sequence' ], $attributes )) {
echo " Error: could not add folder \n " ;
return false ;
}
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' ]);
if ( isset ( $folder [ 'notifications' ][ 'users' ]) && $folder [ 'notifications' ][ 'users' ]) {
foreach ( $folder [ 'notifications' ][ 'users' ] as $userid ) {
if ( ! array_key_exists ( $userid , $objmap [ 'users' ])) {
echo " Warning: user for notification cannot be mapped \n " ;
} 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' ])) {
echo " Warning: user for notification cannot be mapped \n " ;
} else {
$newFolder -> addNotify ( $objmap [ 'groups' ][ $groupid ], 0 );
}
}
}
if ( isset ( $folder [ 'acls' ]) && $folder [ 'acls' ]) {
$newFolder -> setInheritAccess ( false );
foreach ( $folder [ 'acls' ] as $acl ) {
if ( $acl [ 'type' ] == 'user' ) {
if ( ! array_key_exists ( $acl [ 'user' ], $objmap [ 'users' ])) {
echo " Warning: user for notification cannot be mapped \n " ;
} else {
$newFolder -> addAccess ( $acl [ 'mode' ], $objmap [ 'users' ][ $acl [ 'user' ]], 1 );
}
} elseif ( $acl [ 'type' ] == 'group' ) {
if ( ! array_key_exists ( $acl [ 'group' ], $objmap [ 'groups' ])) {
echo " Warning: group for notification cannot be mapped \n " ;
} else {
$newFolder -> addAccess ( $acl [ 'mode' ], $objmap [ 'groups' ][ $acl [ 'group' ]], 0 );
}
}
}
}
} else {
$newFolder = null ;
}
if ( $newFolder )
$objmap [ 'folders' ][ $folder [ 'id' ]] = $newFolder -> getID ();
return $newFolder ;
} /* }}} */
function resolve_links () { /* {{{ */
global $dms , $debug , $defaultUser , $links , $objmap ;
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' ])) {
echo " Warning: user for link cannot be mapped using default user \n " ;
$owner = $defaultUser ;
} else {
$owner = $dms -> getUser ( $objmap [ 'users' ][ $doclink [ 'attributes' ][ 'owner' ]]);
}
if ( ! $doc -> addDocumentLink ( $target -> getID (), $owner -> getID (), $doclink [ 'attributes' ][ 'public' ])) {
echo " Error: could not add document link from " . $doc -> getID () . " to " . $target -> getID () . " \n " ;
}
} else {
echo " Warning: target document not found in database \n " ;
}
} else {
echo " Warning: target document not found in object mapping \n " ;
}
}
} else {
echo " Warning: document not found in database \n " ;
}
} else {
echo " Warning: document not found in object mapping \n " ;
}
}
2012-12-13 21:35:32 +00:00
} /* }}} */
function startElement ( $parser , $name , $attrs ) { /* {{{ */
2015-08-06 04:43:43 +00:00
global $dms , $noversioncheck , $elementstack , $objmap , $cur_user , $cur_group , $cur_folder , $cur_document , $cur_version , $cur_statuslog , $cur_approval , $cur_approvallog , $cur_review , $cur_reviewlog , $cur_attrdef , $cur_documentcat , $cur_keyword , $cur_keywordcat , $cur_file , $cur_link ;
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' ])) {
echo " Error: Database version ( " . implode ( '.' , array ( $dbversion [ 'major' ], $dbversion [ 'minor' ], $dbversion [ 'subminor' ])) . " ) doesn't match version in input file ( " . implode ( '.' , $xdbversion ) . " ). \n " ;
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
* reviewer or approver
*/
2012-12-13 21:35:32 +00:00
$first = $elementstack [ 1 ];
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 ();
}
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' ];
}
2012-12-13 21:35:32 +00:00
}
break ;
case " GROUP " :
$first = $elementstack [ 1 ];
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' ];
}
2012-12-13 21:35:32 +00:00
}
break ;
case " DOCUMENT " :
$cur_document = array ();
2015-07-30 09:24:56 +00:00
$cur_document [ 'id' ] = ( int ) $attrs [ 'ID' ];
$cur_document [ 'folder' ] = ( int ) $attrs [ 'FOLDER' ];
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 ();
break ;
2015-07-31 13:31:34 +00:00
case " STATUSLOG " :
$cur_statuslog = array ();
$cur_statuslog [ '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 ;
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' ]] = '' ;
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' ]] = '' ;
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' ]] = '' ;
} 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' ]] = '' ;
}
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' ] = " " ;
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 ;
2012-12-13 21:35:32 +00:00
}
} /* }}} */
function endElement ( $parser , $name ) { /* {{{ */
2015-07-31 13:31:34 +00:00
global $dms , $sections , $rootfolder , $objmap , $elementstack , $users , $groups , $links , $cur_user , $cur_group , $cur_folder , $cur_document , $cur_version , $cur_statuslog , $cur_approval , $cur_approvallog , $cur_review , $cur_reviewlog , $cur_attrdef , $cur_documentcat , $cur_keyword , $cur_keywordcat , $cur_file , $cur_link ;
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 ;
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 ;
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 ;
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 ;
}
} /* }}} */
function characterData ( $parser , $data ) { /* {{{ */
2015-07-31 13:31:34 +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_attrdef , $cur_documentcat , $cur_keyword , $cur_keywordcat , $cur_file , $cur_link ;
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' ) {
$cur_document [ 'user_attributes' ][ $current [ 'attributes' ][ 'ATTRDEF' ]] = $data ;
} else {
$cur_document [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
}
break ;
case 'FOLDER' :
if ( isset ( $current [ 'attributes' ][ 'TYPE' ]) && $current [ 'attributes' ][ 'TYPE' ] == 'user' ) {
$cur_folder [ 'user_attributes' ][ $current [ 'attributes' ][ 'ATTRDEF' ]] = $data ;
} else {
$cur_folder [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
}
break ;
case 'VERSION' :
if ( isset ( $current [ 'attributes' ][ 'TYPE' ]) && $current [ 'attributes' ][ 'TYPE' ] == 'user' ) {
$cur_version [ 'user_attributes' ][ $current [ 'attributes' ][ 'ATTRDEF' ]] = $data ;
} else {
$cur_version [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
}
break ;
2015-07-31 13:31:34 +00:00
case 'STATUSLOG' :
$cur_statuslog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
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' :
$cur_approvallog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
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' :
$cur_reviewlog [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
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 ;
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' :
$cur_file [ 'attributes' ][ $current [ 'attributes' ][ 'NAME' ]] = $data ;
break ;
case 'LINK' :
$cur_link [ '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 ;
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 );
}
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 {
echo " Directory " . $options [ 'contentdir' ] . " does not exists \n " ;
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 ;
}
2012-12-13 21:35:32 +00:00
$sections = array ( 'documents' , 'folders' , 'groups' , 'users' , 'keywordcategories' , 'documentcategories' , 'attributedefinitions' );
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 . " \" " );
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 ()) {
2013-06-06 12:42:56 +00:00
echo " Database update needed. " ;
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 )) {
echo " Error: Could not find default user with id " . $defaultuserid . " \n " ;
exit ( 1 );
}
} else {
$defaultUser = null ;
}
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 (),
);
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 ();
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 {
echo " Error: could not open mapping file ' " . $exportmapping . " ' \n " ;
}
}
2012-12-13 21:35:32 +00:00
?>