/** * Implementation for execute() * * @param Node $node * @param Context $context * @param \USync\Loading\LoaderInterface $loader */ protected function load(NodeInterface $node, Context $context, LoaderInterface $loader) { $dirtyAllowed = $node->hasAttribute('dirty') && $node->getAttribute('dirty'); $dirtyPrefix = $dirtyAllowed ? '! ' : ''; switch ($this->getLoadMode($node, $context, $loader)) { case self::LOAD_IGNORE: $context->getLogger()->log(sprintf(" ? %s%s", $dirtyPrefix, $node->getPath())); return; case self::LOAD_DELETE: $context->getLogger()->log(sprintf(" - %s%s", $dirtyPrefix, $node->getPath())); if ($loader->exists($node, $context)) { $context->notify('load:delete:pre', $node); $loader->deleteExistingObject($node, $context, $dirtyAllowed); $context->notify('load:delete:post', $node); } return; case self::LOAD_SYNC: /* $object = $node->getValue(); if (!is_array($object)) { $object = array(); } */ if ($loader->exists($node, $context)) { $context->getLogger()->log(sprintf(" ~ %s%s", $dirtyPrefix, $node->getPath())); /* $existing = $loader->getExistingObject($node, $context); // Proceed to merge accordingly to 'keep' and 'drop' keys. if (!empty($object['keep'])) { if ('all' === $object['keep']) { drupal_array_merge_deep($existing, $object); } else if (is_array($object['keep'])) { foreach ($object['keep'] as $key) { if (array_key_exists($key, $existing)) { $object[$key] = $existing[$key]; } } } else { $context->logError(sprintf("%s: malformed 'keep' attribute, must be 'all' or an array of string attribute names", $node->getPath())); } } if (!empty($object['drop'])) { if (is_array($object['drop'])) { foreach ($object['drop'] as $key) { if (isset($object[$key])) { unset($object[$key]); } } } else { $context->logError(sprintf("%s: malformed 'drop' attribute, must be an array of string attribute names", $node->getPath())); } } */ } else { $context->getLogger()->log(sprintf(" + %s%s", $dirtyPrefix, $node->getPath())); } // unset($object['keep'], $object['drop']); $context->notify('load:sync:pre', $node); $identifier = $loader->synchronize($node, $context, $dirtyAllowed); $context->notify('load:sync:pre', $node); if ($identifier && $node instanceof DrupalNodeInterface) { $node->setDrupalIdentifier($identifier); } break; } }