applicationinstaller.class.inc.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  1. <?php
  2. // Copyright (C) 2010-2016 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. require_once(APPROOT.'setup/parameters.class.inc.php');
  19. require_once(APPROOT.'setup/xmldataloader.class.inc.php');
  20. require_once(APPROOT.'setup/backup.class.inc.php');
  21. /**
  22. * The base class for the installation process.
  23. * The installation process is split into a sequence of unitary steps
  24. * for performance reasons (i.e; timeout, memory usage) and also in order
  25. * to provide some feedback about the progress of the installation.
  26. *
  27. * This class can be used for a step by step interactive installation
  28. * while displaying a progress bar, or in an unattended manner
  29. * (for example from the command line), to run all the steps
  30. * in one go.
  31. * @copyright Copyright (C) 2010-2016 Combodo SARL
  32. * @license http://opensource.org/licenses/AGPL-3.0
  33. */
  34. class ApplicationInstaller
  35. {
  36. const OK = 1;
  37. const ERROR = 2;
  38. const WARNING = 3;
  39. const INFO = 4;
  40. protected $oParams;
  41. protected static $bMetaModelStarted = false;
  42. public function __construct($oParams)
  43. {
  44. $this->oParams = $oParams;
  45. }
  46. /**
  47. * Runs all the installation steps in one go and directly outputs
  48. * some information about the progress and the success of the various
  49. * sequential steps.
  50. * @return boolean True if the installation was successful, false otherwise
  51. */
  52. public function ExecuteAllSteps()
  53. {
  54. $sStep = '';
  55. $sStepLabel = '';
  56. $iOverallStatus = self::OK;
  57. do
  58. {
  59. if($sStep != '')
  60. {
  61. echo "$sStepLabel\n";
  62. echo "Executing '$sStep'\n";
  63. }
  64. else
  65. {
  66. echo "Starting the installation...\n";
  67. }
  68. $aRes = $this->ExecuteStep($sStep);
  69. $sStep = $aRes['next-step'];
  70. $sStepLabel = $aRes['next-step-label'];
  71. switch($aRes['status'])
  72. {
  73. case self::OK;
  74. echo "Ok. ".$aRes['percentage-completed']." % done.\n";
  75. break;
  76. case self::ERROR:
  77. $iOverallStatus = self::ERROR;
  78. echo "Error: ".$aRes['message']."\n";
  79. break;
  80. case self::WARNING:
  81. $iOverallStatus = self::WARNING;
  82. echo "Warning: ".$aRes['message']."\n";
  83. echo $aRes['percentage-completed']." % done.\n";
  84. break;
  85. case self::INFO:
  86. echo "Info: ".$aRes['message']."\n";
  87. echo $aRes['percentage-completed']." % done.\n";
  88. break;
  89. }
  90. }
  91. while(($aRes['status'] != self::ERROR) && ($aRes['next-step'] != ''));
  92. return ($iOverallStatus == self::OK);
  93. }
  94. /**
  95. * Executes the next step of the installation and reports about the progress
  96. * and the next step to perform
  97. * @param string $sStep The identifier of the step to execute
  98. * @return hash An array of (status => , message => , percentage-completed => , next-step => , next-step-label => )
  99. */
  100. public function ExecuteStep($sStep = '')
  101. {
  102. try
  103. {
  104. switch($sStep)
  105. {
  106. case '':
  107. $aResult = array(
  108. 'status' => self::OK,
  109. 'message' => '',
  110. 'percentage-completed' => 0,
  111. 'next-step' => 'copy',
  112. 'next-step-label' => 'Copying data model files',
  113. );
  114. // Log the parameters...
  115. $oDoc = new DOMDocument('1.0', 'UTF-8');
  116. $oDoc->preserveWhiteSpace = false;
  117. $oDoc->formatOutput = true;
  118. $this->oParams->ToXML($oDoc, null, 'installation');
  119. $sXML = $oDoc->saveXML();
  120. $sSafeXml = preg_replace("|<pwd>([^<]*)</pwd>|", "<pwd>**removed**</pwd>", $sXML);
  121. SetupPage::log_info("======= Installation starts =======\nParameters:\n$sSafeXml\n");
  122. // Save the response file as a stand-alone file as well
  123. $sFileName = 'install-'.date('Y-m-d');
  124. $index = 0;
  125. while(file_exists(APPROOT.'log/'.$sFileName.'.xml'))
  126. {
  127. $index++;
  128. $sFileName = 'install-'.date('Y-m-d').'-'.$index;
  129. }
  130. file_put_contents(APPROOT.'log/'.$sFileName.'.xml', $sSafeXml);
  131. break;
  132. case 'copy':
  133. $aPreinstall = $this->oParams->Get('preinstall');
  134. $aCopies = $aPreinstall['copies'];
  135. $sReport = self::DoCopy($aCopies);
  136. $sReport = "Copying...";
  137. $aResult = array(
  138. 'status' => self::OK,
  139. 'message' => $sReport,
  140. );
  141. if (isset($aPreinstall['backup']))
  142. {
  143. $aResult['next-step'] = 'backup';
  144. $aResult['next-step-label'] = 'Performing a backup of the database';
  145. $aResult['percentage-completed'] = 20;
  146. }
  147. else
  148. {
  149. $aResult['next-step'] = 'compile';
  150. $aResult['next-step-label'] = 'Compiling the data model';
  151. $aResult['percentage-completed'] = 20;
  152. }
  153. break;
  154. case 'backup':
  155. $aPreinstall = $this->oParams->Get('preinstall');
  156. // __DB__-%Y-%m-%d.zip
  157. $sDestination = $aPreinstall['backup']['destination'];
  158. $sSourceConfigFile = $aPreinstall['backup']['configuration_file'];
  159. $aDBParams = $this->oParams->Get('database');
  160. self::DoBackup($aDBParams['server'], $aDBParams['user'], $aDBParams['pwd'], $aDBParams['name'], $aDBParams['prefix'], $sDestination, $sSourceConfigFile);
  161. $aResult = array(
  162. 'status' => self::OK,
  163. 'message' => "Created backup",
  164. 'next-step' => 'compile',
  165. 'next-step-label' => 'Compiling the data model',
  166. 'percentage-completed' => 20,
  167. );
  168. break;
  169. case 'compile':
  170. $aSelectedModules = $this->oParams->Get('selected_modules');
  171. $sSourceDir = $this->oParams->Get('source_dir', 'datamodels/latest');
  172. $sExtensionDir = $this->oParams->Get('extensions_dir', 'extensions');
  173. $sTargetEnvironment = $this->oParams->Get('target_env', '');
  174. if ($sTargetEnvironment == '')
  175. {
  176. $sTargetEnvironment = 'production';
  177. }
  178. $sTargetDir = 'env-'.$sTargetEnvironment;
  179. $sWorkspaceDir = $this->oParams->Get('workspace_dir', 'workspace');
  180. $bUseSymbolicLinks = false;
  181. $aMiscOptions = $this->oParams->Get('options', array());
  182. if (isset($aMiscOptions['symlinks']) && $aMiscOptions['symlinks'] )
  183. {
  184. if (function_exists('symlink'))
  185. {
  186. $bUseSymbolicLinks = true;
  187. SetupPage::log_info("Using symbolic links instead of copying data model files (for developers only!)");
  188. }
  189. else
  190. {
  191. SetupPage::log_info("Symbolic links (function symlinks) does not seem to be supported on this platform (OS/PHP version).");
  192. }
  193. }
  194. self::DoCompile($aSelectedModules, $sSourceDir, $sExtensionDir, $sTargetDir, $sTargetEnvironment, $bUseSymbolicLinks);
  195. $aResult = array(
  196. 'status' => self::OK,
  197. 'message' => '',
  198. 'next-step' => 'db-schema',
  199. 'next-step-label' => 'Updating database schema',
  200. 'percentage-completed' => 40,
  201. );
  202. break;
  203. case 'db-schema':
  204. $sMode = $this->oParams->Get('mode');
  205. $aSelectedModules = $this->oParams->Get('selected_modules', array());
  206. $sTargetEnvironment = $this->oParams->Get('target_env', '');
  207. if ($sTargetEnvironment == '')
  208. {
  209. $sTargetEnvironment = 'production';
  210. }
  211. $sTargetDir = 'env-'.$sTargetEnvironment;
  212. $aDBParams = $this->oParams->Get('database');
  213. $sDBServer = $aDBParams['server'];
  214. $sDBUser = $aDBParams['user'];
  215. $sDBPwd = $aDBParams['pwd'];
  216. $sDBName = $aDBParams['name'];
  217. $sDBPrefix = $aDBParams['prefix'];
  218. $bOldAddon = $this->oParams->Get('old_addon', false);
  219. self::DoUpdateDBSchema($sMode, $aSelectedModules, $sTargetDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sTargetEnvironment, $bOldAddon);
  220. $aResult = array(
  221. 'status' => self::OK,
  222. 'message' => '',
  223. 'next-step' => 'after-db-create',
  224. 'next-step-label' => 'Creating profiles',
  225. 'percentage-completed' => 60,
  226. );
  227. break;
  228. case 'after-db-create':
  229. $sMode = $this->oParams->Get('mode');
  230. $sTargetEnvironment = $this->oParams->Get('target_env', '');
  231. if ($sTargetEnvironment == '')
  232. {
  233. $sTargetEnvironment = 'production';
  234. }
  235. $sTargetDir = 'env-'.$sTargetEnvironment;
  236. $aDBParams = $this->oParams->Get('database');
  237. $sDBServer = $aDBParams['server'];
  238. $sDBUser = $aDBParams['user'];
  239. $sDBPwd = $aDBParams['pwd'];
  240. $sDBName = $aDBParams['name'];
  241. $sDBPrefix = $aDBParams['prefix'];
  242. $aAdminParams = $this->oParams->Get('admin_account');
  243. $sAdminUser = $aAdminParams['user'];
  244. $sAdminPwd = $aAdminParams['pwd'];
  245. $sAdminLanguage = $aAdminParams['language'];
  246. $sLanguage = $this->oParams->Get('language');
  247. $aSelectedModules = $this->oParams->Get('selected_modules', array());
  248. $sDataModelVersion = $this->oParams->Get('datamodel_version', '0.0.0');
  249. $bOldAddon = $this->oParams->Get('old_addon', false);
  250. $sSourceDir = $this->oParams->Get('source_dir', '');
  251. self::AfterDBCreate($sMode, $sTargetDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sAdminUser,
  252. $sAdminPwd, $sAdminLanguage, $sLanguage, $aSelectedModules, $sTargetEnvironment, $bOldAddon, $sDataModelVersion, $sSourceDir);
  253. $aResult = array(
  254. 'status' => self::OK,
  255. 'message' => '',
  256. 'next-step' => 'load-data',
  257. 'next-step-label' => 'Loading data',
  258. 'percentage-completed' => 80,
  259. );
  260. break;
  261. case 'load-data':
  262. $aSelectedModules = $this->oParams->Get('selected_modules');
  263. $sTargetEnvironment = $this->oParams->Get('target_env', '');
  264. $sTargetDir = 'env-'.(($sTargetEnvironment == '') ? 'production' : $sTargetEnvironment);
  265. $aDBParams = $this->oParams->Get('database');
  266. $sDBServer = $aDBParams['server'];
  267. $sDBUser = $aDBParams['user'];
  268. $sDBPwd = $aDBParams['pwd'];
  269. $sDBName = $aDBParams['name'];
  270. $sDBPrefix = $aDBParams['prefix'];
  271. $aFiles = $this->oParams->Get('files', array());
  272. $bOldAddon = $this->oParams->Get('old_addon', false);
  273. $bSampleData = ($this->oParams->Get('sample_data', 0) == 1);
  274. self::DoLoadFiles($aSelectedModules, $sTargetDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sTargetEnvironment, $bOldAddon, $bSampleData);
  275. $aResult = array(
  276. 'status' => self::INFO,
  277. 'message' => 'All data loaded',
  278. 'next-step' => 'create-config',
  279. 'next-step-label' => 'Creating the configuration File',
  280. 'percentage-completed' => 99,
  281. );
  282. break;
  283. case 'create-config':
  284. $sMode = $this->oParams->Get('mode');
  285. $sTargetEnvironment = $this->oParams->Get('target_env', '');
  286. if ($sTargetEnvironment == '')
  287. {
  288. $sTargetEnvironment = 'production';
  289. }
  290. $sTargetDir = 'env-'.$sTargetEnvironment;
  291. $aDBParams = $this->oParams->Get('database');
  292. $sDBServer = $aDBParams['server'];
  293. $sDBUser = $aDBParams['user'];
  294. $sDBPwd = $aDBParams['pwd'];
  295. $sDBName = $aDBParams['name'];
  296. $sDBPrefix = $aDBParams['prefix'];
  297. $sUrl = $this->oParams->Get('url', '');
  298. $sGraphvizPath = $this->oParams->Get('graphviz_path', '');
  299. $sLanguage = $this->oParams->Get('language', '');
  300. $aSelectedModules = $this->oParams->Get('selected_modules', array());
  301. $bOldAddon = $this->oParams->Get('old_addon', false);
  302. $sSourceDir = $this->oParams->Get('source_dir', '');
  303. $sPreviousConfigFile = $this->oParams->Get('previous_configuration_file', '');
  304. $sDataModelVersion = $this->oParams->Get('datamodel_version', '0.0.0');
  305. self::DoCreateConfig($sMode, $sTargetDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sUrl, $sLanguage, $aSelectedModules, $sTargetEnvironment, $bOldAddon, $sSourceDir, $sPreviousConfigFile, $sDataModelVersion, $sGraphvizPath);
  306. $aResult = array(
  307. 'status' => self::INFO,
  308. 'message' => 'Configuration file created',
  309. 'next-step' => '',
  310. 'next-step-label' => 'Completed',
  311. 'percentage-completed' => 100,
  312. );
  313. break;
  314. default:
  315. $aResult = array(
  316. 'status' => self::ERROR,
  317. 'message' => '',
  318. 'next-step' => '',
  319. 'next-step-label' => "Unknown setup step '$sStep'.",
  320. 'percentage-completed' => 100,
  321. );
  322. }
  323. }
  324. catch(Exception $e)
  325. {
  326. $aResult = array(
  327. 'status' => self::ERROR,
  328. 'message' => $e->getMessage(),
  329. 'next-step' => '',
  330. 'next-step-label' => '',
  331. 'percentage-completed' => 100,
  332. );
  333. SetupPage::log_error('An exception occurred: '.$e->getMessage().' at line '.$e->getLine().' in file '.$e->getFile());
  334. $idx = 0;
  335. // Log the call stack, but not the parameters since they may contain passwords or other sensitive data
  336. SetupPage::log("Call stack:");
  337. foreach($e->getTrace() as $aTrace)
  338. {
  339. $sLine = empty($aTrace['line']) ? "" : $aTrace['line'];
  340. $sFile = empty($aTrace['file']) ? "" : $aTrace['file'];
  341. $sClass = empty($aTrace['class']) ? "" : $aTrace['class'];
  342. $sType = empty($aTrace['type']) ? "" : $aTrace['type'];
  343. $sFunction = empty($aTrace['function']) ? "" : $aTrace['function'];
  344. $sVerb = empty($sClass) ? $sFunction : "$sClass{$sType}$sFunction";
  345. SetupPage::log("#$idx $sFile($sLine): $sVerb(...)");
  346. $idx++;
  347. }
  348. }
  349. return $aResult;
  350. }
  351. protected static function DoCopy($aCopies)
  352. {
  353. $aReports = array();
  354. foreach ($aCopies as $aCopy)
  355. {
  356. $sSource = $aCopy['source'];
  357. $sDestination = APPROOT.$aCopy['destination'];
  358. SetupUtils::builddir($sDestination);
  359. SetupUtils::tidydir($sDestination);
  360. SetupUtils::copydir($sSource, $sDestination);
  361. $aReports[] = "'{$aCopy['source']}' to '{$aCopy['destination']}' (OK)";
  362. }
  363. if (count($aReports) > 0)
  364. {
  365. $sReport = "Copies: ".count($aReports).': '.implode('; ', $aReports);
  366. }
  367. else
  368. {
  369. $sReport = "No file copy";
  370. }
  371. return $sReport;
  372. }
  373. protected static function DoBackup($sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sBackupFile, $sSourceConfigFile)
  374. {
  375. $oBackup = new SetupDBBackup($sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix);
  376. $sZipFile = $oBackup->MakeName($sBackupFile);
  377. $oBackup->CreateZip($sZipFile, $sSourceConfigFile);
  378. }
  379. protected static function DoCompile($aSelectedModules, $sSourceDir, $sExtensionDir, $sTargetDir, $sEnvironment, $bUseSymbolicLinks = false)
  380. {
  381. SetupPage::log_info("Compiling data model.");
  382. require_once(APPROOT.'setup/modulediscovery.class.inc.php');
  383. require_once(APPROOT.'setup/modelfactory.class.inc.php');
  384. require_once(APPROOT.'setup/compiler.class.inc.php');
  385. if (empty($sSourceDir) || empty($sTargetDir))
  386. {
  387. throw new Exception("missing parameter source_dir and/or target_dir");
  388. }
  389. $sSourcePath = APPROOT.$sSourceDir;
  390. $aDirsToScan = array($sSourcePath);
  391. $sExtensionsPath = APPROOT.$sExtensionDir;
  392. if (is_dir($sExtensionsPath))
  393. {
  394. // if the extensions dir exists, scan it for additional modules as well
  395. $aDirsToScan[] = $sExtensionsPath;
  396. }
  397. $sExtraPath = APPROOT.'/data/'.$sEnvironment.'-modules/';
  398. if (is_dir($sExtraPath))
  399. {
  400. // if the extra dir exists, scan it for additional modules as well
  401. $aDirsToScan[] = $sExtraPath;
  402. }
  403. $sTargetPath = APPROOT.$sTargetDir;
  404. if (!is_dir($sSourcePath))
  405. {
  406. throw new Exception("Failed to find the source directory '$sSourcePath', please check the rights of the web server");
  407. }
  408. if (!is_dir($sTargetPath))
  409. {
  410. if (!mkdir($sTargetPath))
  411. {
  412. throw new Exception("Failed to create directory '$sTargetPath', please check the rights of the web server");
  413. }
  414. else
  415. {
  416. // adjust the rights if and only if the directory was just created
  417. // owner:rwx user/group:rx
  418. chmod($sTargetPath, 0755);
  419. }
  420. }
  421. else if (substr($sTargetPath, 0, strlen(APPROOT)) == APPROOT)
  422. {
  423. // If the directory is under the root folder - as expected - let's clean-it before compiling
  424. SetupUtils::tidydir($sTargetPath);
  425. }
  426. $oFactory = new ModelFactory($aDirsToScan);
  427. $oDictModule = new MFDictModule('dictionaries', 'iTop Dictionaries', APPROOT.'dictionaries');
  428. $oFactory->LoadModule($oDictModule);
  429. $sDeltaFile = APPROOT.'core/datamodel.core.xml';
  430. if (file_exists($sDeltaFile))
  431. {
  432. $oCoreModule = new MFCoreModule('core', 'Core Module', $sDeltaFile);
  433. $oFactory->LoadModule($oCoreModule);
  434. }
  435. $sDeltaFile = APPROOT.'application/datamodel.application.xml';
  436. if (file_exists($sDeltaFile))
  437. {
  438. $oApplicationModule = new MFCoreModule('application', 'Application Module', $sDeltaFile);
  439. $oFactory->LoadModule($oApplicationModule);
  440. }
  441. $aModules = $oFactory->FindModules();
  442. foreach($aModules as $foo => $oModule)
  443. {
  444. $sModule = $oModule->GetName();
  445. if (in_array($sModule, $aSelectedModules))
  446. {
  447. $oFactory->LoadModule($oModule);
  448. }
  449. }
  450. $sDeltaFile = APPROOT.'data/'.$sEnvironment.'.delta.xml';
  451. if (file_exists($sDeltaFile))
  452. {
  453. $oDelta = new MFDeltaModule($sDeltaFile);
  454. $oFactory->LoadModule($oDelta);
  455. }
  456. //$oFactory->Dump();
  457. if ($oFactory->HasLoadErrors())
  458. {
  459. foreach($oFactory->GetLoadErrors() as $sModuleId => $aErrors)
  460. {
  461. SetupPage::log_error("Data model source file (xml) could not be loaded - found errors in module: $sModuleId");
  462. foreach($aErrors as $oXmlError)
  463. {
  464. SetupPage::log_error("Load error: File: ".$oXmlError->file." Line:".$oXmlError->line." Message:".$oXmlError->message);
  465. }
  466. }
  467. throw new Exception("The data model could not be compiled. Please check the setup error log");
  468. }
  469. else
  470. {
  471. $oMFCompiler = new MFCompiler($oFactory);
  472. $oMFCompiler->Compile($sTargetPath, null, $bUseSymbolicLinks);
  473. //$aCompilerLog = $oMFCompiler->GetLog();
  474. //SetupPage::log_info(implode("\n", $aCompilerLog));
  475. SetupPage::log_info("Data model successfully compiled to '$sTargetPath'.");
  476. $sCacheDir = APPROOT.'/data/cache-'.$sEnvironment.'/';
  477. Setuputils::builddir($sCacheDir);
  478. Setuputils::tidydir($sCacheDir);
  479. }
  480. // Special case to patch a ugly patch in itop-config-mgmt
  481. $sFileToPatch = $sTargetPath.'/itop-config-mgmt-1.0.0/model.itop-config-mgmt.php';
  482. if (file_exists($sFileToPatch))
  483. {
  484. $sContent = file_get_contents($sFileToPatch);
  485. $sContent = str_replace("require_once(APPROOT.'modules/itop-welcome-itil/model.itop-welcome-itil.php');", "//\n// The line below is no longer needed in iTop 2.0 -- patched by the setup program\n// require_once(APPROOT.'modules/itop-welcome-itil/model.itop-welcome-itil.php');", $sContent);
  486. file_put_contents($sFileToPatch, $sContent);
  487. }
  488. // Set an "Instance UUID" identifying this machine based on a file located in the data directory
  489. $sInstanceUUIDFile = APPROOT.'data/instance.txt';
  490. Setuputils::builddir(APPROOT.'data');
  491. if (!file_exists($sInstanceUUIDFile))
  492. {
  493. $sIntanceUUID = utils::CreateUUID('filesystem');
  494. file_put_contents($sInstanceUUIDFile, $sIntanceUUID);
  495. }
  496. }
  497. protected static function DoUpdateDBSchema($sMode, $aSelectedModules, $sModulesDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sTargetEnvironment = '', $bOldAddon = false)
  498. {
  499. SetupPage::log_info("Update Database Schema for environment '$sTargetEnvironment'.");
  500. $oConfig = new Config();
  501. $aParamValues = array(
  502. 'mode' => $sMode,
  503. 'db_server' => $sDBServer,
  504. 'db_user' => $sDBUser,
  505. 'db_pwd' => $sDBPwd,
  506. 'db_name' => $sDBName,
  507. 'db_prefix' => $sDBPrefix,
  508. );
  509. $oConfig->UpdateFromParams($aParamValues, $sModulesDir);
  510. if ($bOldAddon)
  511. {
  512. // Old version of the add-on for backward compatibility with pre-2.0 data models
  513. $oConfig->SetAddons(array(
  514. 'user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php',
  515. ));
  516. }
  517. $oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
  518. $oProductionEnv->InitDataModel($oConfig, true); // load data model only
  519. // Migrate application data format
  520. //
  521. // priv_internalUser caused troubles because MySQL transforms table names to lower case under Windows
  522. // This becomes an issue when moving your installation data to/from Windows
  523. // Starting 2.0, all table names must be lowercase
  524. if ($sMode != 'install')
  525. {
  526. SetupPage::log_info("Renaming '{$sDBPrefix}priv_internalUser' into '{$sDBPrefix}priv_internaluser' (lowercase)");
  527. // This command will have no effect under Windows...
  528. // and it has been written in two steps so as to make it work under windows!
  529. CMDBSource::SelectDB($sDBName);
  530. try
  531. {
  532. $sRepair = "RENAME TABLE `{$sDBPrefix}priv_internalUser` TO `{$sDBPrefix}priv_internaluser_other`, `{$sDBPrefix}priv_internaluser_other` TO `{$sDBPrefix}priv_internaluser`";
  533. CMDBSource::Query($sRepair);
  534. }
  535. catch (Exception $e)
  536. {
  537. SetupPage::log_info("Renaming '{$sDBPrefix}priv_internalUser' failed (already done in a previous upgrade?)");
  538. }
  539. // let's remove the records in priv_change which have no counterpart in priv_changeop
  540. SetupPage::log_info("Cleanup of '{$sDBPrefix}priv_change' to remove orphan records");
  541. CMDBSource::SelectDB($sDBName);
  542. try
  543. {
  544. $sTotalCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_change`";
  545. $iTotalCount = (int)CMDBSource::QueryToScalar($sTotalCount);
  546. SetupPage::log_info("There is a total of $iTotalCount records in {$sDBPrefix}priv_change.");
  547. $sOrphanCount = "SELECT COUNT(c.id) FROM `{$sDBPrefix}priv_change` AS c left join `{$sDBPrefix}priv_changeop` AS o ON c.id = o.changeid WHERE o.id IS NULL";
  548. $iOrphanCount = (int)CMDBSource::QueryToScalar($sOrphanCount);
  549. SetupPage::log_info("There are $iOrphanCount useless records in {$sDBPrefix}priv_change (".sprintf('%.2f', ((100.0*$iOrphanCount)/$iTotalCount))."%)");
  550. if ($iOrphanCount > 0)
  551. {
  552. SetupPage::log_info("Removing the orphan records...");
  553. $sCleanup = "DELETE FROM `{$sDBPrefix}priv_change` USING `{$sDBPrefix}priv_change` LEFT JOIN `{$sDBPrefix}priv_changeop` ON `{$sDBPrefix}priv_change`.id = `{$sDBPrefix}priv_changeop`.changeid WHERE `{$sDBPrefix}priv_changeop`.id IS NULL;";
  554. CMDBSource::Query($sCleanup);
  555. SetupPage::log_info("Cleanup completed successfully.");
  556. }
  557. else
  558. {
  559. SetupPage::log_info("Ok, nothing to cleanup.");
  560. }
  561. }
  562. catch (Exception $e)
  563. {
  564. SetupPage::log_info("Cleanup of orphan records in `{$sDBPrefix}priv_change` failed: ".$e->getMessage());
  565. }
  566. }
  567. // Module specific actions (migrate the data)
  568. //
  569. $aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT.$sModulesDir);
  570. foreach($aAvailableModules as $sModuleId => $aModule)
  571. {
  572. if (($sModuleId != ROOT_MODULE) && in_array($sModuleId, $aSelectedModules) &&
  573. isset($aAvailableModules[$sModuleId]['installer']) )
  574. {
  575. $sModuleInstallerClass = $aAvailableModules[$sModuleId]['installer'];
  576. SetupPage::log_info("Calling Module Handler: $sModuleInstallerClass::BeforeDatabaseCreation(oConfig, {$aModule['version_db']}, {$aModule['version_code']})");
  577. $aCallSpec = array($sModuleInstallerClass, 'BeforeDatabaseCreation');
  578. call_user_func_array($aCallSpec, array(MetaModel::GetConfig(), $aModule['version_db'], $aModule['version_code']));
  579. }
  580. }
  581. if(!$oProductionEnv->CreateDatabaseStructure(MetaModel::GetConfig(), $sMode))
  582. {
  583. throw new Exception("Failed to create/upgrade the database structure for environment '$sTargetEnvironment'");
  584. }
  585. // Set a DBProperty with a unique ID to identify this instance of iTop
  586. $sUUID = DBProperty::GetProperty('database_uuid', '');
  587. if ($sUUID === '')
  588. {
  589. $sUUID = utils::CreateUUID('database');
  590. DBProperty::SetProperty('database_uuid', $sUUID, 'Installation/upgrade of '.ITOP_APPLICATION, 'Unique ID of this '.ITOP_APPLICATION.' Database');
  591. }
  592. // priv_change now has an 'origin' field to distinguish between the various input sources
  593. // Let's initialize the field with 'interactive' for all records were it's null
  594. // Then check if some records should hold a different value, based on a pattern matching in the userinfo field
  595. CMDBSource::SelectDB($sDBName);
  596. try
  597. {
  598. $sCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_change` WHERE `origin` IS NULL";
  599. $iCount = (int)CMDBSource::QueryToScalar($sCount);
  600. if ($iCount > 0)
  601. {
  602. SetupPage::log_info("Initializing '{$sDBPrefix}priv_change.origin' ($iCount records to update)");
  603. // By default all uninitialized values are considered as 'interactive'
  604. $sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'interactive' WHERE `origin` IS NULL";
  605. CMDBSource::Query($sInit);
  606. // CSV Import was identified by the comment at the end
  607. $sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'csv-import.php' WHERE `userinfo` LIKE '%Web Service (CSV)'";
  608. CMDBSource::Query($sInit);
  609. // CSV Import was identified by the comment at the end
  610. $sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'csv-interactive' WHERE `userinfo` LIKE '%(CSV)' AND origin = 'interactive'";
  611. CMDBSource::Query($sInit);
  612. // Syncho data sources were identified by the comment at the end
  613. // Unfortunately the comment is localized, so we have to search for all possible patterns
  614. $sCurrentLanguage = Dict::GetUserLanguage();
  615. foreach(Dict::GetLanguages() as $sLangCode => $aLang)
  616. {
  617. Dict::SetUserLanguage($sLangCode);
  618. $sSuffix = CMDBSource::Quote('%'.Dict::S('Core:SyncDataExchangeComment'));
  619. $aSuffixes[$sSuffix] = true;
  620. }
  621. Dict::SetUserLanguage($sCurrentLanguage);
  622. $sCondition = "`userinfo` LIKE ".implode(" OR `userinfo` LIKE ", array_keys($aSuffixes));
  623. $sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'synchro-data-source' WHERE ($sCondition)";
  624. CMDBSource::Query($sInit);
  625. SetupPage::log_info("Initialization of '{$sDBPrefix}priv_change.origin' completed.");
  626. }
  627. else
  628. {
  629. SetupPage::log_info("'{$sDBPrefix}priv_change.origin' already initialized, nothing to do.");
  630. }
  631. }
  632. catch (Exception $e)
  633. {
  634. SetupPage::log_error("Initializing '{$sDBPrefix}priv_change.origin' failed: ".$e->getMessage());
  635. }
  636. // priv_async_task now has a 'status' field to distinguish between the various statuses rather than just relying on the date columns
  637. // Let's initialize the field with 'planned' or 'error' for all records were it's null
  638. CMDBSource::SelectDB($sDBName);
  639. try
  640. {
  641. $sCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_async_task` WHERE `status` IS NULL";
  642. $iCount = (int)CMDBSource::QueryToScalar($sCount);
  643. if ($iCount > 0)
  644. {
  645. SetupPage::log_info("Initializing '{$sDBPrefix}priv_async_task.status' ($iCount records to update)");
  646. $sInit = "UPDATE `{$sDBPrefix}priv_async_task` SET `status` = 'planned' WHERE (`status` IS NULL) AND (`started` IS NULL)";
  647. CMDBSource::Query($sInit);
  648. $sInit = "UPDATE `{$sDBPrefix}priv_async_task` SET `status` = 'error' WHERE (`status` IS NULL) AND (`started` IS NOT NULL)";
  649. CMDBSource::Query($sInit);
  650. SetupPage::log_info("Initialization of '{$sDBPrefix}priv_async_task.status' completed.");
  651. }
  652. else
  653. {
  654. SetupPage::log_info("'{$sDBPrefix}priv_async_task.status' already initialized, nothing to do.");
  655. }
  656. }
  657. catch (Exception $e)
  658. {
  659. SetupPage::log_error("Initializing '{$sDBPrefix}priv_async_task.status' failed: ".$e->getMessage());
  660. }
  661. SetupPage::log_info("Database Schema Successfully Updated for environment '$sTargetEnvironment'.");
  662. }
  663. protected static function AfterDBCreate($sMode, $sModulesDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sAdminUser, $sAdminPwd, $sAdminLanguage, $sLanguage, $aSelectedModules, $sTargetEnvironment, $bOldAddon, $sDataModelVersion, $sSourceDir)
  664. {
  665. SetupPage::log_info('After Database Creation');
  666. $oConfig = new Config();
  667. $aParamValues = array(
  668. 'mode' => $sMode,
  669. 'db_server' => $sDBServer,
  670. 'db_user' => $sDBUser,
  671. 'db_pwd' => $sDBPwd,
  672. 'db_name' => $sDBName,
  673. 'db_prefix' => $sDBPrefix,
  674. );
  675. $oConfig->UpdateFromParams($aParamValues, $sModulesDir);
  676. if ($bOldAddon)
  677. {
  678. // Old version of the add-on for backward compatibility with pre-2.0 data models
  679. $oConfig->SetAddons(array(
  680. 'user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php',
  681. ));
  682. }
  683. $oConfig->Set('source_dir', $sSourceDir); // Needed by RecordInstallation below
  684. $oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
  685. $oProductionEnv->InitDataModel($oConfig, true); // load data model and connect to the database
  686. self::$bMetaModelStarted = true; // No need to reload the final MetaModel in case the installer runs synchronously
  687. // Perform here additional DB setup... profiles, etc...
  688. //
  689. $aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT.$sModulesDir);
  690. foreach($aAvailableModules as $sModuleId => $aModule)
  691. {
  692. if (($sModuleId != ROOT_MODULE) && in_array($sModuleId, $aSelectedModules) &&
  693. isset($aAvailableModules[$sModuleId]['installer']) )
  694. {
  695. $sModuleInstallerClass = $aAvailableModules[$sModuleId]['installer'];
  696. SetupPage::log_info("Calling Module Handler: $sModuleInstallerClass::AfterDatabaseCreation(oConfig, {$aModule['version_db']}, {$aModule['version_code']})");
  697. // The validity of the sModuleInstallerClass has been established in BuildConfig()
  698. $aCallSpec = array($sModuleInstallerClass, 'AfterDatabaseCreation');
  699. call_user_func_array($aCallSpec, array(MetaModel::GetConfig(), $aModule['version_db'], $aModule['version_code']));
  700. }
  701. }
  702. $oProductionEnv->UpdatePredefinedObjects();
  703. if($sMode == 'install')
  704. {
  705. if (!self::CreateAdminAccount(MetaModel::GetConfig(), $sAdminUser, $sAdminPwd, $sAdminLanguage))
  706. {
  707. throw(new Exception("Failed to create the administrator account '$sAdminUser'"));
  708. }
  709. else
  710. {
  711. SetupPage::log_info("Administrator account '$sAdminUser' created.");
  712. }
  713. }
  714. // Perform final setup tasks here
  715. //
  716. foreach($aAvailableModules as $sModuleId => $aModule)
  717. {
  718. if (($sModuleId != ROOT_MODULE) && in_array($sModuleId, $aSelectedModules) &&
  719. isset($aAvailableModules[$sModuleId]['installer']) )
  720. {
  721. $sModuleInstallerClass = $aAvailableModules[$sModuleId]['installer'];
  722. SetupPage::log_info("Calling Module Handler: $sModuleInstallerClass::AfterDatabaseSetup(oConfig, {$aModule['version_db']}, {$aModule['version_code']})");
  723. // The validity of the sModuleInstallerClass has been established in BuildConfig()
  724. $aCallSpec = array($sModuleInstallerClass, 'AfterDatabaseSetup');
  725. call_user_func_array($aCallSpec, array(MetaModel::GetConfig(), $aModule['version_db'], $aModule['version_code']));
  726. }
  727. }
  728. }
  729. /**
  730. * Helper function to create and administrator account for iTop
  731. * @return boolean true on success, false otherwise
  732. */
  733. protected static function CreateAdminAccount(Config $oConfig, $sAdminUser, $sAdminPwd, $sLanguage)
  734. {
  735. SetupPage::log_info('CreateAdminAccount');
  736. if (UserRights::CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage))
  737. {
  738. return true;
  739. }
  740. else
  741. {
  742. return false;
  743. }
  744. }
  745. protected static function DoLoadFiles($aSelectedModules, $sModulesDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sTargetEnvironment = '', $bOldAddon = false, $bSampleData = false)
  746. {
  747. $aParamValues = array(
  748. 'db_server' => $sDBServer,
  749. 'db_user' => $sDBUser,
  750. 'db_pwd' => $sDBPwd,
  751. 'db_name' => $sDBName,
  752. 'new_db_name' => $sDBName,
  753. 'db_prefix' => $sDBPrefix,
  754. );
  755. $oConfig = new Config();
  756. $oConfig->UpdateFromParams($aParamValues, $sModulesDir);
  757. if ($bOldAddon)
  758. {
  759. // Old version of the add-on for backward compatibility with pre-2.0 data models
  760. $oConfig->SetAddons(array(
  761. 'user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php',
  762. ));
  763. }
  764. //Load the MetaModel if needed (asynchronous mode)
  765. if (!self::$bMetaModelStarted)
  766. {
  767. $oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
  768. $oProductionEnv->InitDataModel($oConfig, false); // load data model and connect to the database
  769. self::$bMetaModelStarted = true; // No need to reload the final MetaModel in case the installer runs synchronously
  770. }
  771. $oDataLoader = new XMLDataLoader();
  772. CMDBObject::SetTrackInfo("Initialization");
  773. $oMyChange = CMDBObject::GetCurrentChange();
  774. SetupPage::log_info("starting data load session");
  775. $oDataLoader->StartSession($oMyChange);
  776. $aFiles = array();
  777. $aPreviouslyLoadedFiles = array();
  778. $oProductionEnv = new RunTimeEnvironment();
  779. $aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, APPROOT.$sModulesDir);
  780. foreach($aAvailableModules as $sModuleId => $aModule)
  781. {
  782. if (($sModuleId != ROOT_MODULE))
  783. {
  784. // Load data only for selected AND newly installed modules
  785. if (in_array($sModuleId, $aSelectedModules))
  786. {
  787. if ($aModule['version_db'] != '')
  788. {
  789. // Simulate the load of the previously loaded XML files to get the mapping of the keys
  790. if ($bSampleData)
  791. {
  792. $aPreviouslyLoadedFiles = array_merge(
  793. $aPreviouslyLoadedFiles,
  794. $aAvailableModules[$sModuleId]['data.struct'],
  795. $aAvailableModules[$sModuleId]['data.sample']
  796. );
  797. }
  798. else
  799. {
  800. // Load only structural data
  801. $aPreviouslyLoadedFiles = array_merge(
  802. $aPreviouslyLoadedFiles,
  803. $aAvailableModules[$sModuleId]['data.struct']
  804. );
  805. }
  806. }
  807. else
  808. {
  809. if ($bSampleData)
  810. {
  811. $aFiles = array_merge(
  812. $aFiles,
  813. $aAvailableModules[$sModuleId]['data.struct'],
  814. $aAvailableModules[$sModuleId]['data.sample']
  815. );
  816. }
  817. else
  818. {
  819. // Load only structural data
  820. $aFiles = array_merge(
  821. $aFiles,
  822. $aAvailableModules[$sModuleId]['data.struct']
  823. );
  824. }
  825. }
  826. }
  827. }
  828. }
  829. // Simulate the load of the previously loaded files, in order to initialize
  830. // the mapping between the identifiers in the XML and the actual identifiers
  831. // in the current database
  832. foreach($aPreviouslyLoadedFiles as $sFileRelativePath)
  833. {
  834. $sFileName = APPROOT.$sFileRelativePath;
  835. SetupPage::log_info("Loading file: $sFileName (just to get the keys mapping)");
  836. if (empty($sFileName) || !file_exists($sFileName))
  837. {
  838. throw(new Exception("File $sFileName does not exist"));
  839. }
  840. $oDataLoader->LoadFile($sFileName, true);
  841. $sResult = sprintf("loading of %s done.", basename($sFileName));
  842. SetupPage::log_info($sResult);
  843. }
  844. foreach($aFiles as $sFileRelativePath)
  845. {
  846. $sFileName = APPROOT.$sFileRelativePath;
  847. SetupPage::log_info("Loading file: $sFileName");
  848. if (empty($sFileName) || !file_exists($sFileName))
  849. {
  850. throw(new Exception("File $sFileName does not exist"));
  851. }
  852. $oDataLoader->LoadFile($sFileName);
  853. $sResult = sprintf("loading of %s done.", basename($sFileName));
  854. SetupPage::log_info($sResult);
  855. }
  856. $oDataLoader->EndSession();
  857. SetupPage::log_info("ending data load session");
  858. }
  859. protected static function DoCreateConfig($sMode, $sModulesDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sUrl, $sLanguage, $aSelectedModules, $sTargetEnvironment, $bOldAddon, $sSourceDir, $sPreviousConfigFile, $sDataModelVersion, $sGraphvizPath)
  860. {
  861. $aParamValues = array(
  862. 'mode' => $sMode,
  863. 'db_server' => $sDBServer,
  864. 'db_user' => $sDBUser,
  865. 'db_pwd' => $sDBPwd,
  866. 'db_name' => $sDBName,
  867. 'new_db_name' => $sDBName,
  868. 'db_prefix' => $sDBPrefix,
  869. 'application_path' => $sUrl,
  870. 'language' => $sLanguage,
  871. 'graphviz_path' => $sGraphvizPath,
  872. 'selected_modules' => implode(',', $aSelectedModules),
  873. );
  874. $bPreserveModuleSettings = false;
  875. if ($sMode == 'upgrade')
  876. {
  877. try
  878. {
  879. $oOldConfig = new Config($sPreviousConfigFile);
  880. $oConfig = clone($oOldConfig);
  881. $bPreserveModuleSettings = true;
  882. }
  883. catch(Exception $e)
  884. {
  885. // In case the previous configuration is corrupted... start with a blank new one
  886. $oConfig = new Config();
  887. }
  888. }
  889. else
  890. {
  891. $oConfig = new Config();
  892. // To preserve backward compatibility while upgrading to 2.0.3 (when tracking_level_linked_set_default has been introduced)
  893. // the default value on upgrade differs from the default value at first install
  894. $oConfig->Set('tracking_level_linked_set_default', LINKSET_TRACKING_NONE, 'first_install');
  895. }
  896. // Migration: force utf8_unicode_ci as the collation to make the global search
  897. // NON case sensitive
  898. $oConfig->SetDBCollation('utf8_unicode_ci');
  899. // Final config update: add the modules
  900. $oConfig->UpdateFromParams($aParamValues, $sModulesDir, $bPreserveModuleSettings);
  901. if ($bOldAddon)
  902. {
  903. // Old version of the add-on for backward compatibility with pre-2.0 data models
  904. $oConfig->SetAddons(array(
  905. 'user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php',
  906. ));
  907. }
  908. $oConfig->Set('source_dir', $sSourceDir);
  909. // Record which modules are installed...
  910. $oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
  911. $oProductionEnv->InitDataModel($oConfig, true); // load data model and connect to the database
  912. $aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT.$sModulesDir);
  913. if (!$oProductionEnv->RecordInstallation($oConfig, $sDataModelVersion, $aSelectedModules, $sModulesDir))
  914. {
  915. throw new Exception("Failed to record the installation information");
  916. }
  917. // Make sure the root configuration directory exists
  918. if (!file_exists(APPCONF))
  919. {
  920. mkdir(APPCONF);
  921. chmod(APPCONF, 0770); // RWX for owner and group, nothing for others
  922. SetupPage::log_info("Created configuration directory: ".APPCONF);
  923. }
  924. // Write the final configuration file
  925. $sConfigFile = APPCONF.(($sTargetEnvironment == '') ? 'production' : $sTargetEnvironment).'/'.ITOP_CONFIG_FILE;
  926. $sConfigDir = dirname($sConfigFile);
  927. @mkdir($sConfigDir);
  928. @chmod($sConfigDir, 0770); // RWX for owner and group, nothing for others
  929. $oConfig->WriteToFile($sConfigFile);
  930. // try to make the final config file read-only
  931. @chmod($sConfigFile, 0444); // Read-only for owner and group, nothing for others
  932. // Ready to go !!
  933. require_once(APPROOT.'core/dict.class.inc.php');
  934. MetaModel::ResetCache();
  935. }
  936. }
  937. class SetupDBBackup extends DBBackup
  938. {
  939. protected function LogInfo($sMsg)
  940. {
  941. SetupPage::log('Info - '.$sMsg);
  942. }
  943. protected function LogError($sMsg)
  944. {
  945. SetupPage::log('Error - '.$sMsg);
  946. }
  947. }