Closed (fixed)
Project:
Replication
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Aug 2016 at 17:06 UTC
Updated:
31 Aug 2016 at 08:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
josephdpurcell commentedThis patch does the following:
This work is needed for #2749167: Support ReplicationTask. It is on GitHub: https://github.com/relaxedws/drupal-replication/pull/12
This work needs tests.
Comment #6
josephdpurcell commentedThis patch adds a test.
Comment #10
josephdpurcell commentedReroll of #6 against updated 8.x-1.x branch.
Comment #11
phenaproxima'article' seems like a node bundle. Should the parameters be
{entity_type: node, bundle: article}?Ditto.
I'm not sure 'array' is a valid config schema type. Since the parameters are likely to be a free-form array, maybe this should simply be 'ignore'?
I don't think filter_id is a valid entity key...should this be removed? Unless I'm missing something, I'm not sure it confers any benefit.
My inner grammar pedant cringed at this. s/this/these?
Same here.
Is this going to be the configuration of the filter plugin? If so, I'm not sure $parameters needs to be its own thing; we could simply store the configuration of the plugin itself ($this->getFilter()->getConfiguration() or similar), or maybe use a plugin collection.
Can the default value of $parameters_array simply be [], to avoid the sanity check?
Both of these need @inheritdoc.
Comment #12
josephdpurcell commentedComment #13
phenaproximaSequences are used for non-associative sets, like ['foo', 'bar', 'baz']. Since the filter plugin's configuration will almost certainly be associative, and have varying keys and values (depending on the configuration values of the filter plugin in use), I would recommend the use of the
ignoretype so that validation is skipped entirely for the plugin configuration. There are ways to get it to validate the config values of each plugin, but frankly that's probably more work than we need to do right now.Sure. Certain fields of each entity type can have special meaning to Drupal's entity system. For instance, one of the fields is the unique identifier for the entity -- that's the 'id' key. Another one might be the canonical human-readable name of the entity; that's the 'label' key. If the entity can have a unique owner, that'd be its 'uid' key. The entity_keys array in the annotation identifies which fields of the entity map to which keys. There are a bunch of different keys (including 'status', 'uuid', and others), but they are not arbitrary. So filter_id probably does not belong in there, since that's not a known entity key :)
Comment #14
josephdpurcell commented3. Understood; 'ignore' is now used.
4. Ok, that makes sense; I couldn't find any documentation on d.o for it.
7. Still need to discuss.
This patch addresses #3 and revises the test.
Comment #15
josephdpurcell commentedThis patch:
Comment #16
phenaproximaOh, this is coming along nicely :) I have some nitpicks, as is my wont, plus a few defensive-programming things...
This could be
($this->parameters instanceof ParameterBag) ? $this->parameters->all() : []; then we don't need to bother constructing an empty parameter bag.Although this would also require a few changes further down, so maybe not the greatest idea. It's a nitpick in any event.
if ($filter !== NULL)should probably beif (isset($filter)), in case the variable doesn't exist at all.Should be 'array', since there's no real guarantee that every element in $parameters is a string.
Same here.
s/id's/IDs
s/ids/IDs
If the counts are not equal, does that mean the plugin is misconfigured? If so, maybe we should throw a LogicException here rather than silently returning false, since that could result in some very hard-to-trace bugs.
It might be simpler (although I don't know if it would be equally or more performant) to do this instead:
return in_array($entity->getEntityTypeId(), $entity_type_ids) && in_array($entity->bundle(), $bundles). Just a suggestion.It appears that this plugin effectively only supports nodes. Because status is a known entity key, we can make this plugin much more generic. All we need to do is inject the entity type manager service into the plugin (using ContainerFactoryPluginInterface), check the entity type definition for a status key, and filter on that if one exists. Let's nip this in the bud and make this plugin generic.
Should be string[].
I'm not sure about the use of array_filter() here. It's entirely possible that FALSE, 0, and '0' -- none of which will pass array_filter() -- could be perfectly valid values. So in the name of future proofing, my preference is to drop the array_filter() call and expect the calling code to remove invalid or empty values.
I think we should rename this to setParameters() -- it's going to be pretty intuitive that it expects an array.
Let's use assertInstanceOf() here.
$this->assertInstanceOf(ReplicationSettings::class, $entity)s/id/ID
Maybe this should be "bundle ID".
Comment #17
josephdpurcell commentedFollow ups:
Comment #18
phenaproximaWhoops, this should be \LogicException (so the entire use statement can go away).
\LogicException. Additionally, I'm told we're not supposed to put periods at the end of exception messages...
Missing description.
This should be something like this:
if ($status_key = $definition->getKey('status')) return (bool) $entity->$status_keyI wonder if this should be configurable.
Comment #19
josephdpurcell commentedFrom #17:
From #18:
Comment #20
phenaproximaReally close now. I'm having trouble finding things to nitpick.
I'm thinking we should maybe make $configuration['types'] always be an array, even if it's just got one value. Totally not a big deal, of course, but I've never been a huge fan of parsing array-or-string configuration options when an array would be perfectly acceptable.
Should be "include_unpublishable_entities". (Drop the extra E.)
Looks like there might be a rogue line in there :)
The description should come before the @var line, and they should be separated by a blank line.
As I mentioned before, is there any real reason beyond CouchDB compliance to not make $configuration['uuids'] an array in all cases?
A bit unorthodox -- I think the preferred/"traditional" way is probably to call
$this->container('entity_type.manager')->getStorage($entity_type)->create($entity_values)...but this will do fine as well :) Besides, no entity type parameter is being passed in.Let's do assertSame() here to avoid potential snafus over truthy and falsy $expected values.
This method has no data provider, so why does it have parameters at all?
Comment #21
josephdpurcell commentedComment #22
josephdpurcell commentedI missed fixing a few comments from #20 item #4. You can review this instead of #21, but I've added an interdiff anyway to show the difference.
Comment #23
josephdpurcell commentedTests are failing on GitHub, I didn't update the tests! :O I'll fix those later. See https://github.com/relaxedws/drupal-replication/pull/12
Comment #24
josephdpurcell commentedTests are now passing, the changes were mostly cleanup around the switch from filter parameters as strings to multi-dimensional arrays.
Ready for review!
Comment #25
josephdpurcell commentedSetting to needs review just so there is a record.
Comment #44
phenaproximaI could be wrong about this, but is YAML case-sensitive? If it is, then this needs to be lowercase 'false'. I know YAML is a superset of JSON, but I don't know if that implies case-sensitivity.
Nit: id should be ID. I'm not sure I want to hold this patch up longer over that, though :) Could be fixed on commit.
How is it possible that we're doing $this->parameters->set() if $this->parameters is an array? Won't this die with a fatal error?
No need to change this for now, but for the record, you can use the slightly more convenient assertCount(), like so:
$this->assertCount(1, $changes, 'There is one change')s/id/ID. Fixable on commit, if we want to nitpick.
This doc comment no longer makes sense, since we're using the storage handler's create() method. How about something like "The values with which to create the entity"?
I don't think this assertion adds much value, since we're just testing the output of the entity storage handler, which is covered by core tests. I would recommend we do something like this, if we want to bother keeping it at all:
$saved = $entity->saved(); $this->assertNotEmpty($saved);Comment #45
josephdpurcell commentedComment #49
josephdpurcell commentedAfter switching to BrowserTestBase, the ReplicationFilterTest passes on Travis: https://github.com/relaxedws/drupal-replication/pull/12
Comment #50
phenaproximaMe likey. And @josephdpurcell deserves a rest for his troubles :) RTBC!
Comment #52
jeqq commentedThank you @josephdpurcell and @phenaproxima for your work on this issue!