forked from philandteds/content_sync
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
328df9a
commit efa5ced
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
} | ||
|
||
} |