コード例 #1
0
 /**
  * Try to map a correspondence between the local and remote owners. Requires that a key with
  * sufficient permission to the API is given
  *
  * @param Item $item
  */
 protected function updateItemOwner($item)
 {
     $ownerId = $this->responseData['owner']['id'];
     if (!$ownerId) {
         $item->owner_id = null;
         $item->save();
         return;
     }
     $owner = $this->db->getTable('OmekaApiImportRecordIdMap')->localRecord('User', $ownerId, $this->endpointUri);
     if ($owner) {
         $item->owner_id = $owner->id;
     } else {
         $response = $this->service->users->get($ownerId);
         if ($response->getStatus() == 200) {
             $responseData = json_decode($response->getBody(), true);
             $adapter = new ApiImport_ResponseAdapter_Omeka_UserAdapter($responseData, $this->endpointUri);
             $adapter->import();
             $item->owner_id = $adapter->record->id;
         } else {
             _log(__("Attempting User import") . " " . $response->getStatus() . ": " . $response->getMessage(), Zend_Log::INFO);
         }
     }
     $item->save();
 }
コード例 #2
0
 /**
  * Try to dig up or import a local user id corresponding to remote user data
  *
  * @param array $userData
  */
 protected function getLocalUserId($userData)
 {
     $userId = $userData['id'];
     $localUser = $this->db->getTable('OmekaApiImportRecordIdMap')->localRecord('User', $userId, $this->endpointUri);
     if ($localUser) {
         return $localUser->id;
     } else {
         try {
             $response = $this->service->users->get($userId);
         } catch (Exception $e) {
             _log($e);
         }
         if ($response->getStatus() == 200) {
             $responseData = json_decode($response->getBody(), true);
             $adapter = new ApiImport_ResponseAdapter_Omeka_UserAdapter($responseData, $this->endpointUri);
             $adapter->import();
             return $adapter->record->id;
         } else {
             _log(__("Failed importing user. Falling back to current user") . " " . $response->getStatus() . " " . $response->getMessage(), Zend_Log::INFO);
             //fallback to the user doing the import owning the record
             return current_user()->id;
         }
         _log(__("Failed looking up user. Falling back to current user."));
         return current_user()->id;
     }
 }