Commit 2725e46f authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added 'node_id' and 'phy_deleted_on' fields + added 'setPhyDeletedOn()' method.

parent 362dbd01
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -129,12 +129,12 @@ class DbConnector(object):
                cursor = conn.cursor(cursor_factory = RealDictCursor)
                cursor.execute("""
                    WITH all_nodes AS (
                        SELECT name, os_name, node_id, parent_path, path, relative_path, owner_id, location_id, null as deleted_on FROM node
                        SELECT name, os_name, node_id, parent_path, path, relative_path, owner_id, location_id, null as deleted_on, null as phy_deleted_on FROM node
                        UNION
                        SELECT name, os_name, node_id, parent_path, path(parent_path, node_id) AS path, path(parent_relative_path, node_id) AS relative_path, owner_id, location_id, deleted_on 
                        SELECT name, os_name, node_id, parent_path, path(parent_path, node_id) AS path, path(parent_relative_path, node_id) AS relative_path, owner_id, location_id, deleted_on, phy_deleted_on 
                        FROM deleted_node
                    )
                    SELECT base_path || '/' || owner_id as os_base_path, os_path AS os_rel_path, an.deleted_on 
                    SELECT an.node_id, base_path || '/' || owner_id as os_base_path, os_path AS os_rel_path, an.deleted_on, an.phy_deleted_on 
                    FROM (
                        SELECT node_id, '/' || string_agg(name, '/') AS os_path
                        FROM (
@@ -701,6 +701,22 @@ class DbConnector(object):
                if not conn.closed:
                    conn.rollback()
                    
    def setPhyDeletedOn(self, nodeId):
        """Sets the 'phy_deleted_on' flag for a VOSpace deleted node."""
        with self.getConnection() as conn:
            try:
                cursor = conn.cursor(cursor_factory = RealDictCursor)
                phyDeletedOn = datetime.datetime.now().isoformat()
                cursor.execute("""
                    UPDATE deleted_node SET phy_deleted_on = %s
                    WHERE node_id = %s;
                    """,
                    (phyDeletedOn, nodeId,))
                conn.commit()
            except Exception as e:
                if not conn.closed:
                    conn.rollback()        

    ##### Storage #####

    def insertStorage(self, storageType, basePath, baseUrl, hostname):