Commit d31993dd authored by Doris Tam's avatar Doris Tam Committed by Robert Lyon
Browse files

Bug 1911824: Change the copy setting for artefact annotation to 'nocopy'

Check that $evidences exist in case there exist evidenviews but no evidence blocks to copy

if the only block on a view is an annotation block, then make a check to not get the sql to run copies
which will result in error as there are no artefacts to copy.

Change-Id: Ie914704046c2396a2fedce958cef3a44dd28ae33
(cherry picked from commit cba39269)
parent 69b378d1
......@@ -567,7 +567,7 @@ class PluginBlocktypeExternalfeed extends MaharaCoreBlocktype {
return $result;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'full';
}
......
......@@ -519,7 +519,7 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
return $smarty->fetch('blocktype:externalvideo:servicelist.tpl');
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'full';
}
......
......@@ -409,7 +409,7 @@ class PluginBlocktypeGoogleApps extends MaharaCoreBlocktype {
return $smarty->fetch('blocktype:googleapps:supported.tpl');
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'full';
}
......
......@@ -61,7 +61,7 @@ class PluginBlocktypeGroupInfo extends MaharaCoreBlocktype {
return false;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -279,7 +279,7 @@ class PluginBlocktypeGroupViews extends MaharaCoreBlocktype {
);
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -132,7 +132,7 @@ class PluginBlocktypeInbox extends MaharaCoreBlocktype {
return $elements;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -637,7 +637,7 @@ EOF;
// Do nothing, in the default case
}
/*
/**
* The copy_type of a block affects how it should be copied when its view gets copied.
* nocopy: The block doesn't appear in the new view at all.
* shallow: A new block of the same type is created in the new view with a configuration as specified by the
......@@ -651,8 +651,11 @@ EOF;
*
* If the old owner and the new owner are the same, reference is used unless 'fullinclself' is specified.
* If a block contains no artefacts, reference and full are equivalent.
*
* @param BlockInstance $instance of the block
* @param View $view - the view the block is created for
*/
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......@@ -2201,7 +2204,7 @@ class BlockInstance {
$copytype = $configdata['copytype'];
}
else {
$copytype = call_static_method($blocktypeclass, 'default_copy_type');
$copytype = call_static_method($blocktypeclass, 'default_copy_type', $this, $view);
}
$viewowner = $view->ownership();
......
......@@ -147,7 +147,7 @@ class PluginBlocktypeMyfriends extends MaharaCoreBlocktype {
return false;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -169,7 +169,7 @@ class PluginBlocktypeMyGroups extends MaharaCoreBlocktype {
return $values;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -143,7 +143,7 @@ class PluginBlocktypeMyviews extends MaharaCoreBlocktype {
return false;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -197,7 +197,7 @@ class PluginBlocktypeNavigation extends MaharaCoreBlocktype {
return $values;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'full';
}
......
......@@ -120,7 +120,7 @@ class PluginBlocktypeNewViews extends MaharaCoreBlocktype {
return $elements;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -744,7 +744,7 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
return $values;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -212,7 +212,7 @@ class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype {
return $elements;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -185,7 +185,7 @@ class PluginBlocktypeText extends MaharaCoreBlocktype {
EmbeddedImage::delete_embedded_images('instructions', $instance->get('id'));
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'full';
}
......
......@@ -667,7 +667,7 @@ EOF;
return $values;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'fullinclself';
}
......
......@@ -318,7 +318,7 @@ EOF;
return false;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -302,7 +302,7 @@ class PluginBlocktypeWatchlist extends MaharaCoreBlocktype {
return $values;
}
public static function default_copy_type() {
public static function default_copy_type(BlockInstance $instance, View $view) {
return 'shallow';
}
......
......@@ -625,43 +625,47 @@ class Collection {
// If there are views with framework evidence to re-map
if (!empty($evidenceviews)) {
// We need to get how the old views/artefacts/blocks/evidence fit together
$evidences = get_records_sql_array('
SELECT va.view, va.artefact, va.block, fe.*
FROM {view} v
JOIN {view_artefact} va ON va.view = v.id
JOIN {artefact} a ON a.id = va.artefact
JOIN {framework_evidence} fe ON fe.view = v.id
WHERE v.id IN (' . join(',', array_keys($evidenceviews)) . ')
AND a.id IN (' . join(',', array_keys($artefactcopies)) . ')
AND fe.annotation = va.block', array());
$newartefactcopies = array();
foreach ($artefactcopies as $ac) {
$newartefactcopies[$ac->newid] = 1;
}
// And get how the new views/artefacts/blocks fit together
$newblocks = get_records_sql_assoc('
SELECT va.artefact, va.view, va.block
FROM {view} v
JOIN {view_artefact} va ON va.view = v.id
JOIN {artefact} a ON a.id = va.artefact
WHERE v.id IN (' . join(',', array_values($evidenceviews)) . ')
AND a.id IN (' . join(',', array_keys($newartefactcopies)) . ')
AND artefacttype = ?', array('annotation'));
foreach ($evidences as $evidence) {
if (key_exists($evidence->artefact, $artefactcopies) && key_exists($artefactcopies[$evidence->artefact]->newid, $newartefactcopies)) {
$newartefact = $artefactcopies[$evidence->artefact]->newid;
$newevidence = new stdClass();
$newevidence->view = $newblocks[$newartefact]->view;
$newevidence->artefact = $newartefact;
$newevidence->annotation = $newblocks[$newartefact]->block;
$newevidence->framework = $evidence->framework;
$newevidence->element = $evidence->element;
$newevidence->state = 0;
$newevidence->reviewer = null;
$newevidence->ctime = $evidence->ctime;
$newevidence->mtime = $evidence->mtime;
insert_record('framework_evidence', $newevidence);
if (!empty($artefactcopies)) {
$evidences = get_records_sql_array('
SELECT va.view, va.artefact, va.block, fe.*
FROM {view} v
JOIN {view_artefact} va ON va.view = v.id
JOIN {artefact} a ON a.id = va.artefact
JOIN {framework_evidence} fe ON fe.view = v.id
WHERE v.id IN (' . join(',', array_keys($evidenceviews)) . ')
AND a.id IN (' . join(',', array_keys($artefactcopies)) . ')
AND fe.annotation = va.block', array());
$newartefactcopies = array();
foreach ($artefactcopies as $ac) {
$newartefactcopies[$ac->newid] = 1;
}
// And get how the new views/artefacts/blocks fit together
$newblocks = get_records_sql_assoc('
SELECT va.artefact, va.view, va.block
FROM {view} v
JOIN {view_artefact} va ON va.view = v.id
JOIN {artefact} a ON a.id = va.artefact
WHERE v.id IN (' . join(',', array_values($evidenceviews)) . ')
AND a.id IN (' . join(',', array_keys($newartefactcopies)) . ')
AND artefacttype = ?', array('annotation'));
if (!empty($evidences)) {
foreach ($evidences as $evidence) {
if (key_exists($evidence->artefact, $artefactcopies) && key_exists($artefactcopies[$evidence->artefact]->newid, $newartefactcopies)) {
$newartefact = $artefactcopies[$evidence->artefact]->newid;
$newevidence = new stdClass();
$newevidence->view = $newblocks[$newartefact]->view;
$newevidence->artefact = $newartefact;
$newevidence->annotation = $newblocks[$newartefact]->block;
$newevidence->framework = $evidence->framework;
$newevidence->element = $evidence->element;
$newevidence->state = 0;
$newevidence->reviewer = null;
$newevidence->ctime = $evidence->ctime;
$newevidence->mtime = $evidence->mtime;
insert_record('framework_evidence', $newevidence);
}
}
}
}
}
......
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