I have a class 'CourseTemplatePage' which extends the Page class. I want to create a clone of this page when the CloneAsTemplate action is called.
$data = $arguments->allParams();
if($ct = DataObject::get_by_id('CourseTemplatePage', $data['ID']))
$newct = $ct->duplicateWithChildren();
$newct->Title .= ' (Clone)';
The this code gets to the publish command, an Warning occurs, stating that the record didn't exist in Stage.
Upon inspecting the database, everything seems to be correct, with proper entries in the CourseTemplatePage, CourseTemplatePage_Live, CourseTemplatePage_version, etc...
However, when I took a look at the record in SiteTree, I saw the record had a ClassName of 'SiteTree' instead of 'CourseTemplatePage'. Looking at the code for the Versioned class, it appears that the class name must properly match in order for publish to work.
Is there something wrong in my code that is causing duplicateWithChildren() to incorrectly classify the CourseTemplatePage? Or is there something else that I am glossing over? Any help would be appreciated.