Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

update_archive_status()

Description

Update the archive state of resource(s) and log this

Parameters

ColumnTypeDefaultDescription
$resource
$archive integer - Destination archive state
$existingstates integer|array array - existing archive state _or_ array of corresponding existing archive states
$collection integer 0 - optional id of collection containing resources
$resource_id integer|array - Resource unique ref -or- array of Resource refs

Return

void

Location

include/resource_functions.php lines 5967 to 6041

Definition

 
function update_archive_status($resource$archive$existingstates = array(), $collection  0)
    {
    global 
$userref$user_resources_approved_email;

    if(!
is_array($resource))
        {
        
$resource = array($resource);
        }

    if(!
is_array($existingstates))
        {
        
$existingstates = array($existingstates);
        }

    
$count count($resource);

    for(
$n 0$n $count$n++)
        {
        if(!
is_numeric($resource[$n]))
            {
            continue;
            }

        
resource_log($resource[$n], LOG_CODE_STATUS_CHANGED0'', isset($existingstates[$n]) ? $existingstates[$n] : ''$archive);    
        }

    
# Prevent any attempt to update with non-numeric archive state
    
if (!is_numeric($archive))
        {
        
debug("update_archive_status FAILED - resources=(" implode(",",$resource) . "), archive: " $archive ", existingstates:(" implode(",",$existingstates) . "), collection: " $collection);
        return;
        }

    
sql_query("UPDATE resource SET archive = '" escape_check($archive) .  "' WHERE ref IN ('" implode("', '"$resource) . "')");
    
hook('after_update_archive_status''', array($resource$archive,$existingstates));
    
// Send notifications
    
debug("update_archive_status - resources=(" implode(",",$resource) . "), archive: " $archive ", existingstates:(" implode(",",$existingstates) . "), collection: " $collection);
    switch (
$archive)
        {
        case 
'0':
            if (isset(
$existingstates[0]) && $existingstates[0] == -&& $user_resources_approved_email)
                {
                
notify_user_resources_approved($resource);
                
# Clear any outstanding notifications relating to submission of these resources
                
message_remove_related(SUBMITTED_RESOURCE,$resource);
                if(
$collection != 0)
                    {
                    
message_remove_related(SUBMITTED_COLLECTION,$collection);
                    }
                }
            break;
        
        case 
'-1':
            if (isset(
$existingstates[0]) && $existingstates[0] == -2)
                {
                
notify_user_contributed_submitted($resource$collection);
                }
            break;
    
        case 
'-2':
            if (isset(
$existingstates[0]) && $existingstates[0] == -1)
                {
                
notify_user_contributed_unsubmitted($resource);
                }
            
# Clear any outstanding notifications relating to submission of these resources
            
message_remove_related(SUBMITTED_RESOURCE,$resource);
            if(
$collection != 0)
                {
                
message_remove_related(SUBMITTED_COLLECTION,$collection);
                }
            break;
        }
    
    return;
    }

This article was last updated 30th November 2020 16:05 Europe/London time based on the source file dated 30th November 2020 11:55 Europe/London time.