Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
abc25e8a
Commit
abc25e8a
authored
Jul 17, 2015
by
Robert Lyon
Committed by
Gerrit Code Review
Jul 17, 2015
Browse files
Merge "Rewrite the navigation block's collection pointer, after leap2a import"
parents
2b5b8da7
3658fa88
Changes
3
Hide whitespace changes
Inline
Side-by-side
htdocs/blocktype/lib.php
View file @
abc25e8a
...
@@ -377,6 +377,23 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
...
@@ -377,6 +377,23 @@ abstract class PluginBlocktype extends Plugin implements IPluginBlocktype {
return
$configdata
;
return
$configdata
;
}
}
/**
* Rewrite a block instance's relationships to views & collections at the end of the leap import process.
*
* (For instance the navigation block stores a collection ID, and needs to know the new ID the
* collection wound up with.)
*
* This method is called at the end of the import process. You will probably want to access the
* $importer->viewids, $importer->collectionids, and/or $importer->artefactids fields
*
* @param int $blockinstanceid ID of the block instance.
* @param PluginImportLeap $importer The importer object.
*/
public
static
function
import_rewrite_blockinstance_relationships_leap
(
$blockinstanceid
,
$importer
)
{
// Do nothing, in the default case
}
/*
/*
* The copy_type of a block affects how it should be copied when its view gets copied.
* 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.
* nocopy: The block doesn't appear in the new view at all.
...
...
htdocs/blocktype/navigation/lib.php
View file @
abc25e8a
...
@@ -33,7 +33,7 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
...
@@ -33,7 +33,7 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
$configdata
=
$bi
->
get
(
'configdata'
);
$configdata
=
$bi
->
get
(
'configdata'
);
if
(
!
empty
(
$configdata
[
'collection'
]))
{
if
(
!
empty
(
$configdata
[
'collection'
]))
{
return
$bi
->
get_data
(
'collection'
,
$configdata
[
'collection'
])
->
get
(
'name'
);
return
$bi
->
get_data
(
'collection'
,
(
int
)
$configdata
[
'collection'
])
->
get
(
'name'
);
}
}
return
''
;
return
''
;
}
}
...
@@ -43,7 +43,7 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
...
@@ -43,7 +43,7 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
$smarty
=
smarty_core
();
$smarty
=
smarty_core
();
if
(
!
empty
(
$configdata
[
'collection'
]))
{
if
(
!
empty
(
$configdata
[
'collection'
]))
{
$views
=
$instance
->
get_data
(
'collection'
,
$configdata
[
'collection'
])
->
views
();
$views
=
$instance
->
get_data
(
'collection'
,
(
int
)
$configdata
[
'collection'
])
->
views
();
if
(
!
empty
(
$views
))
{
if
(
!
empty
(
$views
))
{
$smarty
->
assign
(
'views'
,
$views
[
'views'
]);
$smarty
->
assign
(
'views'
,
$views
[
'views'
]);
}
}
...
@@ -129,4 +129,60 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
...
@@ -129,4 +129,60 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
return
'full'
;
return
'full'
;
}
}
/**
* Change the collection ID format to match the ID format we use in Leap2A,
* e.g.: portfolio:collection23
*
* @param BlockInstance $bi The blockinstance to export the config for.
* @return array The config for the blockinstance
*/
public
static
function
export_blockinstance_config_leap
(
BlockInstance
$bi
)
{
$jsonconfigdata
=
parent
::
export_blockinstance_config_leap
(
$bi
);
if
(
isset
(
$jsonconfigdata
[
'collection'
]))
{
// It should be a collection...
$collection
=
json_decode
(
$jsonconfigdata
[
'collection'
]);
if
(
is_array
(
$collection
))
{
$collection
=
$collection
[
0
];
}
$jsonconfigdata
[
'collection'
]
=
json_encode
(
array
(
'portfolio:collection'
.
(
int
)
$collection
));
}
return
$jsonconfigdata
;
}
/**
* After a leap2a import, rewrite the block instance's collection ID to the collection's new ID.
* (If the collection was part of this import. If it's not, just remove it.)
*
* @param int $blockinstanceid
* @param PluginLeapImport $importer
*/
public
static
function
import_rewrite_blockinstance_relationships_leap
(
$blockinstanceid
,
$importer
)
{
$bi
=
new
BlockInstance
(
$blockinstanceid
);
$configdata
=
$bi
->
get
(
'configdata'
);
// Rewrite the collection ID from the old one to the new one.
if
(
isset
(
$configdata
[
'collection'
]))
{
$oldcollectionid
=
$configdata
[
'collection'
];
// Backwards-compatibility for Leap2a files before we started rewriting the collection ID
if
(
strpos
(
$oldcollectionid
,
'portfolio:collection'
)
!==
0
)
{
$oldcollectionid
=
'portfolio:collection'
.
(
int
)
$oldcollectionid
;
}
if
(
isset
(
$importer
->
collectionids
[
$oldcollectionid
]))
{
// If the collection was present in this import, point to its new ID
$configdata
[
'collection'
]
=
$importer
->
collectionids
[
$oldcollectionid
];
}
else
{
// If the collection was not present, then deactivate this block
// TODO: Make some guesses about what it should point at?
unset
(
$configdata
[
'collection'
]);
}
}
$bi
->
set
(
'configdata'
,
$configdata
);
$bi
->
commit
();
}
}
}
htdocs/import/leap/lib.php
View file @
abc25e8a
...
@@ -24,10 +24,10 @@ class PluginImportLeap extends PluginImport {
...
@@ -24,10 +24,10 @@ class PluginImportLeap extends PluginImport {
private
$strategylisting
=
array
();
private
$strategylisting
=
array
();
private
$loadmapping
=
array
();
private
$loadmapping
=
array
();
private
$coreloadmapping
=
array
();
private
$coreloadmapping
=
array
();
p
rivate
$artefactids
=
array
();
p
ublic
$artefactids
=
array
();
p
rivate
$viewids
=
array
();
p
ublic
$viewids
=
array
();
p
rivate
$collectionids
=
array
();
p
ublic
$collectionids
=
array
();
p
rivate
$collectionviewentries
=
array
();
p
ublic
$collectionviewentries
=
array
();
protected
$filename
;
protected
$filename
;
protected
$persondataid
=
null
;
protected
$persondataid
=
null
;
...
@@ -337,8 +337,12 @@ class PluginImportLeap extends PluginImport {
...
@@ -337,8 +337,12 @@ class PluginImportLeap extends PluginImport {
}
}
}
}
}
}
// Allow each plugin to load relationships to views if they need to
// Allow each
artefact
plugin to load relationships to views if they need to
$this
->
call_import_method_plugins
(
'setup_view_relationships_from_requests'
);
$this
->
call_import_method_plugins
(
'setup_view_relationships_from_requests'
);
// Allow each blocktype plugin to load relationships to views if they need to
$this
->
rewrite_blockinstance_relationships
();
$this
->
import_completed
();
$this
->
import_completed
();
$this
->
delete_import_entry_requests
();
$this
->
delete_import_entry_requests
();
...
@@ -742,6 +746,9 @@ class PluginImportLeap extends PluginImport {
...
@@ -742,6 +746,9 @@ class PluginImportLeap extends PluginImport {
$entry
,
$this
,
$strategydata
[
'strategy'
],
$strategydata
[
'other_required_entries'
]);
$entry
,
$this
,
$strategydata
[
'strategy'
],
$strategydata
[
'other_required_entries'
]);
}
}
}
}
// Allow each blocktype plugin to load relationships to views if they need to
$this
->
rewrite_blockinstance_relationships
();
}
}
public
function
entry_has_strategy
(
$entryid
,
$strategyid
,
$artefactplugin
=
null
)
{
public
function
entry_has_strategy
(
$entryid
,
$strategyid
,
$artefactplugin
=
null
)
{
...
@@ -1510,6 +1517,29 @@ class PluginImportLeap extends PluginImport {
...
@@ -1510,6 +1517,29 @@ class PluginImportLeap extends PluginImport {
return
$config
;
return
$config
;
}
}
/**
* This method is called late in the import process, after views, collections, and artefacts have been set up, to give collections the opportunity
* to rewrite any references they have to old view, collection, or artefact IDs.
*
* Blocktypes that use this API should define an "import_rewrite_blockinstance_relationships_leap" method.
*/
private
function
rewrite_blockinstance_relationships
()
{
foreach
(
$this
->
viewids
as
$entryid
=>
$viewid
)
{
$records
=
get_records_array
(
'block_instance'
,
'view'
,
$viewid
,
'view, id'
);
if
(
$records
)
{
foreach
(
$records
as
$blockrec
)
{
// Let blocktype plugin rewrite relationships now that all views and collections are set up
safe_require
(
'blocktype'
,
$blockrec
->
blocktype
);
$classname
=
generate_class_name
(
'blocktype'
,
$blockrec
->
blocktype
);
$method
=
'import_rewrite_blockinstance_relationships_leap'
;
$blockinstance
[
'config'
]
=
call_static_method
(
$classname
,
$method
,
$blockrec
->
id
,
$this
);
}
}
}
}
/**
/**
* Given an artefact record, looks through it for any Leap2A style
* Given an artefact record, looks through it for any Leap2A style
* references to other artefacts, and rewrite those to point at the created
* references to other artefacts, and rewrite those to point at the created
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment