Commit 606eff4a by Nigel Cunningham Committed by Robert Lyon

Bug1287344: Don't try to delete missing artefact plugins' data

Don't try to delete the data of missing artefact plugins when upgrading. The user might want the data but be unable to get a matching version at the moment. behatnotneeded: DB upgrading Change-Id: I52dfec0d97a4bf36a96ca41823c8203f5abb8c73 Signed-off-by: 's avatarNigel Cunningham <nigelc@catalyst-au.net>
parent aae69bc6
......@@ -535,7 +535,7 @@ function upgrade_plugin($upgrade) {
}
}
// install artefact types
// install artefact types
if ($plugintype == 'artefact') {
if (!is_callable(array($pcname, 'get_artefact_types'))) {
throw new InstallationException("Artefact plugin $pcname must implement get_artefact_types and doesn't");
......@@ -543,6 +543,16 @@ function upgrade_plugin($upgrade) {
$types = call_static_method($pcname, 'get_artefact_types');
$ph = array();
if (is_array($types)) {
// Check for missing plugins - don't try to remove their data.
// Bugs 505732 and 1287344.
$used_types = get_records_sql_assoc("SELECT t.name, count(a.id) ct, t.plugin FROM {artefact_installed_type} t
LEFT JOIN {artefact} a ON t.name = a.artefacttype
GROUP BY t.name
HAVING count(a.id) > 0 AND plugin = '$pluginname'");
if ($used_types === FALSE) {
$used_types = array();
}
foreach ($types as $type) {
$ph[] = '?';
if (!record_exists('artefact_installed_type', 'plugin', $pluginname, 'name', $type)) {
......@@ -551,10 +561,23 @@ function upgrade_plugin($upgrade) {
$t->plugin = $pluginname;
insert_record('artefact_installed_type',$t);
}
if (isset($used_types[$type])) {
unset($used_types[$type]);
}
}
foreach ($used_types as $type) {
$ph[] = '?';
}
$used_types = array_keys($used_types);
$select = '(plugin = ? AND name NOT IN (' . implode(',', $ph) . '))';
delete_records_select('artefact_installed_type', $select,
array_merge(array($pluginname),$types));
array_merge(array($pluginname),$types,$used_types));
if (!empty($used_types)) {
log_warn('Plugin for artefact type(s) "' . implode('", "', $used_types) . '" has gone away', true, false);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment