Skip to content
Snippets Groups Projects
Select Git revision
  • da47cc8cb0c3704537eaa94c2765ba10afc08d48
  • main default protected
  • dev protected
  • f-linkahead-rename
  • f-real-id
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-filesystem-main
  • f-name
  • keep_changes
  • f-permission-checks-2
  • f-mysql8-tests
  • f-retrieve-history
  • t-distinct-parents
  • v8.1.0
  • v8.0.0
  • v7.0.2
  • v7.0.1
  • v7.0.0
  • v6.0.1
  • v6.0.0
  • v5.0.0
  • v4.1.0
  • v4.0.0
  • v3.0
  • v2.0.30
29 results

setFileProperties.sql

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    setFileProperties.sql 2.34 KiB
    /*
     * This file is a part of the CaosDB Project.
     *
     * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
     * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Affero General Public License as
     * published by the Free Software Foundation, either version 3 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU Affero General Public License for more details.
     *
     * You should have received a copy of the GNU Affero General Public License
     * along with this program. If not, see <https://www.gnu.org/licenses/>.
     */
    
    DROP PROCEDURE IF EXISTS setFileProperties;
    DELIMITER //
    /**
     * Update file properties.
     *
     * If ENTITY_VERSIONING is enabled the old file properties are moved to
     * `archive_files`.
     *
     * Parameters
     * ----------
     * EntityID : VARCHAR(255)
     *   The file's id.
     * FilePath : TEXT
     *   Path of the file in the internal file system.  If NULL, an existing file
     *   entity is simply deleted.
     * FileSize : BIGINT UNSIGNED
     *   Size of the file in bytes.
     * FileHash : VARCHAR(255)
     *   A Sha512 Hash of the file.
     */
    CREATE PROCEDURE setFileProperties (
        in EntityID VARCHAR(255),
        in FilePath TEXT,
        in FileSize BIGINT UNSIGNED,
        in FileHash VARCHAR(255)
    )
    BEGIN
        DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
        DECLARE IVersion INT UNSIGNED DEFAULT NULL;
    
        SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
    
        IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
            SELECT max(e._iversion) INTO IVersion
                FROM entity_version AS e
                WHERE e.entity_id = InternalEntityID;
    
            INSERT INTO archive_files (file_id, path, size, hash,
                    _iversion)
                SELECT file_id, path, size, hash, IVersion AS _iversion
                FROM files
                WHERE file_id = InternalEntityID;
        END IF;
    
        DELETE FROM files WHERE file_id = InternalEntityID;
    
        IF FilePath IS NOT NULL THEN
            INSERT INTO files (file_id, path, size, hash)
                VALUES (InternalEntityID, FilePath, FileSize, unhex(FileHash));
        END IF;
    
    END //
    DELIMITER ;