Example #1
0
/**
 * Determine if a given log record has a log present on the filesystem (handles both archived and non-archive logs).
 *
 * @uses $DB
 * @param object|integer $logorid The log record from the DB or the record ID to detect a file for
 * @return boolean True if a viable file exists, False otherwise
 */
function rlip_log_file_exists($logorid)
{
    global $DB;
    // Check whether a record or record ID was passed in, also return false if neither was specified
    if (is_integer($logorid)) {
        $log = $DB->get_record(RLIP_LOG_TABLE, array('id' => $logorid));
    } else {
        if (is_object($logorid)) {
            $log = $logorid;
        } else {
            return false;
        }
    }
    // Check if the log file still exists on the filesystem
    if (!empty($log->logpath) && file_exists($log->logpath)) {
        return true;
    }
    // Check if a zip archive exists for the date the job was started on
    $archivelog = rlip_get_archive_log_filename($log);
    if (!empty($archivelog) && file_exists($archivelog)) {
        return true;
    }
    return false;
}
Example #2
0
require_once $CFG->dirroot . '/local/datahub/lib.php';
require_once $CFG->dirroot . '/local/datahub/lib/rlip_fileplugin.class.php';
$file = get_plugin_directory('dhfile', 'log') . '/log.class.php';
require_once $file;
$id = required_param('id', PARAM_INT);
if (!($log = $DB->get_record(RLIP_LOG_TABLE, array('id' => $id)))) {
    print_error('filenotfound', 'error', $CFG->wwwroot . '/');
}
$logfilename = '';
// Check if the log file still exists on the filesystem
if (!empty($log->logpath) && file_exists($log->logpath)) {
    $logfilename = $log->logpath;
}
// Check if a zip archive exists for the date the job was started on
if ($logfilename == '') {
    $archivelog = rlip_get_archive_log_filename($log);
    //error_log("download.php: checking for log archive: {$archivelog}");
    if (!empty($archivelog) && file_exists($archivelog)) {
        // Create a directory for temporary unzipping the log archive
        do {
            $path = $CFG->dataroot . '/temp/dh_download' . mt_rand(0, 9999999);
        } while (file_exists($path));
        check_dir_exists($path);
        // Unzip the log archive file
        $fp = get_file_packer('application/zip');
        if (!$fp->extract_to_pathname($archivelog, $path)) {
            @remove_dir($path);
        } else {
            // Look for to see if the specific file we want exists in the unarchive zip file
            $logfilename = $path . '/' . basename($log->logpath);
            if (!file_exists($logfilename)) {