function create($description) { global $addslashes, $moduleFactory; if ($this->getNumAvailable() >= AT_COURSE_BACKUPS) { return FALSE; } $timestamp = time(); $zipfile = new zipfile(); $package_identifier = VERSION . "\n\n\n" . 'Do not change the first line of this file it contains the ATutor version this backup was created with.'; $zipfile->add_file($package_identifier, 'atutor_backup_version', $timestamp); // backup course properties. ONLY BANNER FOR NOW. require_once AT_INCLUDE_PATH . 'classes/CSVExport.class.php'; $CSVExport = new CSVExport(); $now = time(); $sql = 'SELECT banner FROM ' . TABLE_PREFIX . 'courses WHERE course_id=' . $this->course_id; $properties = $CSVExport->export($sql, $course_id); $zipfile->add_file($properties, 'properties.csv', $now); // backup modules $modules = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED | AT_MODULE_STATUS_DISABLED); $keys = array_keys($modules); foreach ($keys as $module_name) { $module =& $modules[$module_name]; $module->backup($this->course_id, $zipfile); } $zipfile->close(); $system_file_name = md5($timestamp); if (!is_dir(AT_BACKUP_DIR)) { @mkdir(AT_BACKUP_DIR); } if (!is_dir(AT_BACKUP_DIR . $this->course_id)) { @mkdir(AT_BACKUP_DIR . $this->course_id); } $zipfile->write_file(AT_BACKUP_DIR . $this->course_id . DIRECTORY_SEPARATOR . $system_file_name . '.zip'); $row['description'] = $addslashes($description); $row['contents'] = addslashes(serialize($table_counters)); $row['system_file_name'] = $system_file_name; $row['file_size'] = $zipfile->get_size(); $row['file_name'] = $this->generateFileName(); $this->add($row); return TRUE; }
/** * Backup this module for a given course * @access public * @param int $course_id ID of the course to backup * @param object $zipfile a reference to a zipfile object * @author Joel Kronenberg */ function backup($course_id, &$zipfile) { static $CSVExport; if (!isset($CSVExport)) { require_once AT_INCLUDE_PATH . 'classes/CSVExport.class.php'; $CSVExport = new CSVExport(); } $now = time(); if ($this->isBackupable()) { require $this->_module_path . $this->_directoryName . '/module_backup.php'; if (isset($sql)) { foreach ($sql as $file_name => $table_sql) { $content = $CSVExport->export($table_sql, $course_id); if ($content) { $zipfile->add_file($content, $file_name . '.csv', $now); } } } if (isset($dirs)) { foreach ($dirs as $dir => $path) { $path = str_replace('?', $course_id, $path); $zipfile->add_dir($path, $dir); } } } }