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

update_node_active_state()

Description

Batch update nodes' active state to the database. The same state will apply to all nodes in the list.

For logic on which nodes to toggle {@see toggle_active_state_for_nodes()}

Parameters

ColumnTypeDefaultDescription
$refs list Node IDs
$active: bool
$active bool Should nodes be active or not?

Location

include/node_functions.php lines 2934 to 2967

Definition

 
function update_node_active_state(array $refsbool $active): void
    
{
    if (
$refs === []) {
        return;
    }

    
$refs_chunked db_chunk_id_list($refs);
    if (
$refs_chunked === []) {
        return;
    }

    
db_begin_transaction('set_node_active_state');

    foreach (
$refs_chunked as $refs_chunk) {
        
ps_query(
            
sprintf(
                   
'UPDATE node AS n
                INNER JOIN resource_type_field AS rtf ON n.resource_type_field = rtf.ref
                       SET n.`active` = ?
                     WHERE n.`ref` IN (%s)
                       AND rtf.`type` IN (%s)'
,
                
ps_param_insert(count($refs_chunk)),
                
ps_param_insert(count($GLOBALS['FIXED_LIST_FIELD_TYPES']))
            ),
            
array_merge(
                [
'i'$active],
                
ps_param_fill($refs_chunk'i'),
                
ps_param_fill($GLOBALS['FIXED_LIST_FIELD_TYPES'], 'i')
            )
        );
    }

    
db_end_transaction('set_node_active_state');
    }

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.