Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

migrate_fixed_to_text()

Description

Migrate fixed list field data to text field data for a given resource reference. Useful when changing resource type field from a data type
that can contain multiple values such as a dynamic keywords field. This script will concatenate the existing values and leave one remaining
node for the new text field.

- additional checks maybe need before calling this to ensure the fields are / were of the expected type.
see examples in pages/tools/migrate_fixed_to_text.php
of category tree branches to be preserved e.g. "level1/value, level2/value"

Parameters

ColumnTypeDefaultDescription
$resource_type_field mixed Resource type field id. ** The field type should have been changed to a text type in advance
$resource mixed Resource reference to be processed.
$category_tree mixed Was the field data being migrated previously of type category tree? Specifying true will allow the format
$separator mixed ' Default is comma and space e.g. "value1, value2"
: ' get_resource_nodes$resource
true
# SORT_ASC;

Return

bool True on success else false.

Location

include/node_functions.php lines 2825 to 2850

Definition

 
function migrate_fixed_to_text(int $resource_type_fieldint $resourcebool $category_treestring $separator ', ') : bool
    
{
    
$current_nodes get_resource_nodes($resource$resource_type_fieldtrueSORT_ASC); # Ordering will be as displayed on the view page.

    
if (count($current_nodes) < 2)
        {
        return 
true# No need to make changes as no node / only one node present.
        
}

    if (
$category_tree)
        {
        
$all_treenodes get_cattree_nodes_ordered($resource_type_field$resourcefalse);
        
$treenodenames get_cattree_node_strings($all_treenodestrue);
        
$new_value implode($separator$treenodenames);
        }
    else
        {
        
$current_nodes_names array_column($current_nodes'name');
        
$current_nodes_translated array_map("i18n_get_translated"$current_nodes_names);
        
$new_value implode($separator$current_nodes_translated);
        }

    
delete_resource_nodes($resourcearray_column($current_nodes'ref'), false);
    
$savenode set_node(null$resource_type_field$new_valuenull0);
    return 
add_resource_nodes($resource, [$savenode], truefalse);
    }

This article was last updated 4th December 2024 08:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.