Possibly two questions for Glen who offered to look at this, but I'm posting here so anyone else who has the same problem can see it (or answer if they know how)...
Q1 - In my install script I like to report to the user in a message what version of the component has just been installed/uninstalled. In J3 I read the version from the manifest file as the best source of truth thus:
function postflight($type, $parent) {
$message = 'Installing xbOSM component v.'.$parent->get('manifest')->version.' '.$parent->get('manifest')->creationDate;
Factory::getApplication()->enqueueMessage($message,'Info');
...
And a similar thing when uninstalling in the uninstall function
$parent->get('manifest') causes a "Server Error" in j4,what can I use for a J4 install to get the version instead that will also work in J3?
Q2 - with some components when installing I need to create a default category ('Uncategorised') for the component in the install script. You can't do this in the sql install script because if the component has been previously installed the category will already exist and mysql barfs at the insert statement. You also don't know the correct values for lft, rgt, or created_user_id columns in the sql (the others you can make defaults for)
So what I usually do is this in the install php script
$message .= 'Creating xbOSM categories : ';
$category_data['id'] = 0;
$category_data['parent_id'] = 0;
$category_data['extension'] = 'com_xbosm';
$category_data['published'] = 1;
$category_data['language'] = '*';
$category_data['params'] = array('category_layout' => '','image' => '');
$category_data['metadata'] = array('author' => '','robots' => '');
$basePath = JPATH_ADMINISTRATOR.'/components/com_categories';
require_once $basePath.'/models/category.php';
$config = array('table_path' => $basePath.'/tables');
$category_model = new CategoriesModelCategory($config);
$db = Factory::getDBO();
$query = $db->getQuery(true);
$query->select('id')->from($db->quoteName('#__categories'))
->where($db->quoteName('alias')." = ".$db->quote('uncategorised'))
->where($db->quoteName('extension')." = ".$db->quote('com_xbosm'));
$db->setQuery($query);
if ($db->loadResult()>0) {
$message .= '"xbOSM Uncategorised" category already exists... ';
} else {
$category_data['title'] = 'Uncategorised';
$category_data['alias'] = 'uncategorised';
$category_data['description'] = 'Default category for xbOSM items not otherwise assigned';
if(!$category_model->save($category_data)){
$message .= '<br />[Error creating Uncategorised: '.$category_model->getError().']<br /> ';
}else{
$message .= '"Uncategorised" (id='. $category_model->getItem()->id.') created... ';
}
}
$query->clear();
Factory::getApplication()->enqueueMessage($message,'Info');
Thus using the com_category model to create the new category for the component, or report if it already exists. Works fine in j3, not in j4.
What should this be to work in both j3 and j4?
Hopefully someone has solved this one and can share the correct way....
Roger