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

Fields don't survive migration from ss3 to ss4 #179

Open
OldStarchy opened this issue Feb 17, 2022 · 2 comments
Open

Fields don't survive migration from ss3 to ss4 #179

OldStarchy opened this issue Feb 17, 2022 · 2 comments

Comments

@OldStarchy
Copy link

After upgrading from 3.6.7 to 4.10 the configuration for all the fields in all MemberProfilePages are reset to defaults.
The version of the silverstripe-memberprofiles package was upgraded from 2.0.3 to 4.0.6. Have been following the instructions here.

It looks like all the original field settings have become "archived", though they still all display in the field list. Is there a defined migration strategy for this module?

@OldStarchy
Copy link
Author

OldStarchy commented Feb 17, 2022

Some fields are duplicated, all the original fields are still there but have become "archived", and new fields (from the initial dev/build I guess) are duplicating the member fields; there's two "First Name" fields, two "Surname" fields, etc.

@OldStarchy
Copy link
Author

OldStarchy commented Feb 17, 2022

I think this is because the fields need to be published initially during migration. Maybe. I need to do more testing.

This might help

PublishMemberProfileFieldsTask.php
<?php

use Psr\Log\LoggerInterface;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Versioned\RecursivePublishable;
use SilverStripe\Versioned\Versioned;
use Symbiote\MemberProfiles\Model\MemberProfileField;

class PublishMemberProfileFieldsTask extends BuildTask
{
    protected $title = 'Publish archived Member Profile Fields';

    protected $description = 'Publishes all archived Member Profile Fields';

    protected $enabled = true;

    public function run($request)
    {
        /** @var LoggerInterface */
        $logger = Injector::inst()->get(LoggerInterface::class);

        /** @var (MemberProfileField & RecursivePublishable & Versioned)[] */
        $fields = MemberProfileField::get()->sort('ProfilePageID');

        $logger->info('Publishing fields...');
        $errors = 0;
        $success = 0;
        $skipped = 0;
        foreach ($fields as $field) {
            if ($field->isArchived()) {
                $logger->info("PUBLISHING: Page({$field->ProfilePageID}) {$field->ID} {$field->MemberField} \"{$field->CustomTitle}\"");

                try {
                    $field->write(false, false, true);
                    $field->publishRecursive();
                    $success++;
                } catch (Error $e) {
                    $logger->error($e->getMessage());
                    $errors++;
                }
            } else {
                $logger->info("SKIPING   : Page({$field->ProfilePageID}) {$field->ID} {$field->MemberField} \"{$field->CustomTitle}\"");
                $skipped++;
            }
        }
        $logger->info("Published ${success} fields, ${errors} errors, (${skipped} skipped)");
    }
}

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

1 participant