Trouble with extensionPackage object in MODX 3

I’ve been wrestling with trying to make ClassExtender work in MODX 3 for days.

I don’t know if this is a bug, or if I’m doing something wrong.

Calling parseSchema() and createObjectContainer() both work (finally). They create the class files and the DB table. Creating the modExtensionPackage object for my package in the DB works as well.

However, I can’t get the classes to work unless I include my autoloader, and addPackage().

Here’s the record in the modx_extension_packages table:

ID: 8
namespace: "extendeduser"
name: "extendeduser"
package: "extendeduser"
path: "[[++core_path]]components/classextender/model/"
table_prefix: "ext_"

(I would have used the users’ table prefix (e.g., modx_), but it would break existing installs.)

This code in a snippet prints a handful of MODX packages, but does not list the extendeduser package.

 return '<pre>' . print_r($modx->packages, true) . '</pre>';

If I call $modx->addExtensionPackage() instead of using the modExtensionPackage object, things work as expected, and I don’t have to call addPackage() any more, but it’s deprecated.

Either the modExtensionPackage object doesn’t actually work in this situation, or I’m doing something wrong.

I should also mention that when using Xdebug and stepping through the code of $this->_loadExtensionPackages($options); called in $modx->initialize(), things go sideways at line 63 of modExtensionPackage.php when $modx->getCacheManager() fails.

Any help appreciated.

Worth linking back to the issue: Update modX.[add|remove]ExtensionPackage to use new modExtensionPackage model · Issue #11463 · modxcms/revolution · GitHub

Agreed, though that’s not a good idea unless MODX will actually load them.

I can’t reproduce this. When I debug it, $modx->getCacheManager() works fine and the cache file core/cache/namespaces/extension-packages.cache.php is created.

Make sure to create a corresponding record in the table modx_namespaces.

I’m suspect that you’ve identified the problem. I didn’t create the namespace object because it looked like the namespace was only consulted if the extension package’s path was empty, but maybe it’s necessary for the cacheManager call.

Yes, there is an inner join in the query:

Good catch. Thanks!!!

The extension package isn’t loaded unless the namespace exists.

Oddly, I’m still seeing the same thing as before in Xdebug. The MODX initialize() function calls _loadExtensionPackages(), where the extension package is still not being loaded. If I’m not in the debugger, the package gets loaded. I think there may be an exception that’s thrown and caught, but not reported.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.

Everything seems copacetic now that I’ve fixed the schema and created the namespaces. Thanks again for the help.