示例#1
0
function archive_store_file(&$file, &$sheet)
{
    if (!is_dir($GLOBALS['cfg']['import_archive_root'])) {
        return array('ok' => 0, 'error' => 'archive root is not a directory');
    }
    $archived_path = archive_path_for_sheet($sheet);
    $dirname = dirname($archived_path);
    $ok = 1;
    if (!file_exists($dirname)) {
        if (!mkdir($dirname, 0700, true)) {
            return array('ok' => 0, 'error' => 'failed to create root dir');
        }
    }
    if (!copy($file['path'], $archived_path)) {
        return array('ok' => 0, 'error' => 'failed to copy file');
    }
    return array('ok' => 1, 'path' => $archived_path);
}
示例#2
0
function sheets_delete_sheet(&$sheet)
{
    #
    # Figure out where the sheet is stored
    #
    loadlib("archive");
    $archive_path = archive_path_for_sheet($sheet);
    #
    export_cache_purge_sheet($sheet);
    #
    # Purge search
    #
    dots_search_remove_sheet($sheet);
    dots_search_extras_remove_sheet($sheet);
    #
    # Okay, go
    #
    $user = users_get_by_id($sheet['user_id']);
    $enc_id = AddSlashes($sheet['id']);
    $sql = "SELECT * FROM Dots WHERE sheet_id='{$enc_id}'";
    $more = array('page' => 1, 'per_page' => 1000);
    $page_count = null;
    $total_count = null;
    $dots_deleted = 0;
    while (!isset($page_count) || $page_count >= $more['page']) {
        $rsp = db_fetch_paginated_users($user['cluster_id'], $sql, $more);
        if (!$rsp['ok']) {
            $rsp['dots_deleted'] = $dots_deleted;
            $rsp['dots_count'] = $total_count;
            return $rsp;
        }
        if (!isset($page_count)) {
            $page_count = $rsp['pagination']['page_count'];
            $total_count = $rsp['pagination']['total_count'];
        }
        foreach ($rsp['rows'] as $dot) {
            $dot_more = array('skip_update_sheet' => 1, 'skip_update_search' => 1);
            $dot_rsp = dots_delete_dot($dot, $dot_more);
            if ($dot_rsp['ok']) {
                $dots_deleted++;
            }
        }
        $more['page']++;
    }
    $sql = "DELETE FROM Sheets WHERE id='{$enc_id}'";
    $rsp = db_write_users($user['cluster_id'], $sql);
    # Dot specific caches are purged above when we call
    # dots_delete_dot.
    $cache_keys = array("sheet_{$sheet['id']}", "sheets_counts_for_user_{$sheet['user_id']}", "sheets_counts_for_user_{$sheet['user_id']}_public");
    foreach ($cache_keys as $key) {
        cache_unset($key);
    }
    #
    # Update the lookup table
    #
    $update = array('deleted' => time());
    $lookup_rsp = sheets_lookup_update($sheet, $update);
    if (!$lookup_rsp['ok']) {
        # what?
    }
    #
    # Remove the upload (if any)
    #
    if (file_exists($archive_path)) {
        $ok = unlink($archive_path);
        # if not $ok then what?
    }
    # Remove any cache exports
    export_cache_purge_sheet($sheet);
    #
    # Happy happy!
    #
    $rsp['dots_deleted'] = $dots_deleted;
    $rsp['dots_count'] = $total_count;
    return $rsp;
}