Modx 3 : Reverse Engeneering scripts do not work anymore

Hi Everyone,

I have worked with 2.X for years with customs db tables. For that, I use the script from Bob :

With Modx 3, the script is no longer generating .map files. I have been testing the script :
https://docs.modx.com/3.x/en/extending-modx/xpdo/custom-models/generating-the-model/reverse-engineer

Which does not work as well.

I looked at the tuncion parseSchema in the new modx 3, this function has changed and it does no longer generate the .map files : but it does so in its 2.x version.

Does anyone face the same issue ? Is there a new script to use for reverse engeneering current db tables ?

Thanks in advance for your help

Maybe take a look at the extra ExtraBuilder.

I believe it supports the creation of the schema from an existing database table and I think it has been updated to run on MODX 3.

1 Like

Are you sure about this? During my last chat with Jason he told me that xPDO did not build the XML schema right for MODX3. I was working on FormIt2db with the autopackage option.

With my script, are you seeing anything relevant in the MODX error log?

With the other script, do you have Doctrine installed?

Thanks for your replies…

I am testing ExtraBuilder to see what can be done from it / if it works.

Bob, regarding your script, everything runs as usual and nothing appears in the error log. All files but .map.inc are generated.

For the second script, no, I did not install Doctrine.

I think you are right.

There was an option to “Import/Reverse Engineer from Tables” in version 1.
But in version 2 this functionality was removed (as far as I can tell).

I have tested ExtraBuilder… I have imported an existing Schema to start with my current tables.

It has loaded all things correctly… I have adjusted the key name to “XXX\Model” and I have then generated all files (schema, classes and map files) in various folders.

But then, my classes cannot be loaded in my snippets.

Just to mention it : when I take my 2.x generated .map.inc files and I place them to complete the files generated by your script running on modX 3, everything works as usual / all classes are well loaded.

It seems that it is just a matter of missing .map.inc files

Thanks for that info. I’ve added a note (with credit to you) on the page you linked to.

In 3.x models, there should not be separate map files. I will get the reverse engineering script worked out, but the model generation with the parse-schema command does work once you have a properly defined schema.

So, the .map.inc are no longer used in modx 3.0.

Please let me know about new version of the scripts… and thanks for helping out here :slight_smile:

They are used if the model is an xPDO 2.x model. But models built with 3.x include the map data as part of the platform class. No separate map file is generated by 3.x.

I’m little fixed it.
https://pastebin.com/yzzTXYQ8

Sorry—I neglected to reply, but in Revo ^3.0.1 (as well as in xPDO ~3.0.4|~3.1.1), you can use the xpdo write-schema command. I believe that the Revo 3.0.1 distribution includes xPDO 3.1.1.

❯ core/vendor/bin/xpdo help write-schema
Description:
  Generate an XML schema from existing database tables.

Usage:
  write-schema [options] [--] <platform> <schema_file> <package> [<base_class> [<table_prefix>]]

Arguments:
  platform               The PDO platform being targeted, e.g. mysql, sqlite, etc.
  schema_file            The path and filename to generate the XML schema to
  package                The package name (aka PHP namespace) for the schema
  base_class             An optional base_class to use for the generated schema objects; default is xPDO\Om\xPDOObject [default: ""]
  table_prefix           An optional table_prefix to override one specified for the xPDO configuration [default: ""]

Options:
  -r, --restrict_prefix  If set to 1, only tables that match the table_prefix will be included in the schema
  -C, --config=CONFIG    A path to a config file
  -h, --help             Display help for the given command. When no command is given display help for the list command
  -q, --quiet            Do not output any message
  -V, --version          Display this application version
      --ansi|--no-ansi   Force (or disable --no-ansi) ANSI output
  -n, --no-interaction   Do not ask any interactive question
  -v|vv|vvv, --verbose   Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
1 Like