modmore / Gitify

Command line toolkit to make managing a MODX site in git a lot easier.
MIT License
122 stars 55 forks source link

modTemplateVarTemplate are getting overwritten by each other #437

Closed DLSamson closed 1 year ago

DLSamson commented 1 year ago

Summary

When I execute gitify extract, to create links between TV and Template as file name, Gitify concatenates tmplvarid and templateid. But, when the file names are the same, it just overwrites one by other.

For example: 112.yaml Can be a result of tmplvarid: 1 and templateid: 12 or Can be a result of tmplvarid: 11 and templateid: 2

So as a result when I execute gitify build it detaches tv from template, because it thinks it is orphaned.

Part of debug logs from gitify extract -vvv

Extracting modTemplateVarTemplate into template_variables_access (132 records)...
- Generated 14.yaml
- Generated 15.yaml
- Generated 16.yaml
- Generated 17.yaml
- Generated 19.yaml
- Generated 112.yaml             <- The first time
- Generated 22.yaml
- Generated 32.yaml
- Generated 52.yaml
- Generated 529.yaml
- Generated 530.yaml
- Generated 62.yaml
- Generated 72.yaml
- Generated 85.yaml
- Generated 86.yaml
- Generated 87.yaml
- Generated 95.yaml
- Generated 96.yaml
- Generated 97.yaml
- Generated 102.yaml
- Generated 103.yaml
- Generated 104.yaml
- Generated 105.yaml
- Generated 106.yaml
- Generated 107.yaml
- Generated 1010.yaml
- Generated 1011.yaml
- Generated 1019.yaml
- Generated 1022.yaml
- Generated 112.yaml            <- The second time
- Generated 113.yaml
- Generated 114.yaml
- Generated 115.yaml
- Generated 116.yaml
- Generated 117.yaml

Step to reproduce

Create a template with id 12. Attach tv with id 1 to it. Create a template with id 2. Attach tv with id 11 to it.

Execute gitify extract Execute gitify build

It will say the first modTemplateVarTemplate is orphaned and will detach it from template.

Environment

Gitify version: 2.0.1-pl, MODX version: 2.8.4-pl, Operating System: Windows 10, MySQL version: 8, PHP version: 7.4

Suggestion

Maybe we should add a symbol between tmplvarid and templateid? For example: dot or dash

So in my case we would get files like:

1.12.yaml and 11.2.yaml or 1-12.yaml and 11-2.yaml

P.S. I know about gitify build --no-cleanup, but we cannot use it, since many people can work with site's repository and add or delete elements.

hugopeek commented 1 year ago

Hi @DLSamson, what does your config for this table look like, in .gitify?

In my case, the tmplvarid and templateid values are separated by a . in the file name, with the following config:

    template_variables_access:
        class: modTemplateVarTemplate
        primary:
            - tmplvarid
            - templateid
DLSamson commented 1 year ago

It looks like this:

template_variables_access:
        class: modTemplateVarTemplate
        primary:
            - tmplvarid
            - templateid

Also gitify in my composer.lock file:

"name": "modmore/gitify",
"version": "2.0.1-pl"

I installed gitify locally in the project, so I use vendor/bin/gitify

DLSamson commented 1 year ago

Hello again, I found out what was the problem.

How to fix this:

  1. Open your system_settings
  2. Find friendly_alias_restrict_chars and friendly_alias_restrict_chars_pattern
  3. Check if it has \. in it
  4. Choose a different value for friendly_alias_restrict_chars or Remove \. from friendly_alias_restrict_chars_pattern

Explanation:

In method modmore\Gitify\Command\ExtractCommand::extractObjects when making a file name, it passes it through modmore\Gitify\Command\ExtractCommand::filterPathSegment method

Which is

Uses the modResource::filterPathSegment method if available for cleaning a file path.

  • When it is not available (pre MODX 2.3) it uses a fake resource to call its cleanAlias method

modResource::filterPathSegment method checks friendly_alias_restrict_chars and friendly_alias_restrict_chars_pattern config values

In my case, pattern had \. character, so it has been cleaning it as well from file name. I removed it. Now it's okay, files are genereting with a dot in its name.