1515from . import schemas
1616from opengeodeweb_microservice .database .data import Data
1717from opengeodeweb_microservice .database .connection import get_session
18+ from opengeodeweb_microservice .database import connection
1819
1920routes = flask .Blueprint ("routes" , __name__ , url_prefix = "/opengeodeweb_back" )
2021
@@ -336,6 +337,14 @@ def import_project() -> flask.Response:
336337 flask .abort (400 , "Uploaded file must be a .zip" )
337338
338339 data_folder_path : str = flask .current_app .config ["DATA_FOLDER_PATH" ]
340+
341+ # 423 Locked bypass : remove stopped requests
342+ if connection .scoped_session_registry :
343+ connection .scoped_session_registry .remove ()
344+ if connection .engine :
345+ connection .engine .dispose ()
346+ connection .engine = connection .session_factory = connection .scoped_session_registry = None
347+
339348 try :
340349 if os .path .exists (data_folder_path ):
341350 shutil .rmtree (data_folder_path )
@@ -360,11 +369,37 @@ def import_project() -> flask.Response:
360369 if not os .path .isfile (database_root_path ):
361370 flask .abort (400 , "Missing project.db at project root" )
362371
372+ # Reset database to the imported project.db
373+ connection .init_database (database_root_path , create_tables = False )
374+
375+ with get_session () as session :
376+ for data_entry in session .query (Data ).all ():
377+ data_path = geode_functions .data_file_path (data_entry .id )
378+
379+ viewable_name = data_entry .viewable_file_name
380+ if viewable_name :
381+ vpath = geode_functions .data_file_path (data_entry .id , viewable_name )
382+ if os .path .isfile (vpath ):
383+ continue
384+
385+ input_file = str (data_entry .input_file or "" )
386+ if not input_file :
387+ continue
388+
389+ input_full = geode_functions .data_file_path (data_entry .id , input_file )
390+ if not os .path .isfile (input_full ):
391+ continue
392+
393+ data_object = geode_functions .load (data_entry .geode_object , input_full )
394+ utils_functions .save_all_viewables_and_return_info (
395+ data_entry .geode_object , data_object , data_entry , data_path
396+ )
397+ session .commit ()
398+
363399 snapshot = {}
364400 try :
365401 raw = zip_archive .read ("snapshot.json" ).decode ("utf-8" )
366402 snapshot = flask .json .loads (raw )
367403 except KeyError :
368404 snapshot = {}
369-
370405 return flask .make_response ({"snapshot" : snapshot }, 200 )
0 commit comments