3232
3333use  OCA \Cloud_Py_API \Db \SettingMapper ;
3434use  OCP \AppFramework \Db \DoesNotExistException ;
35+ use  OCP \ITempManager ;
3536
3637class  PythonService {
37- 	/** @var string */ 
38- 	private  $ pythonCommand
39- 
40- 	/** @var string */ 
41- 	private  $ ncInstanceId
42- 
43- 	/** @var string */ 
44- 	private  $ ncDataFolder
45- 
46- 	/** @var UtilsService */ 
47- 	private  $ utils
38+ 	private  string  $ pythonCommand
39+ 	private  string  $ ncInstanceId
40+ 	private  string  $ ncDataFolder
41+ 	private  bool  $ isObjectStorage
4842
4943	public  function  __construct (
50- 		IConfig $ config
44+ 		private   readonly   IConfig $ config
5145		SettingMapper $ settingMapper
52- 		UtilsService $ utils
46+ 		private  readonly  UtilsService $ utils
47+ 		private  readonly  ITempManager $ tempManager
5348	) {
5449		try  {
5550			$ pythonCommand$ settingMapperfindByName ('python_command ' );
5651			$ this pythonCommand  = $ pythonCommandgetValue ();
5752		} catch  (DoesNotExistException $ e
5853			$ this pythonCommand  = '/usr/bin/python3 ' ;
5954		}
60- 		$ this utils  = $ utils 
61- 		$ this ncInstanceId  = $ configgetSystemValue ('instanceid ' );
62- 		$ this ncDataFolder  = $ configgetSystemValue ('datadirectory '  ) ;
55+ 		$ this ncInstanceId  = $ this -> config -> getSystemValue ( ' instanceid ' ) ;
56+ 		$ this ncDataFolder  = $ this -> config ->getSystemValue ('datadirectory ' );
57+ 		$ this isObjectStorage  = $ this -> config ->getSystemValue ('objectstore '  ,  null ) !==  null ;
6358	}
6459
6560	/** 
@@ -84,10 +79,14 @@ public function run(
8479			array  $ scriptParams
8580			bool  $ nonBlockingfalse ,
8681			array  $ env
87- 			bool  $ binaryfalse 
82+ 			bool  $ binaryfalse , 
8883	) {
8984		if  ($ binary
90- 			$ cwd$ this ncDataFolder  . '/appdata_ '  . $ this ncInstanceId  . '/ '  . $ appId'/ ' ;
85+ 			if  ($ this isObjectStorage ) {
86+ 				$ cwd'' ; // scriptName should already include absolute path (/tmp/...) 
87+ 			} else  {
88+ 				$ cwd$ this ncDataFolder  . '/appdata_ '  . $ this ncInstanceId  . '/ '  . $ appId'/ ' ;
89+ 			}
9190		} else  {
9291			$ cwd$ this utils ->getCustomAppsDirectory () . $ appId'/ ' ;
9392		}
@@ -111,7 +110,15 @@ public function run(
111110		}
112111		if  ($ nonBlocking
113112			if  ($ binary
114- 				$ logFile$ cwd'logs/ '  . date ('d-m-Y_H-i-s ' , time ()) . '.log ' ;
113+ 				if  (!$ this isObjectStorage ) {
114+ 					$ logFile$ cwd'logs/ '  . date ('d-m-Y_H-i-s ' , time ()) . '.log ' ;
115+ 				} else  {
116+ 					$ tempLogsDir$ this tempManager ->getTempBaseDir () . '/ '  . $ appId'/logs/ ' ;
117+ 					if  (!file_exists ($ tempLogsDir
118+ 						mkdir ($ tempLogsDir0700 , true );
119+ 					}
120+ 					$ logFile$ tempLogsDir$ appId'_ '  . date ('d-m-Y_H-i-s ' , time ()) . '.log ' ;
121+ 				}
115122			} else  {
116123				$ appDataDir$ this ncDataFolder  . '/appdata_ '  . $ this ncInstanceId  . '/ '  . $ appId'/ ' ;
117124				$ pyBitecodeEnvVar'PYTHONBYTECODEBASE=" '  . $ appDataDir'"  ' ;
0 commit comments