/** * Get entities from a xmlrpc method call. * * @param string $method * Method to call. * @param .. * Params to send to server. * * @return mixed * Method result, or FALSE in case of network error. */ private function &__getEntities($method) { $ret = array(); if (!$this->_server) { throw new Yamm_EntityFetcherException("No server configured"); } $args = func_get_args(); $method = array_shift($args); array_unshift($args, $this->_transactionId); array_unshift($args, $method); array_unshift($args, $this->_server->getUrl()); $result = call_user_func_array('yamm_api_xmlrpc_call', $args); if ($result === FALSE) { throw new Yamm_EntityFetcherException("Unable to reach server"); } // Result can be empty (no dependencies) if (!empty($result['data'])) { foreach ($result['data'] as $serializedEntity) { $ret[] = Yamm_Entity::unserialize($serializedEntity); } } unset($result); return $ret; }
/** * Serialize and entity to get through XML/RPC. * * @param Yamm_Entity $entity * * @return string */ public static function serialize(Yamm_Entity $entity) { return $entity->getType() . ':' . base64_encode(serialize($entity)); }
/** * Build a full tree of dependencies. * * @param Yamm_Entity $entity * Entity for which to fetch dependencies. */ protected function _buildDependencies(Yamm_Entity $entity) { $dependencies = $entity->getDependencies(); $this->_pruneDependencies($dependencies); yamm_api_debug("Entity parser got @count dependencies", array('@count' => count($dependencies))); // Go and unpack them. foreach ($this->_fetcher->fetchDependencies($dependencies) as $depEntity) { // Check for already builded ones (circular dependencies). if (!$this->_alreadyBuilt($depEntity)) { // And build it. $this->_buildDependencies($depEntity); } } $entity->save(); }
/** * (non-PHPdoc) * @see Yamm_Sync_Backend_Interface::getEntities() */ public function getEntities($limit = YAMM_SYNC_DEFAULT_LIMIT, $offset = 0, $phase = 'default') { $ret = array(); if (!($view = self::loadView($phase))) { throw new Yamm_Sync_ProfileException("View '" . $phase . "' does not exist."); } try { // Prepare view. $view->set_display(NULL); $view->pre_execute(); // Emulate incremental behavior using page feature. $view->set_use_pager(TRUE); $view->set_items_per_page($limit); $view->set_offset($offset); // Get results. $view->execute(); $count = count($view->result); watchdog('yamm', 'View @view exports @count objects', array('@view' => $view->name, '@count' => $count), WATCHDOG_DEBUG); $entity_type = Yamm_Sync_Backend_Views::getViewEntityType($view); foreach ($view->result as $result) { // We hope our user is not stupid, and set only one field which is the // internal object id. // FIXME: We could use the base field here. $result = (array) $result; $identifier = array_shift($result); try { $uuid = Yamm_EntityFactory::getUuidForType($entity_type, $identifier, TRUE); $entity = Yamm_Entity::loadByUuid($uuid); $ret[] = $entity; } catch (Yamm_EntityException $e) { // Just alert the site admin this entity build failed, but continue // with others. watchdog('yamm', '@e', array('@e' => $e->getMessage()), WATCHDOG_ERROR); } } } catch (Yamm_Sync_ProfileException $e) { watchdog('yamm_pull', '@e', array('@e' => $e->getMessage()), WATCHDOG_ERROR); } // Keep some memory to survive. $view->destroy(); unset($view); return $ret; }