Exemplo n.º 1
0
/**
 * Disables metadata based on $options.
 *
 * @warning Unlike elgg_get_metadata() this will not accept an empty options array!
 *
 * @warning This returns null on no ops.
 *
 * @param array $options An options array. {@See elgg_get_metadata()}
 * @return mixed
 * @since 1.8.0
 */
function elgg_disable_metadata(array $options)
{
    if (!elgg_is_valid_options_for_batch_operation($options, 'metadata')) {
        return false;
    }
    $options['metastring_type'] = 'metadata';
    return elgg_batch_metastring_based_objects($options, 'elgg_batch_disable_callback', false);
}
Exemplo n.º 2
0
 public function testKeepMeFromDeletingEverything()
 {
     foreach ($this->metastringTypes as $type) {
         $required = array('guid', 'guids', 'limit');
         switch ($type) {
             case 'metadata':
                 $metadata_required = array('metadata_owner_guid', 'metadata_owner_guids', 'metadata_name', 'metadata_names', 'metadata_value', 'metadata_values');
                 $required = array_merge($required, $metadata_required);
                 break;
             case 'annotations':
                 $annotations_required = array('annotation_owner_guid', 'annotation_owner_guids', 'annotation_name', 'annotation_names', 'annotation_value', 'annotation_values');
                 $required = array_merge($required, $annotations_required);
                 break;
         }
         $options = array();
         $this->assertFalse(elgg_is_valid_options_for_batch_operation($options), $type);
         foreach ($required as $key) {
             $options = array();
             $options[$key] = ELGG_ENTITIES_ANY_VALUE;
             $this->assertFalse(elgg_is_valid_options_for_batch_operation($options, $type), "Sent {$key} = ELGG_ENTITIES_ANY_VALUE");
             $options[$key] = ELGG_ENTITIES_NO_VALUE;
             $this->assertFalse(elgg_is_valid_options_for_batch_operation($options, $type), "Sent {$key} = ELGG_ENTITIES_NO_VALUE");
             $options[$key] = false;
             $this->assertFalse(elgg_is_valid_options_for_batch_operation($options, $type), "Sent {$key} = bool false");
             $options[$key] = true;
             $this->assertTrue(elgg_is_valid_options_for_batch_operation($options, $type), "Sent {$key} = bool true");
             $options[$key] = 'test';
             $this->assertTrue(elgg_is_valid_options_for_batch_operation($options, $type), "Sent {$key} = 'test'");
             $options[$key] = array('test');
             $this->assertTrue(elgg_is_valid_options_for_batch_operation($options, $type), "Sent {$key} = array('test')");
         }
     }
 }
Exemplo n.º 3
0
/**
 * Disables metadata based on $options.
 *
 * @warning Unlike elgg_get_metadata() this will not accept an empty options array!
 *
 * @warning This returns null on no ops.
 *
 * @param array $options An options array. {@See elgg_get_metadata()}
 * @return mixed
 * @since 1.8.0
 */
function elgg_disable_metadata(array $options)
{
    if (!elgg_is_valid_options_for_batch_operation($options, 'metadata')) {
        return false;
    }
    elgg_get_metadata_cache()->invalidateByOptions('disable', $options);
    $options['metastring_type'] = 'metadata';
    return elgg_batch_metastring_based_objects($options, 'elgg_batch_disable_callback', false);
}
Exemplo n.º 4
0
/**
 * Disables annotations based on $options.
 *
 * @warning Unlike elgg_get_annotations() this will not accept an empty options array!
 *
 * @param array $options An options array. {@See elgg_get_annotations()}
 * @return mixed
 * @since 1.8.0
 */
function elgg_disable_annotations(array $options)
{
    if (!elgg_is_valid_options_for_batch_operation($options, 'annotations')) {
        return false;
    }
    $options['metastrings_type'] = 'annotations';
    return elgg_batch_metastring_based_objects($options, 'elgg_batch_disable_callback');
}
Exemplo n.º 5
0
/**
 * Disables metadata based on $options.
 *
 * @warning Unlike elgg_get_metadata() this will not accept an empty options array!
 *
 * @param array $options An options array. {@See elgg_get_metadata()}
 * @return bool|null true on success, false on failure, null if no metadata disabled.
 * @since 1.8.0
 */
function elgg_disable_metadata(array $options)
{
    if (!elgg_is_valid_options_for_batch_operation($options, 'metadata')) {
        return false;
    }
    elgg_get_metadata_cache()->invalidateByOptions('disable', $options);
    // if we can see hidden (disabled) we need to use the offset
    // otherwise we risk an infinite loop if there are more than 50
    $inc_offset = access_get_show_hidden_status();
    $options['metastring_type'] = 'metadata';
    return elgg_batch_metastring_based_objects($options, 'elgg_batch_disable_callback', $inc_offset);
}