public function loadObjectbyRemoteID($eZContentObject) { $urlIniArray = $this->itFiltersUtil->getSyncUrl(); # parte fissa link recupero oggetto da server $objectRetrieveUrl = 'api/opendata/v1/content/node/0/remoteid/'; # recupero url dal file ini per la classe interessata $classUrl = $urlIniArray[$eZContentObject->ClassIdentifier]; # recupero remoteID per costruzione link recupero oggetto da server $elementRemoteID = $eZContentObject->RemoteID; $apiNodeUrl = $classUrl[0] . $objectRetrieveUrl . $elementRemoteID; $this->remoteApiNode = OCOpenDataApiNode::fromLink($apiNodeUrl); if (!$this->remoteApiNode instanceof OCOpenDataApiNode) { throw new Exception("Fallita la creazione di OCOpenDataApiNode "); } $result_value = $this->updateContentObject($eZContentObject); if (!$result_value) { throw new Exception("Aggiornamento dell'oggetto fallito"); } return true; }
/** * Processa l'importazione di un oggetto * @param object $row */ public function process($row) { try { $apiNodeUrl = rtrim($row['base_url'], '/'); $apiNodeUrl .= '/api/opendata/v1/content/node/' . $row['remote_node_id']; $remoteApiNode = OCOpenDataApiNode::fromLink($apiNodeUrl); if (!$remoteApiNode instanceof OCOpenDataApiNode) { throw new Exception("Url remoto \"{$apiNodeUrl}\" non raggiungibile"); } $newObject = $remoteApiNode->createContentObject($row['parent_node_id']); if (!$newObject instanceof eZContentObject) { throw new Exception("Fallita la creazione dell'oggetto da nodo remoto"); } } catch (Exception $e) { $this->curLog->ocLoggerUtil->addErrorMessage('Error in ITTematicaSyncHandler - process: ' . $e->getMessage()); $this->curLog->ocLoggerUtil->writeLogs(); echo 'Got Exception on ITTematicaSyncHandler - process: ' . $e->getMessage() . "\n"; } }
/** * @param int $remoteNodeID * @param int $localParentNodeID * * @return eZContentObject * @throws Exception */ public function import($remoteNodeID, $localParentNodeID) { if (!class_exists('OCOpenDataApiNode')) { throw new Exception("Libreria OCOpenDataApiNode non trovata"); } $apiNodeUrl = rtrim($this->attributes['definition']['Url'], '/') . '/api/opendata/v1/content/node/' . $remoteNodeID; $remoteApiNode = OCOpenDataApiNode::fromLink($apiNodeUrl); if (!$remoteApiNode instanceof OCOpenDataApiNode) { throw new Exception("Url remoto \"{$apiNodeUrl}\" non raggiungibile"); } $newObject = $remoteApiNode->createContentObject($localParentNodeID); if (!$newObject instanceof eZContentObject) { throw new Exception("Fallita la creazione dell'oggetto da nodo remoto"); } $rowPending = array('action' => self::ACTION_SYNC_OBJECT, 'param' => $newObject->attribute('id')); $pendingItem = new eZPendingActions($rowPending); $pendingItem->store(); return $newObject; }
/** * @param int $remoteNodeID * @param int $localParentNodeID * * @return eZContentObject * @throws Exception */ public function import($remoteNodeID, $localParentNodeID) { if (!class_exists('OCOpenDataApiNode')) { throw new Exception("Libreria OCOpenDataApiNode non trovata"); } $apiNodeUrl = rtrim($this->attributes['definition']['Url'], '/') . '/api/opendata/v1/content/node/' . $remoteNodeID; $remoteApiNode = OCOpenDataApiNode::fromLink($apiNodeUrl); if (!$remoteApiNode instanceof OCOpenDataApiNode) { throw new Exception("Url remoto \"{$apiNodeUrl}\" non raggiungibile"); } $attributeList = array(); foreach ($this->remoteClassAttributes as $identifier) { if (isset($remoteApiNode->fields[$identifier])) { $fieldArray = $remoteApiNode->fields[$identifier]; $localeIdentifier = isset($this->mapAttributes[$identifier]) ? $this->mapAttributes[$identifier] : false; if ($localeIdentifier) { if (strpos($localeIdentifier, '::') === 0) { $localeIdentifier = str_replace('::', '', $localeIdentifier); $attributeList[$localeIdentifier] = $this->importAttribute($identifier, $localeIdentifier, $fieldArray); } else { switch ($fieldArray['type']) { case 'ezxmltext': $attributeList[$localeIdentifier] = SQLIContentUtils::getRichContent($fieldArray['value']); break; case 'ezbinaryfile': case 'ezimage': $attributeList[$localeIdentifier] = !empty($fieldArray['value']) ? SQLIContentUtils::getRemoteFile($fieldArray['value']) : ''; break; default: $attributeList[$localeIdentifier] = $fieldArray['string_value']; break; } } } } } $params = array(); $params['class_identifier'] = $this->mapClassIdentifier; $params['remote_id'] = static::REMOTE_PREFIX . $remoteApiNode->metadata['objectRemoteId']; $params['parent_node_id'] = $localParentNodeID; $params['attributes'] = $attributeList; $newObject = eZContentFunctions::createAndPublishObject($params); if (!$newObject instanceof eZContentObject) { throw new Exception("Fallita la creazione dell'oggetto da nodo remoto"); } return $newObject; }