Skip to content

Commit

Permalink
User import handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SerheyDolgushev committed Mar 18, 2015
1 parent 328df9a commit efa5ced
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions classes/import_handler/rp/user.php
@@ -0,0 +1,50 @@
<?php

/**
* @package ContentSync
* @class ContentSyncImportHandlerUser
* @author Serhey Dolgushev <dolgushev.serhey@gmail.com>
* @date 18 Mar 2015
* */
class ContentSyncImportHandlerUser extends ContentSyncImportHandlereRPBase {

protected static $rootNodeURLPath = 'users/members';
protected static $simpleAttributes = array(
'first_name',
'last_name',
'user_account'
);

public static function fetchNode( $uniqueID ) {
$user = eZUser::fetchByName( $uniqueID );
return $user instanceof eZUser ? $user->attribute( 'contentobject' )->attribute( 'main_node' ) : null;
}

public function processAttributes( array $attributes, $uniqueID, eZContentObjectVersion $existingVerion = null ) {
$return = $this->processSimpleAttributes( $attributes );

return $return;
}

public function processLocations( array $locations, array $objectData ) {
$root = eZContentObjectTreeNode::fetchByURLPath( static::$rootNodeURLPath );
if( $root instanceof eZContentObjectTreeNode === false ) {
$message = 'Root node with URL path "' . static::$rootNodeURLPath . '" is missing';
ContentSyncImport::addLogtMessage( $message );
}

return array( $root );
}

public function import( array $objectData, eZContentObjectVersion $existingVersion = null ) {
$object = $this->fetchObject( $objectData['unique_id'] );

if( $object instanceof eZContentObject === false ) {
return $this->createObject( $objectData );
} else {
$objectData['locations'] = array( $object->attribute( 'main_node' )->attribute( 'parent' ) );
return $this->updateObject( $objectData, $object, $existingVersion );
}
}

}

0 comments on commit efa5ced

Please sign in to comment.