Beispiel #1
0
<?php

elgg_admin_gatekeeper();
$guid = (int) get_input('guid');
$entity = get_entity($guid);
if (!elgg_instanceof($entity, 'object', 'profile_sync_config')) {
    return;
}
$files = profile_sync_get_ordered_log_files($entity);
if (empty($files)) {
    echo elgg_echo('notfound');
    return;
}
$head = elgg_format_element('th', [], elgg_echo('profile_sync:interval:date'));
$head .= elgg_format_element('th', [], '&nbsp;');
$table = elgg_format_element('tr', [], $head);
foreach ($files as $file => $datetime) {
    $row_data = elgg_format_element('td', [], $datetime);
    $row_data .= elgg_format_element('td', [], elgg_view('output/url', ['text' => elgg_echo('show'), 'href' => 'ajax/view/profile_sync/view_log?guid=' . $entity->getGUID() . '&file=' . $file, 'is_trusted' => true, 'class' => 'elgg-lightbox']));
    $table .= elgg_format_element('tr', [], $row_data);
}
$content = elgg_format_element('table', ['class' => 'elgg-table-alt'], $table);
echo elgg_view_module('inline', elgg_echo('profile_sync:sync_logs:title', [$entity->title]), $content, ['class' => 'profile-sync-logs-wrapper']);
Beispiel #2
0
/**
 * Cleanup the oldes logfiles of a sync config, based of the settings of the sync config
 *
 * @param ElggObject $sync_config the sync config to cleanup the logs for
 *
 * @return bool
 */
function profile_sync_cleanup_logs(ElggObject $sync_config)
{
    if (!elgg_instanceof($sync_config, 'object', 'profile_sync_config')) {
        return false;
    }
    $log_cleanup_count = sanitise_int($sync_config->log_cleanup_count, false);
    if (empty($log_cleanup_count)) {
        return true;
    }
    $log_files = profile_sync_get_ordered_log_files($sync_config, false);
    if (empty($log_files) || count($log_files) < $log_cleanup_count) {
        return true;
    }
    $to_be_removed = array_slice($log_files, $log_cleanup_count);
    if (empty($to_be_removed)) {
        return true;
    }
    $fh = new ElggFile();
    $fh->owner_guid = $sync_config->getGUID();
    $result = true;
    foreach ($to_be_removed as $filename) {
        $fh->setFilename($filename);
        if (!$fh->exists()) {
            continue;
        }
        $result = $result & $fh->delete();
    }
    return $result;
}