Commit b1c47f17 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

During an upgrade, don't try to add blocktypes to viewtypes or categories that aren't installed yet


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent c613f4f4
...@@ -932,14 +932,17 @@ function get_blocktype_categories() { ...@@ -932,14 +932,17 @@ function get_blocktype_categories() {
function install_blocktype_categories_for_plugin($blocktype) { function install_blocktype_categories_for_plugin($blocktype) {
safe_require('blocktype', $blocktype); safe_require('blocktype', $blocktype);
$blocktype = blocktype_namespaced_to_single($blocktype); $blocktype = blocktype_namespaced_to_single($blocktype);
$catsinstalled = get_column('blocktype_category', 'name');
db_begin(); db_begin();
delete_records('blocktype_installed_category', 'blocktype', $blocktype); delete_records('blocktype_installed_category', 'blocktype', $blocktype);
if ($cats = call_static_method(generate_class_name('blocktype', $blocktype), 'get_categories')) { if ($cats = call_static_method(generate_class_name('blocktype', $blocktype), 'get_categories')) {
foreach ($cats as $cat) { foreach ($cats as $cat) {
insert_record('blocktype_installed_category', (object)array( if (in_array($cat, $catsinstalled)) {
'blocktype' => $blocktype, insert_record('blocktype_installed_category', (object)array(
'category' => $cat 'blocktype' => $blocktype,
)); 'category' => $cat
));
}
} }
} }
db_commit(); db_commit();
...@@ -948,14 +951,17 @@ function install_blocktype_categories_for_plugin($blocktype) { ...@@ -948,14 +951,17 @@ function install_blocktype_categories_for_plugin($blocktype) {
function install_blocktype_viewtypes_for_plugin($blocktype) { function install_blocktype_viewtypes_for_plugin($blocktype) {
safe_require('blocktype', $blocktype); safe_require('blocktype', $blocktype);
$blocktype = blocktype_namespaced_to_single($blocktype); $blocktype = blocktype_namespaced_to_single($blocktype);
$vtinstalled = get_column('view_type', 'type');
db_begin(); db_begin();
delete_records('blocktype_installed_viewtype', 'blocktype', $blocktype); delete_records('blocktype_installed_viewtype', 'blocktype', $blocktype);
if ($viewtypes = call_static_method(generate_class_name('blocktype', $blocktype), 'get_viewtypes')) { if ($viewtypes = call_static_method(generate_class_name('blocktype', $blocktype), 'get_viewtypes')) {
foreach($viewtypes as $vt) { foreach($viewtypes as $vt) {
insert_record('blocktype_installed_viewtype', (object)array( if (in_array($vt, $vtinstalled)) {
'blocktype' => $blocktype, insert_record('blocktype_installed_viewtype', (object)array(
'viewtype' => $vt, 'blocktype' => $blocktype,
)); 'viewtype' => $vt,
));
}
} }
} }
db_commit(); db_commit();
......
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