Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate breaks Fred / ContentBlocks and others #144

Open
matdave opened this issue Mar 24, 2025 · 2 comments
Open

Migrate breaks Fred / ContentBlocks and others #144

matdave opened this issue Mar 24, 2025 · 2 comments

Comments

@matdave
Copy link
Contributor

matdave commented Mar 24, 2025

I just noticed that the migration script is serializing the properties, similar to issue #137

This is making it impossible to revert ContentBlocks or Fred resources that were pre-migration. I've got a tiny workaround to json_encode(unserialize($after)) and set the type to "array", but this should maybe be fixed in the migration script.

@matdave
Copy link
Contributor Author

matdave commented Mar 24, 2025

For reference for anyone else that runs into this issue, I'm providing my migration fix file here:

<?php 

use modmore\VersionX\VersionX;

require_once dirname(__DIR__, 3) . '/config.core.php';
require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
require_once MODX_CONNECTORS_PATH . 'index.php';


/** @var \modX|modX $modx */
$versionX = new VersionX($modx);

$c = $modx->newQuery('vxDeltaField');
$c->leftJoin('vxDelta', 'Delta', ['Delta.id = vxDeltaField.delta']);
$c->where([
    'Delta.principal_class' => 'modResource',
    'vxDeltaField.field' => 'properties',
    [
        'vxDeltaField.before:LIKE' => 'a:%',
        'OR:vxDeltaField.after:LIKE' => 'a:%'
    ]
]);

$c->limit(10000);

$collection = $modx->getIterator('vxDeltaField', $c);
$fix = 0;
foreach($collection as $df) {
    $save = false;
    if (str_starts_with($df->before, 'a:')) {
        $before = json_encode(unserialize($df->before));
        $df->set('before', $before);
        $df->set('before_type', 'array');
        $save = true;
    }
    if (str_starts_with($df->after, 'a:')) {
        $after = json_encode(unserialize($df->after));
        $df->set('after', $after);
        $df->set('after_type', 'array');
        $save = true;
    }
    if ($save) {
        $df->save();
        $fix++;
    }
}

print_r("\r\nDone fixing $fix!\r\n");

I have a "limit" set to keep it from killing the server, and it can be run as many times as needed.

@muzzwood
Copy link
Contributor

Thanks for catching that @matdave .. I've put together a PR here, though I no longer have data handy to test it. #145

Would you be able to give it a test, or send me a few records on one of the source tables where it's a problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants