/** * Retrieve new instance of WireDatabaseBackups ready to use with this connection * * See WireDatabaseBackup class for usage. * * @return WireDatabaseBackup * @throws WireException|Exception on fatal error * */ public function backups() { $path = $this->wire('config')->paths->assets . 'backups/database/'; if (!is_dir($path)) { wireMkdir($path, true); if (!is_dir($path)) { throw new WireException("Unable to create path for backups: {$path}"); } } $backups = new WireDatabaseBackup($path); $backups->setDatabase($this); $backups->setDatabaseConfig($this->wire('config')); $backups->setBackupOptions(array('user' => $this->wire('user')->name)); return $backups; }
/** * Import profile SQL dump * */ protected function profileImportSQL($database, $file1, $file2, array $options = array()) { $defaults = array('dbEngine' => 'MyISAM', 'dbCharset' => 'utf8'); $options = array_merge($defaults, $options); if (self::TEST_MODE) { return; } $restoreOptions = array(); $replace = array(); if ($options['dbEngine'] != 'MyISAM') { $replace['ENGINE=MyISAM'] = "ENGINE={$options['dbEngine']}"; $this->warn("Engine changed to '{$options['dbEngine']}', please keep an eye out for issues."); } if ($options['dbCharset'] != 'utf8') { $replace['CHARSET=utf8'] = "CHARSET={$options['dbCharset']}"; $this->warn("Character set has been changed to '{$options['dbCharset']}', please keep an eye out for issues."); } if (count($replace)) { $restoreOptions['findReplaceCreateTable'] = $replace; } require "./wire/core/WireDatabaseBackup.php"; $backup = new WireDatabaseBackup(); $backup->setDatabase($database); if ($backup->restoreMerge($file1, $file2, $restoreOptions)) { $this->ok("Imported database file: {$file1}"); $this->ok("Imported database file: {$file2}"); } else { foreach ($backup->errors() as $error) { $this->err($error); } } }