[RFC] Property sorting in node list?
Closed this issue · 6 comments
We should add sorting to the node list command, the only question is if it should be on by default, or an option, or a configuration option.
I am tempted to make it on by default, but this would lose the "natural order" of the properties - would anybody care about that?
From:
PHPCRSH > ls
/cmf/sulu_io/contents/ceci-est-une-test [nt:unstructured] > nt:base
+----------------------------+--------------+------------------------------------------------+
| i18n:en-workflowStage | LONG (1) | 1 |
| jcr:uuid | STRING (36) | 70ea97fa-a60f-47b7-b291-1b6ec1a7b9d4 |
| i18n:denullfields | STRING (9) | [0] published |
| cnorm:email.0 | STRING (20) | daniel@dantleech.com |
| i18n:de-created | DATE (29) | 2015-02-26T18:08:14+01:00 |
| i18n:de-changer | LONG (1) | 1 |
| i18n:de-navigationContexts | STRING (0) | |
| phpcr:classparents | STRING (42) | [0] DTL\Bundle\ContentBundle\Document\Document |
| i18n:en-title | STRING (14) | This is a test |
| i18n:en-creator | LONG (1) | 1 |
| i18n:en-changer | LONG (1) | 1 |
| i18n:en-navigationContexts | STRING (0) | |
| i18n:en-structureType | STRING (7) | contact |
| i18n:en-changed | DATE (29) | 2015-02-26T18:08:14+01:00 |
| cnorm:telephone.0 | STRING (6) | 123123 |
| jcr:mixinTypes | NAME (13,17) | [0] phpcr:managed |
| | | [1] mix:referenceable |
| i18n:de-resourceLocator | STRING (15) | /url/to/content |
| jcr:primaryType | NAME (15) | nt:unstructured |
| i18n:de-structureType | STRING (7) | contact |
| ci18n:de-name.0 | STRING (20) | Danièl le Français |
| i18n:de-creator | LONG (1) | 1 |
| phpcr:class | STRING (46) | DTL\Bundle\ContentBundle\Document\PageDocument |
| i18n:ennullfields | STRING (9) | [0] published |
| i18n:de-workflowStage | LONG (1) | 1 |
| i18n:en-resourceLocator | STRING (15) | /url/to/content |
| i18n:de-title | STRING (17) | Ceci est une test |
| i18n:en-created | DATE (29) | 2015-02-26T18:08:14+01:00 |
| ci18n:en-name.0 | STRING (12) | Daniel Leech |
| i18n:de-changed | DATE (29) | 2015-02-26T18:08:14+01:00 |
+----------------------------+--------------+------------------------------------------------+
to
PHPCRSH > ls
/cmf/sulu_io/contents/ceci-est-une-test [nt:unstructured] > nt:base
+----------------------------+--------------+------------------------------------------------+
| ci18n:de-name.0 | STRING (20) | Danièl le Français |
| ci18n:en-name.0 | STRING (12) | Daniel Leech |
| cnorm:email.0 | STRING (20) | daniel@dantleech.com |
| cnorm:telephone.0 | STRING (6) | 123123 |
| i18n:de-changed | DATE (29) | 2015-02-26T18:08:14+01:00 |
| i18n:de-changer | LONG (1) | 1 |
| i18n:de-created | DATE (29) | 2015-02-26T18:08:14+01:00 |
| i18n:de-creator | LONG (1) | 1 |
| i18n:de-navigationContexts | STRING (0) | |
| i18n:de-resourceLocator | STRING (15) | /url/to/content |
| i18n:de-structureType | STRING (7) | contact |
| i18n:de-title | STRING (17) | Ceci est une test |
| i18n:de-workflowStage | LONG (1) | 1 |
| i18n:denullfields | STRING (9) | [0] published |
| i18n:en-changed | DATE (29) | 2015-02-26T18:08:14+01:00 |
| i18n:en-changer | LONG (1) | 1 |
| i18n:en-created | DATE (29) | 2015-02-26T18:08:14+01:00 |
| i18n:en-creator | LONG (1) | 1 |
| i18n:en-navigationContexts | STRING (0) | |
| i18n:en-resourceLocator | STRING (15) | /url/to/content |
| i18n:en-structureType | STRING (7) | contact |
| i18n:en-title | STRING (14) | This is a test |
| i18n:en-workflowStage | LONG (1) | 1 |
| i18n:ennullfields | STRING (9) | [0] published |
| jcr:mixinTypes | NAME (13,17) | [0] phpcr:managed |
| | | [1] mix:referenceable |
| jcr:primaryType | NAME (15) | nt:unstructured |
| jcr:uuid | STRING (36) | 70ea97fa-a60f-47b7-b291-1b6ec1a7b9d4 |
| phpcr:class | STRING (46) | DTL\Bundle\ContentBundle\Document\PageDocument |
| phpcr:classparents | STRING (42) | [0] DTL\Bundle\ContentBundle\Document\Document |
+----------------------------+--------------+------------------------------------------------+
afaik there is no "default" order for properties. they are technically unordered and relying on a particular order would be a mistake of client code. so ordering by default seems sane.
i wonder however if you should violate the strict alphabetical ordering to move jcr to the top. in the context of phpcr-odm, moving phpcr right after jcr would make sense too. but maybe that goes too far (hand-tuning custom order of namespaces and then sort the rest alphabetically). just sorting alphabetically looks like a good improvment. i would not even allow to disable that i think.
I tend to agree with making it on by default with no config, but do wonder if it would be useful to have the "natural order" in some places, e.g. when debugging PHPCR implementations, somehow.
Regarding changing the order, I think it would be better to not move things about. jcr:
is a system namespace, but I don't think we should treat it any differently with the ordering, putting it at the top would be confusing imo. what would be the benefit?
that i would see the node type and uuid immediately. if i could custom-order first jcr, than phpcr namespace, i would also see the document type without going through a long list. but lets ignore that for now. if you add a config option, lets just make it so that this is a future possibility (e.g. don't have sorted=true|false but ordering=alphabetical|undetermined)
and i would not call the thing "natural order" but "undetermined" to make clear that there are no guarantees whatsoever.
i thought maybe just add an option
--sort=[none|asc|desc]
and default always to asc