public function RestoreFromZip($sZipFile, $sEnvironment = 'production') { $this->LogInfo("Starting restore of " . basename($sZipFile)); $oZip = new ZipArchiveEx(); $res = $oZip->open($sZipFile); // Load the database // $sDataDir = tempnam(SetupUtils::GetTmpDir(), 'itop-'); unlink($sDataDir); // I need a directory, not a file... SetupUtils::builddir($sDataDir); // Here is the directory $oZip->extractTo($sDataDir, 'itop-dump.sql'); $sDataFile = $sDataDir . '/itop-dump.sql'; $this->LoadDatabase($sDataFile); unlink($sDataFile); // Update the code // $sDeltaFile = APPROOT . 'data/' . $sEnvironment . '.delta.xml'; if ($oZip->locateName('delta.xml') !== false) { // Extract and rename delta.xml => <env>.delta.xml; file_put_contents($sDeltaFile, $oZip->getFromName('delta.xml')); } else { @unlink($sDeltaFile); } if (is_dir(APPROOT . 'data/production-modules/')) { SetupUtils::rrmdir(APPROOT . 'data/production-modules/'); } if ($oZip->locateName('production-modules/') !== false) { $oZip->extractDirTo(APPROOT . 'data/', 'production-modules/'); } $sConfigFile = APPROOT . 'conf/' . $sEnvironment . '/config-itop.php'; @chmod($sConfigFile, 0770); // Allow overwriting the file $oZip->extractTo(APPROOT . 'conf/' . $sEnvironment, 'config-itop.php'); @chmod($sConfigFile, 0444); // Read-only $oEnvironment = new RunTimeEnvironment($sEnvironment); $oEnvironment->CompileFrom($sEnvironment); }