1
votes

I have upgraded a site from 3.5 to 4.x. Mostly going well, but hitting major snags with namespacing.

This one comes from a module called silverstripe-news that I have had to upgrade manually as it is abandonware. I used the upgrade-code tool on it, and manually did the rest as per the guide. But I may have missed something. But I can kind of see the issue.

Here's the basics of the original model admin:

class NewsAdmin extends ModelAdmin {
    private static $url_segment = 'news';
    private static $menu_title = 'News';

    private static $managed_models = array(
        'NewsPost'
    );
}

And here is NewsPost:

class NewsPost extends Page {
    private static $pages_admin = true;
    private static $db = array(
        'DateTime'          => 'SS_Datetime',
        'Tags'              => 'Varchar(500)',
        'Author'            => 'Varchar(100)',
        'Summary'           => 'HTMLText'
    );
}

After the upgrade-tool does it's thing, and my manual changes, they look more like this:

ModelAdmin

namespace Vendor\SilverstripeNews;

class NewsAdmin extends ModelAdmin {
    private static $url_segment = 'news';
    private static $menu_title = 'News';

    public $showImportForm = false;

    private static $managed_models = array(
        NewsPost::class
    );
}

NewsPost

namespace Vendor\SilverstripeNews;

class NewsPost extends Page {
    private static $singular_name = 'News Post';
    private static $plural_name   = 'News Posts';
    private static $table_name = "NewsPost";
    private static $pages_admin = true;

    private static $db = array(
        'DateTime'          => 'DBDatetime',
        'Tags'              => 'Varchar(500)',
        'Author'            => 'Varchar(100)',
        'Summary'           => 'HTMLText'
    );
}

The issue lies in the original data that was created under the old system. They are in SiteTree_Live with a ClassName of "NewsPost". Therefore, they cannot be found by ModelAdmin's managed_model (I think). Certainly, all the articles that were there before the upgrade, are no longer visible. I assume that it's looking for Vendor\SilverstripeNews\NewsPost, of which there are none.

Looking at this article, apparently managed_models still uses the old format anyway, and the Object::class method might be a simple inaccuracy from the upgrade-code tool. But I tried changing back to follow this article, dev/build, and reload, and I'm told "Class NewsPost does not exist".

1

1 Answers

2
votes

The issue lies in the original data that was created under the old system. They are in SiteTree_Live with a ClassName of "NewsPost". Therefore, they cannot be found by ModelAdmin's managed_model (I think).

You can use the classname_value_remapping config prop for this. This will update ClassName enum fields in the DB to reflect the new namespaces:

# File: yourmodule/_config/legacy.yml
SilverStripe\ORM\DatabaseAdmin:
  classname_value_remapping:
    NewsPost: Vendor\SilverStripeNews\NewsPost

See other legacy.yml files in core for more examples.

This gets run during a dev/build.