public static function getBackupNameWithUniqueCode($preferences) { if (!isset($preferences)) { return null; } global $Out; $name = synch_Backup_controller::getItemFromPreferences($preferences, 'backup_name'); $uniqueCode = synch_Backup_controller::getItemFromPreferences($preferences, 'backup_unique_code'); // append the unique code to the backup name $strings = explode('.', $name); if (!is_array($strings)) { // no file extension return $name . '-' . $uniqueCode; } $strings[count($strings) - 2] .= '-' . $uniqueCode; return implode('.', $strings); }
public function restoreMergedBackup($dataItemId, $files, $session) { global $CFG; $page = new stdClass(); //Move the merged backup file from the session folder to the course folder // Move the backups from the course directory into synch/sessions/sessionid/backups with the serverid appended the file name // Generate a new file name from the original backup file and the local server id //$newFileName = $this->createSessionBackupFileName($preferences); $sessionBackupFileName = $files['merged']; // Generate the path to the session backup folder $sessionBackupPath = $this->createSessionBackupPath($session); // Does the merge file exist if (!FileSystem::exists($sessionBackupPath . '/' . $sessionBackupFileName, 'f')) { return false; } // Move the session merge file to the course backup folder. if (1) { // fudge for testing in development $courseBackupFileName = FileSystem::removeFromFileName($sessionBackupFileName, $CFG->synch->merge_file_suffix); $courseBackupFileName = FileSystem::removeFromFileName($courseBackupFileName, synch_backup_controller::getUniqueCodeFromFileName($sessionBackupFileName)); // Do we need to update the file name within the preferences. We will be passing // the file name and from then on it shouldn't be required. $courseId = SynchContentHierarchy::getIdFromDataItemId($dataItemId); $courseBackupPath = synch_Backup_controller::createBackupFilePath($courseId); // Create the folder structure if necessary FileSystem::createFoldersFromPath($courseBackupPath); $moved = FileSystem::copyFile($sessionBackupPath . '/' . $sessionBackupFileName, $courseBackupPath . '/' . $courseBackupFileName); } else { $moved = true; } if (!$moved) { return false; } $preferences = new Object(); $preferences->course_id = $courseId; $preferences->backup_name = $courseBackupFileName; $preferences->backup_unique_code = synch_backup_controller::getUniqueCodeFromFileName($sessionBackupFileName); global $SynchServerController; // If there are changes from the remote Moodle restore to the local Moodle $remoteServerId = $SynchServerController->getRemoteServerId(); if ($this->getSessionHasChangesByServerId($remoteServerId, $session)) { // Call the restoreCourse method of SynchBackupController $restored = synch_backup_controller::restoreCourse($preferences, $session); } return $restored; }