/** * Base function * * This functions receives the request to generate a dump file for the * database and does so! Only superadmins are allowed to do this! */ public function index() { $sFileName = 'LimeSurvey_' . $sDbName . '_dump_' . dateShift(date('Y-m-d H:i:s'), 'Y-m-d', Yii::app()->getConfig('timeadjust')) . '.sql'; $this->_outputHeaders($sFileName); Yii::app()->loadHelper("admin/backupdb"); outputDatabase(); exit; }
/** * Create a backup of the DataBase * @return array result of backup */ private function _createDbBackup() { Yii::app()->loadHelper("admin/backupdb"); $backupDb = new stdClass(); $basefilename = dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')) . '_' . md5(uniqid(rand(), true)); $sfilename = $this->tempdir . DIRECTORY_SEPARATOR . "backup_db_" . randomChars(20) . "_" . dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')) . ".sql"; $dfilename = $this->tempdir . DIRECTORY_SEPARATOR . "LimeSurvey_database_backup_" . $basefilename . ".zip"; outputDatabase('', false, $sfilename); if (is_file($sfilename) && filesize($sfilename)) { $archive = new PclZip($dfilename); $v_list = $archive->add(array($sfilename), PCLZIP_OPT_REMOVE_PATH, $this->tempdir, PCLZIP_OPT_ADD_TEMP_FILE_ON); unlink($sfilename); if ($v_list == 0) { $backupDb->result = FALSE; $backupDb->message = 'db_backup_zip_failed'; } else { $backupDb->result = TRUE; $backupDb->message = htmlspecialchars($dfilename); } } else { $backupDb->result = FALSE; $backupDb->message = htmlspecialchars(db_backup_failed); } return $backupDb; }
function step3() { $clang = $this->getController()->lang; $buildnumber = Yii::app()->getConfig("buildnumber"); $tempdir = Yii::app()->getConfig("tempdir"); $updatebuild = getGlobalSetting("updatebuild"); //$_POST=$this->input->post(); $rootdir = Yii::app()->getConfig("rootdir"); $publicdir = Yii::app()->getConfig("publicdir"); $tempdir = Yii::app()->getConfig("tempdir"); $aDatabasetype = Yii::app()->db->getDriverName(); $aData = array('clang' => $clang); // Request the list with changed files from the server if (!isset(Yii::app()->session['updateinfo'])) { if ($updateinfo['error'] == 1) { } } else { $updateinfo = Yii::app()->session['updateinfo']; } $aData['updateinfo'] = $updateinfo; // okay, updateinfo now contains all necessary updateinformation // Create DB and file backups now $basefilename = dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')) . '_' . md5(uniqid(rand(), true)); //Now create a backup of the files to be delete or modified $filestozip = array(); foreach ($updateinfo['files'] as $file) { if (is_file($publicdir . $file['file']) === true) { $filestozip[] = $publicdir . $file['file']; } } Yii::app()->loadLibrary("admin/pclzip"); $archive = new PclZip($tempdir . DIRECTORY_SEPARATOR . 'LimeSurvey_files_backup_' . $basefilename . '.zip'); $v_list = $archive->add($filestozip, PCLZIP_OPT_REMOVE_PATH, $publicdir); if ($v_list == 0) { $aFileBackup = array('class' => 'error', 'text' => sprintf($clang->gT("Error on file backup: %s"), $archive->errorInfo(true))); } else { $aFileBackup = array('class' => 'success', 'text' => sprintf($clang->gT("File backup created: %s"), $tempdir . DIRECTORY_SEPARATOR . 'LimeSurvey_files_backup_' . $basefilename . '.zip')); } $aData['aFileBackup'] = $aFileBackup; $aData['databasetype'] = $aDatabasetype; //TODO: Yii provides no function to backup the database. To be done after dumpdb is ported if (in_array($aDatabasetype, array('mysql', 'mysqli'))) { if (in_array($aDatabasetype, array('mysql', 'mysqli')) && Yii::app()->getConfig('demoMode') != true) { Yii::app()->loadHelper("admin/backupdb"); $sfilename = $tempdir . DIRECTORY_SEPARATOR . "backup_db_" . randomChars(20) . "_" . dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')) . ".sql"; $dfilename = $tempdir . DIRECTORY_SEPARATOR . "LimeSurvey_database_backup_" . $basefilename . ".zip"; outputDatabase('', false, $sfilename); // Before try to zip: test size of file if (is_file($sfilename) && filesize($sfilename)) { $archive = new PclZip($dfilename); $v_list = $archive->add(array($sfilename), PCLZIP_OPT_REMOVE_PATH, $tempdir, PCLZIP_OPT_ADD_TEMP_FILE_ON); unlink($sfilename); if ($v_list == 0) { // Unknow reason because backup of DB work ? $aSQLBackup = array('class' => 'warning', 'text' => $clang->gT("Unable to backup your database for unknow reason. Before proceeding please backup your database using a backup tool!")); } else { $aSQLBackup = array('class' => 'success', 'text' => sprintf($clang->gT('DB backup created: %s'), htmlspecialchars($dfilename))); } } else { $aSQLBackup = array('class' => 'warning', 'text' => $clang->gT("Unable to backup your database for unknow reason. Before proceeding please backup your database using a backup tool!")); } } } else { $aSQLBackup = array('class' => 'warning', 'text' => $clang->gT('Database backup functionality is currently not available for your database type. Before proceeding please backup your database using a backup tool!')); } $aData['aSQLBackup'] = $aSQLBackup; if ($aFileBackup['class'] == "success" && $aSQLBackup['class'] == "success") { $aData['result'] = "success"; } elseif ($aFileBackup['class'] == "error" || $aSQLBackup['class'] == "error") { $aData['result'] = "error"; } else { $aData['result'] = "warning"; } $this->_renderWrappedTemplate('update', 'step3', $aData); }
function step3() { $clang = $this->getController()->lang; $buildnumber = Yii::app()->getConfig("buildnumber"); $tempdir = Yii::app()->getConfig("tempdir"); $updatekey = getGlobalSetting("updatekey"); $updatebuild = getGlobalSetting("updatebuild"); //$_POST=$this->input->post(); $rootdir = Yii::app()->getConfig("rootdir"); $publicdir = Yii::app()->getConfig("publicdir"); $tempdir = Yii::app()->getConfig("tempdir"); $aDatabasetype = Yii::app()->db->getDriverName(); $aData = array('clang' => $clang); // Request the list with changed files from the server if (!isset(Yii::app()->session['updateinfo'])) { if ($updateinfo['error'] == 1) { setGlobalSetting('updatekey', ''); } } else { $updateinfo = Yii::app()->session['updateinfo']; } $aData['updateinfo'] = $updateinfo; // okay, updateinfo now contains all necessary updateinformation // Create DB and file backups now $basefilename = dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')) . '_' . md5(uniqid(rand(), true)); //Now create a backup of the files to be delete or modified $filestozip = array(); foreach ($updateinfo['files'] as $file) { if (is_file($publicdir . $file['file']) === true) { $filestozip[] = $publicdir . $file['file']; } } Yii::app()->loadLibrary("admin/pclzip/pclzip"); $archive = new PclZip($tempdir . DIRECTORY_SEPARATOR . 'LimeSurvey_files_backup_' . $basefilename . '.zip'); $v_list = $archive->add($filestozip, PCLZIP_OPT_REMOVE_PATH, $publicdir); if ($v_list == 0) { die("Error : " . $archive->errorInfo(true)); } $aData['sFilesArchive'] = $tempdir . DIRECTORY_SEPARATOR . 'LimeSurvey_files_backup_' . $basefilename . '.zip'; $aData['databasetype'] = $aDatabasetype; //TODO: Yii provides no function to backup the database. To be done after dumpdb is ported if (in_array($aDatabasetype, array('mysql', 'mysqli'))) { if (in_array($aDatabasetype, array('mysql', 'mysqli')) && Yii::app()->getConfig('demoMode') != true) { Yii::app()->loadHelper("admin/backupdb"); $sfilename = $tempdir . DIRECTORY_SEPARATOR . "backup_db_" . randomChars(20) . "_" . dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')) . ".sql"; $dfilename = $tempdir . DIRECTORY_SEPARATOR . "LimeSurvey_database_backup_" . $basefilename . ".sql.gz"; outputDatabase('', false, $sfilename); $archive = new PclZip($dfilename); $v_list = $archive->add(array($sfilename), PCLZIP_OPT_REMOVE_PATH, $tempdir); unlink($sfilename); if ($v_list == 0) { die("Error : " . $archive->errorInfo(true)); } $aData['sSQLArchive'] = $dfilename; } } $this->_renderWrappedTemplate('update', 'step3', $aData); }