Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource 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 2890 to 2923

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 29th April 2024 19:35 Europe/London time based on the source file dated 15th April 2024 11:30 Europe/London time.