Post by richard » Fri Aug 14, 2009 12:57 am

Hello Daniel..

Got a fresh install of OC 1.3.1 and tried the DB backup option on the admin.
Please see below:
http _localhost_opencart131_admin_index.php route=tool_backup_backup.png

http _localhost_opencart131_admin_index.php route=tool_backup_backup.png (6.99 KiB) Viewed 855 times

Thanks.
:)

Image a point in time
http://richarrdg.tumblr.com/


New member

Posts

Joined
Wed Jul 08, 2009 2:09 pm

Post by JNeuhoff » Fri Aug 14, 2009 3:05 am

Yes, it is a bug. Daniel has hardcoded 'opencart_dev' strings in there. Use the following file for admin/model/tool/backup.php:

Code: Select all

<?php
class ModelToolBackup extends Model {
	public function restore($sql) {
		foreach (explode(";\n", $sql) as $sql) {
    		$sql = trim($sql);
    		
			if ($sql) {
      			$this->db->query($sql);
    		}
  		}
	}
	
	public function backup() {
		$output = '';
		
		$table_query = $this->db->query("SHOW TABLES FROM `" . DB_DATABASE . "`");

		foreach ($table_query->rows as $table) {
			if (DB_PREFIX) {
				if (strpos($table["Tables_in_".DB_DATABASE], DB_PREFIX) === FALSE) {
					$status = FALSE;
				} else {
					$status = TRUE;
				}
			} else {
				$status = TRUE;
			}
			
			if ($status) {
				$output .= 'TRUNCATE TABLE `' . $table["Tables_in_".DB_DATABASE] . '`;' . "\n\n";
			
				$query = $this->db->query("SELECT * FROM `" . $table["Tables_in_".DB_DATABASE] . "`");
				
				foreach ($query->rows as $result) {
					$fields = '';
					
					foreach (array_keys($result) as $value) {
						$fields .= '`' . $value . '`, ';
					}
					
					$values = '';
					
					foreach (array_values($result) as $value) {
						$value = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $value);
						$value = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $value);
						$value = str_replace('\\', '\\\\',	$value);
						$value = str_replace('\'', '\\\'',	$value);
						$value = str_replace('\\\n', '\n',	$value);
						$value = str_replace('\\\r', '\r',	$value);
						$value = str_replace('\\\t', '\t',	$value);			
						
						$values .= '\'' . $value . '\', ';
					}
					
					$output .= 'INSERT INTO `' . $table["Tables_in_".DB_DATABASE] . '` (' . preg_replace('/, $/', '', $fields) . ') VALUES (' . preg_replace('/, $/', '', $values) . ');' . "\n";
				}
				
				$output .= "\n\n";
			}
		}

		return $output;	
	}
}
?>

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Daniel » Fri Aug 14, 2009 4:06 am

shit!

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm
Who is online

Users browsing this forum: No registered users and 12 guests