function tripal_project_update_7200
2.x tripal_project.install | tripal_project_update_7200() |
This is the required update for tripal_project when upgrading from Drupal core API 6.x.
File
- tripal_project/
tripal_project.install, line 141 - Install the tripal project
Code
function tripal_project_update_7200() {
// Make sure we have the full API loaded this will help during a
// site upgrade when the tripal_core module is disabled.
module_load_include('module', 'tripal_core', 'tripal_core');
tripal_core_import_api();
module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
// Add the project_property CV
try {
// First we add the cv.
// Notice that tripal_insert_cv() will only add it if it doesn't exist already.
$cv = tripal_insert_cv(
'project_property',
'Contains properties for projects'
);
if ($cv) {
$cv_id = $cv->cv_id;
// Set as Default CV for contact types.
$is_set = tripal_get_default_cv('projectprop', 'type_id');
if (!$is_set) {
tripal_set_default_cv('projectprop', 'type_id', 'project_property', $cv_id);
}
}
}
catch (\PDOException $e) {
$error = $e->getMessage();
throw new DrupalUpdateException('Failed to add project_property vocabulary: ' . $error);
}
// add the project_relationship CV
try {
// First we add the cv.
// Notice that tripal_insert_cv() will only add it if it doesn't exist already.
$cv = tripal_insert_cv(
'project_relationship',
'Contains types of relationships between projects.'
);
if ($cv) {
$cv_id = $cv->cv_id;
// Set as Default CV for contact types.
$is_set = tripal_get_default_cv('project_relationship', 'type_id');
if (!$is_set) {
tripal_set_default_cv('project_relationship', 'type_id', 'project_relationship', $cv_id);
}
}
}
catch (\PDOException $e) {
$error = $e->getMessage();
throw new DrupalUpdateException('Failed to add project_relationship vocabulary: ' . $error);
}
// For Tripal in Drupal 6 the project_description cvterm was stored in the
// 'tripal' CV. It should be stored in the new project_property CV that
// is added by this module for Tripal 2.0 and Drupal 7. So, we need to
// reset the CV ID for that term and rename the term to 'Project Description'
$sql = "
UPDATE {cvterm} CVT
SET
name = 'Project Description',
cv_id = (SELECT cv_id FROM {cv} WHERE name = 'project_property')
WHERE
name = 'project_description' AND
cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal')
";
try {
chado_query($sql);
}
catch (\PDOException $e) {
$error = $e->getMessage();
throw new DrupalUpdateException('Failed to change project_description property type to the project_property CV and update the name: ' . $error);
}
}