runtimeenv.class.inc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Manage a runtime environment
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. require_once(APPROOT."setup/modulediscovery.class.inc.php");
  25. require_once(APPROOT.'setup/modelfactory.class.inc.php');
  26. require_once(APPROOT.'setup/compiler.class.inc.php');
  27. require_once(APPROOT.'core/metamodel.class.php');
  28. define ('MODULE_ACTION_OPTIONAL', 1);
  29. define ('MODULE_ACTION_MANDATORY', 2);
  30. define ('MODULE_ACTION_IMPOSSIBLE', 3);
  31. define ('ROOT_MODULE', '_Root_'); // Convention to store IN MEMORY the name/version of the root module i.e. application
  32. define ('DATAMODEL_MODULE', 'datamodel'); // Convention to store the version of the datamodel
  33. class RunTimeEnvironment
  34. {
  35. protected $sTargetEnv;
  36. public function __construct($sEnvironment = 'production')
  37. {
  38. $this->sTargetEnv = $sEnvironment;
  39. }
  40. /**
  41. * Helper function to initialize the ORM and load the data model
  42. * from the given file
  43. * @param $oConfig object The configuration (volatile, not necessarily already on disk)
  44. * @param $bModelOnly boolean Whether or not to allow loading a data model with no corresponding DB
  45. * @return none
  46. */
  47. public function InitDataModel($oConfig, $bModelOnly = true, $bUseCache = false)
  48. {
  49. require_once(APPROOT.'/core/log.class.inc.php');
  50. require_once(APPROOT.'/core/kpi.class.inc.php');
  51. require_once(APPROOT.'/core/coreexception.class.inc.php');
  52. require_once(APPROOT.'/core/dict.class.inc.php');
  53. require_once(APPROOT.'/core/attributedef.class.inc.php');
  54. require_once(APPROOT.'/core/filterdef.class.inc.php');
  55. require_once(APPROOT.'/core/stimulus.class.inc.php');
  56. require_once(APPROOT.'/core/MyHelpers.class.inc.php');
  57. require_once(APPROOT.'/core/expression.class.inc.php');
  58. require_once(APPROOT.'/core/cmdbsource.class.inc.php');
  59. require_once(APPROOT.'/core/sqlquery.class.inc.php');
  60. require_once(APPROOT.'/core/dbobject.class.php');
  61. require_once(APPROOT.'/core/dbobjectsearch.class.php');
  62. require_once(APPROOT.'/core/dbobjectset.class.php');
  63. require_once(APPROOT.'/application/cmdbabstract.class.inc.php');
  64. require_once(APPROOT.'/core/userrights.class.inc.php');
  65. require_once(APPROOT.'/setup/moduleinstallation.class.inc.php');
  66. $sConfigFile = $oConfig->GetLoadedFile();
  67. if (strlen($sConfigFile) > 0)
  68. {
  69. $this->log_info("MetaModel::Startup from $sConfigFile (ModelOnly = $bModelOnly)");
  70. }
  71. else
  72. {
  73. $this->log_info("MetaModel::Startup (ModelOnly = $bModelOnly)");
  74. }
  75. if (!$bUseCache)
  76. {
  77. // Reset the cache for the first use !
  78. MetaModel::ResetCache(md5(APPROOT).'-'.$this->sTargetEnv);
  79. }
  80. MetaModel::Startup($oConfig, $bModelOnly, $bUseCache);
  81. }
  82. /**
  83. * Analyzes the current installation and the possibilities
  84. *
  85. * @param Config $oConfig Defines the target environment (DB)
  86. * @param mixed $modulesPath Either a single string or an array of absolute paths
  87. * @param bool $bAbortOnMissingDependency ...
  88. * @param hash $aModulesToLoad List of modules to search for, defaults to all if ommitted
  89. * @return hash Array with the following format:
  90. * array =>
  91. * 'iTop' => array(
  92. * 'version_db' => ... (could be empty in case of a fresh install)
  93. * 'version_code => ...
  94. * )
  95. * <module_name> => array(
  96. * 'version_db' => ...
  97. * 'version_code' => ...
  98. * 'install' => array(
  99. * 'flag' => SETUP_NEVER | SETUP_OPTIONAL | SETUP_MANDATORY
  100. * 'message' => ...
  101. * )
  102. * 'uninstall' => array(
  103. * 'flag' => SETUP_NEVER | SETUP_OPTIONAL | SETUP_MANDATORY
  104. * 'message' => ...
  105. * )
  106. * 'label' => ...
  107. * 'dependencies' => array(<module1>, <module2>, ...)
  108. * 'visible' => true | false
  109. * )
  110. * )
  111. */
  112. public function AnalyzeInstallation($oConfig, $modulesPath, $bAbortOnMissingDependency = false, $aModulesToLoad = null)
  113. {
  114. $aRes = array(
  115. ROOT_MODULE => array(
  116. 'version_db' => '',
  117. 'name_db' => '',
  118. 'version_code' => ITOP_VERSION.'.'.ITOP_REVISION,
  119. 'name_code' => ITOP_APPLICATION,
  120. )
  121. );
  122. $aDirs = is_array($modulesPath) ? $modulesPath : array($modulesPath);
  123. $aModules = ModuleDiscovery::GetAvailableModules($aDirs, $bAbortOnMissingDependency, $aModulesToLoad);
  124. foreach($aModules as $sModuleId => $aModuleInfo)
  125. {
  126. list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId);
  127. if ($sModuleName == '')
  128. {
  129. throw new Exception("Missing name for the module: '$sModuleId'");
  130. }
  131. if ($sModuleVersion == '')
  132. {
  133. // The version must not be empty (it will be used as a criteria to determine wether a module has been installed or not)
  134. //throw new Exception("Missing version for the module: '$sModuleId'");
  135. $sModuleVersion = '1.0.0';
  136. }
  137. $sModuleAppVersion = $aModuleInfo['itop_version'];
  138. $aModuleInfo['version_db'] = '';
  139. $aModuleInfo['version_code'] = $sModuleVersion;
  140. if (!in_array($sModuleAppVersion, array('1.0.0', '1.0.1', '1.0.2')))
  141. {
  142. // This module is NOT compatible with the current version
  143. $aModuleInfo['install'] = array(
  144. 'flag' => MODULE_ACTION_IMPOSSIBLE,
  145. 'message' => 'the module is not compatible with the current version of the application'
  146. );
  147. }
  148. elseif ($aModuleInfo['mandatory'])
  149. {
  150. $aModuleInfo['install'] = array(
  151. 'flag' => MODULE_ACTION_MANDATORY,
  152. 'message' => 'the module is part of the application'
  153. );
  154. }
  155. else
  156. {
  157. $aModuleInfo['install'] = array(
  158. 'flag' => MODULE_ACTION_OPTIONAL,
  159. 'message' => ''
  160. );
  161. }
  162. $aRes[$sModuleName] = $aModuleInfo;
  163. }
  164. try
  165. {
  166. require_once(APPROOT.'/core/cmdbsource.class.inc.php');
  167. CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName());
  168. CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation());
  169. $aSelectInstall = CMDBSource::QueryToArray("SELECT * FROM ".$oConfig->GetDBSubname()."priv_module_install");
  170. }
  171. catch (MySQLException $e)
  172. {
  173. // No database or erroneous information
  174. $aSelectInstall = array();
  175. }
  176. // Build the list of installed module (get the latest installation)
  177. //
  178. $aInstallByModule = array(); // array of <module> => array ('installed' => timestamp, 'version' => <version>)
  179. foreach ($aSelectInstall as $aInstall)
  180. {
  181. //$aInstall['comment']; // unsused
  182. $iInstalled = strtotime($aInstall['installed']);
  183. $sModuleName = $aInstall['name'];
  184. $sModuleVersion = $aInstall['version'];
  185. if ($sModuleVersion == '')
  186. {
  187. // Though the version cannot be empty in iTop 2.0, it used to be possible
  188. // therefore we have to put something here or the module will not be considered
  189. // as being installed
  190. $sModuleVersion = '0.0.0';
  191. }
  192. if ($aInstall['parent_id'] == 0)
  193. {
  194. $sModuleName = ROOT_MODULE;
  195. }
  196. if (array_key_exists($sModuleName, $aInstallByModule))
  197. {
  198. if ($iInstalled < $aInstallByModule[$sModuleName]['installed'])
  199. {
  200. continue;
  201. }
  202. }
  203. if ($aInstall['parent_id'] == 0)
  204. {
  205. $aRes[$sModuleName]['version_db'] = $sModuleVersion;
  206. $aRes[$sModuleName]['name_db'] = $aInstall['name'];
  207. }
  208. $aInstallByModule[$sModuleName]['installed'] = $iInstalled;
  209. $aInstallByModule[$sModuleName]['version'] = $sModuleVersion;
  210. }
  211. // Adjust the list of proposed modules
  212. //
  213. foreach ($aInstallByModule as $sModuleName => $aModuleDB)
  214. {
  215. if ($sModuleName == ROOT_MODULE) continue; // Skip the main module
  216. if (!array_key_exists($sModuleName, $aRes))
  217. {
  218. // A module was installed, it is not proposed in the new build... skip
  219. continue;
  220. }
  221. $aRes[$sModuleName]['version_db'] = $aModuleDB['version'];
  222. if ($aRes[$sModuleName]['install']['flag'] == MODULE_ACTION_MANDATORY)
  223. {
  224. $aRes[$sModuleName]['uninstall'] = array(
  225. 'flag' => MODULE_ACTION_IMPOSSIBLE,
  226. 'message' => 'the module is part of the application'
  227. );
  228. }
  229. else
  230. {
  231. $aRes[$sModuleName]['uninstall'] = array(
  232. 'flag' => MODULE_ACTION_OPTIONAL,
  233. 'message' => ''
  234. );
  235. }
  236. }
  237. return $aRes;
  238. }
  239. public function WriteConfigFileSafe($oConfig)
  240. {
  241. self::MakeDirSafe(APPCONF);
  242. self::MakeDirSafe(APPCONF.$this->sTargetEnv);
  243. $sTargetConfigFile = APPCONF.$this->sTargetEnv.'/'.ITOP_CONFIG_FILE;
  244. // Write the config file
  245. @chmod($sTargetConfigFile, 0770); // In case it exists: RWX for owner and group, nothing for others
  246. $oConfig->WriteToFile($sTargetConfigFile);
  247. @chmod($sTargetConfigFile, 0440); // Read-only for owner and group, nothing for others
  248. }
  249. /**
  250. * Get the installed modules (only the installed ones)
  251. */
  252. protected function GetMFModulesToCompile($sSourceEnv, $sSourceDir)
  253. {
  254. $sSourceDirFull = APPROOT.$sSourceDir;
  255. if (!is_dir($sSourceDirFull))
  256. {
  257. throw new Exception("The source directory '$sSourceDirFull' does not exist (or could not be read)");
  258. }
  259. $aDirsToCompile = array($sSourceDirFull);
  260. if (is_dir(APPROOT.'extensions'))
  261. {
  262. $aDirsToCompile[] = APPROOT.'extensions';
  263. }
  264. $aRet = array();
  265. // Determine the installed modules
  266. //
  267. $oSourceConfig = new Config(APPCONF.$sSourceEnv.'/'.ITOP_CONFIG_FILE);
  268. $oSourceEnv = new RunTimeEnvironment($sSourceEnv);
  269. $aAvailableModules = $oSourceEnv->AnalyzeInstallation($oSourceConfig, $aDirsToCompile);
  270. // Do load the required modules
  271. //
  272. $oFactory = new ModelFactory($aDirsToCompile);
  273. $aModules = $oFactory->FindModules();
  274. foreach($aModules as $foo => $oModule)
  275. {
  276. $sModule = $oModule->GetName();
  277. if (array_key_exists($sModule, $aAvailableModules))
  278. {
  279. if ($aAvailableModules[$sModule]['version_db'] != '')
  280. {
  281. $aRet[] = $oModule;
  282. }
  283. }
  284. }
  285. $sDeltaFile = APPROOT.'data/'.$this->sTargetEnv.'.delta.xml';
  286. if (file_exists($sDeltaFile))
  287. {
  288. $oDelta = new MFDeltaModule($sDeltaFile);
  289. $aRet[] = $oDelta;
  290. }
  291. return $aRet;
  292. }
  293. public function CompileFrom($sSourceEnv, $bUseSymLinks = false)
  294. {
  295. $oSourceConfig = new Config(utils::GetConfigFilePath($sSourceEnv));
  296. $sSourceDir = $oSourceConfig->Get('source_dir');
  297. $sSourceDirFull = APPROOT.$sSourceDir;
  298. // Do load the required modules
  299. //
  300. $oFactory = new ModelFactory($sSourceDirFull);
  301. foreach($this->GetMFModulesToCompile($sSourceEnv, $sSourceDir) as $oModule)
  302. {
  303. $sModule = $oModule->GetName();
  304. $oFactory->LoadModule($oModule);
  305. if ($oFactory->HasLoadErrors())
  306. {
  307. break;
  308. }
  309. }
  310. if ($oFactory->HasLoadErrors())
  311. {
  312. foreach($oFactory->GetLoadErrors() as $sModuleId => $aErrors)
  313. {
  314. echo "<h3>Module: ".$sModuleId."</h3>\n";
  315. foreach($aErrors as $oXmlError)
  316. {
  317. echo "<p>File: ".$oXmlError->file." Line:".$oXmlError->line." Message:".$oXmlError->message."</p>\n";
  318. }
  319. }
  320. }
  321. else
  322. {
  323. $oFactory->ApplyChanges();
  324. //$oFactory->Dump();
  325. $sTargetDir = APPROOT.'env-'.$this->sTargetEnv;
  326. self::MakeDirSafe($sTargetDir);
  327. $oMFCompiler = new MFCompiler($oFactory);
  328. $oMFCompiler->Compile($sTargetDir, null, $bUseSymLinks);
  329. require_once(APPROOT.'/core/dict.class.inc.php');
  330. MetaModel::ResetCache(md5(APPROOT).'-'.$this->sTargetEnv);
  331. }
  332. }
  333. /**
  334. * Helper function to create the database structure
  335. * @return boolean true on success, false otherwise
  336. */
  337. public function CreateDatabaseStructure(Config $oConfig, $sMode)
  338. {
  339. if (strlen($oConfig->GetDBSubname()) > 0)
  340. {
  341. $this->log_info("Creating the structure in '".$oConfig->GetDBName()."' (table names prefixed by '".$oConfig->GetDBSubname()."').");
  342. }
  343. else
  344. {
  345. $this->log_info("Creating the structure in '".$oConfig->GetDBSubname()."'.");
  346. }
  347. //MetaModel::CheckDefinitions();
  348. if ($sMode == 'install')
  349. {
  350. if (!MetaModel::DBExists(/* bMustBeComplete */ false))
  351. {
  352. MetaModel::DBCreate();
  353. $this->log_ok("Database structure successfully created.");
  354. }
  355. else
  356. {
  357. if (strlen($oConfig->GetDBSubname()) > 0)
  358. {
  359. throw new Exception("Error: found iTop tables into the database '".$oConfig->GetDBName()."' (prefix: '".$oConfig->GetDBSubname()."'). Please, try selecting another database instance or specify another prefix to prevent conflicting table names.");
  360. }
  361. else
  362. {
  363. throw new Exception("Error: found iTop tables into the database '".$oConfig->GetDBName()."'. Please, try selecting another database instance or specify a prefix to prevent conflicting table names.");
  364. }
  365. }
  366. }
  367. else
  368. {
  369. if (MetaModel::DBExists(/* bMustBeComplete */ false))
  370. {
  371. MetaModel::DBCreate();
  372. $this->log_ok("Database structure successfully updated.");
  373. // Check (and update only if it seems needed) the hierarchical keys
  374. ob_start();
  375. MetaModel::CheckHKeys(false /* bDiagnosticsOnly */, true /* bVerbose*/, true /* bForceUpdate */); // Since in 1.2-beta the detection was buggy, let's force the rebuilding of HKeys
  376. $sFeedback = ob_get_clean();
  377. $this->log_ok("Hierchical keys rebuilt: $sFeedback");
  378. // Check (and fix) data sync configuration
  379. ob_start();
  380. MetaModel::CheckDataSources(false /*$bDiagnostics*/, true/*$bVerbose*/);
  381. $sFeedback = ob_get_clean();
  382. $this->log_ok("Data sources checked: $sFeedback");
  383. }
  384. else
  385. {
  386. if (strlen($oConfig->GetDBSubname()) > 0)
  387. {
  388. throw new Exception("Error: No previous instance of iTop found into the database '".$oConfig->GetDBName()."' (prefix: '".$oConfig->GetDBSubname()."'). Please, try selecting another database instance.");
  389. }
  390. else
  391. {
  392. throw new Exception("Error: No previous instance of iTop found into the database '".$oConfig->GetDBName()."'. Please, try selecting another database instance.");
  393. }
  394. }
  395. }
  396. return true;
  397. }
  398. public function RecordInstallation(Config $oConfig, $sDataModelVersion, $aSelectedModules, $sModulesRelativePath)
  399. {
  400. // Record datamodel version
  401. $aData = array(
  402. 'source_dir' => $oConfig->Get('source_dir'),
  403. );
  404. $oInstallRec = new ModuleInstallation();
  405. $oInstallRec->Set('name', DATAMODEL_MODULE);
  406. $oInstallRec->Set('version', $sDataModelVersion);
  407. $oInstallRec->Set('comment', json_encode($aData));
  408. $oInstallRec->Set('parent_id', 0); // root module
  409. $iMainItopRecord = $oInstallRec->DBInsertNoReload();
  410. // Record main installation
  411. $oInstallRec = new ModuleInstallation();
  412. $oInstallRec->Set('name', ITOP_APPLICATION);
  413. $oInstallRec->Set('version', ITOP_VERSION.'.'.ITOP_REVISION);
  414. $oInstallRec->Set('comment', "Done by the setup program\nBuilt on ".ITOP_BUILD_DATE);
  415. $oInstallRec->Set('parent_id', 0); // root module
  416. $iMainItopRecord = $oInstallRec->DBInsertNoReload();
  417. // Record installed modules
  418. //
  419. $aAvailableModules = $this->AnalyzeInstallation($oConfig, APPROOT.$sModulesRelativePath);
  420. foreach($aSelectedModules as $sModuleId)
  421. {
  422. $aModuleData = $aAvailableModules[$sModuleId];
  423. $sName = $sModuleId;
  424. $sVersion = $aModuleData['version_code'];
  425. $aComments = array();
  426. $aComments[] = 'Done by the setup program';
  427. if ($aModuleData['mandatory'])
  428. {
  429. $aComments[] = 'Mandatory';
  430. }
  431. else
  432. {
  433. $aComments[] = 'Optional';
  434. }
  435. if ($aModuleData['visible'])
  436. {
  437. $aComments[] = 'Visible (during the setup)';
  438. }
  439. else
  440. {
  441. $aComments[] = 'Hidden (selected automatically)';
  442. }
  443. foreach ($aModuleData['dependencies'] as $sDependOn)
  444. {
  445. $aComments[] = "Depends on module: $sDependOn";
  446. }
  447. $sComment = implode("\n", $aComments);
  448. $oInstallRec = new ModuleInstallation();
  449. $oInstallRec->Set('name', $sName);
  450. $oInstallRec->Set('version', $sVersion);
  451. $oInstallRec->Set('comment', $sComment);
  452. $oInstallRec->Set('parent_id', $iMainItopRecord);
  453. $oInstallRec->DBInsertNoReload();
  454. }
  455. // Database is created, installation has been tracked into it
  456. return true;
  457. }
  458. public function GetApplicationVersion(Config $oConfig)
  459. {
  460. $aResult = false;
  461. try
  462. {
  463. require_once(APPROOT.'/core/cmdbsource.class.inc.php');
  464. CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName());
  465. CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation());
  466. $sSQLQuery = "SELECT * FROM ".$oConfig->GetDBSubname()."priv_module_install";
  467. $aSelectInstall = CMDBSource::QueryToArray($sSQLQuery);
  468. }
  469. catch (MySQLException $e)
  470. {
  471. // No database or erroneous information
  472. $this->log_error('Can not connect to the database: host: '.$oConfig->GetDBHost().', user:'.$oConfig->GetDBUser().', pwd:'.$oConfig->GetDBPwd().', db name:'.$oConfig->GetDBName());
  473. $this->log_error('Exception '.$e->getMessage());
  474. return false;
  475. }
  476. // Scan the list of installed modules to get the version of the 'ROOT' module which holds the main application version
  477. foreach ($aSelectInstall as $aInstall)
  478. {
  479. $sModuleVersion = $aInstall['version'];
  480. if ($sModuleVersion == '')
  481. {
  482. // Though the version cannot be empty in iTop 2.0, it used to be possible
  483. // therefore we have to put something here or the module will not be considered
  484. // as being installed
  485. $sModuleVersion = '0.0.0';
  486. }
  487. if ($aInstall['parent_id'] == 0)
  488. {
  489. if ($aInstall['name'] == DATAMODEL_MODULE)
  490. {
  491. $aResult['datamodel_version'] = $sModuleVersion;
  492. $aComments = json_decode($aInstall['comment'], true);
  493. if (is_array($aComments))
  494. {
  495. $aResult = array_merge($aResult, $aComments);
  496. }
  497. }
  498. else
  499. {
  500. $aResult['product_name'] = $aInstall['name'];
  501. $aResult['product_version'] = $sModuleVersion;
  502. }
  503. }
  504. }
  505. if (!array_key_exists('datamodel_version', $aResult))
  506. {
  507. // Versions prior to 2.0 did not record the version of the datamodel
  508. // so assume that the datamodel version is equal to the application version
  509. $aResult['datamodel_version'] = $aResult['product_version'];
  510. }
  511. $this->log_info("GetApplicationVersion returns: product_name: ".$aResult['product_name'].', product_version: '.$aResult['product_version']);
  512. return $aResult;
  513. }
  514. public static function MakeDirSafe($sDir)
  515. {
  516. if (!is_dir($sDir))
  517. {
  518. if (!@mkdir($sDir))
  519. {
  520. throw new Exception("Failed to create directory '$sTargetPath', please check the rights of the web server");
  521. }
  522. @chmod($sDir, 0770); // RWX for owner and group, nothing for others
  523. }
  524. }
  525. /**
  526. * Wrappers for logging into the setup log files
  527. */
  528. protected function log_error($sText)
  529. {
  530. SetupPage::log_error($sText);
  531. }
  532. protected function log_warning($sText)
  533. {
  534. SetupPage::log_warning($sText);
  535. }
  536. protected function log_info($sText)
  537. {
  538. SetupPage::log_info($sText);
  539. }
  540. protected function log_ok($sText)
  541. {
  542. SetupPage::log_ok($sText);
  543. }
  544. } // End of class