Mage_Backup_Model_Db Class Reference

List of all members.

Public Member Functions

 getResource ()
 getTables ()
 getTableCreateScript ($tableName, $addDropIfExists=false)
 getTableDataDump ($tableName)
 getHeader ()
 getFooter ()
 renderSql ()
 createBackup (Mage_Backup_Model_Backup $backup)

Public Attributes

const BUFFER_LENGTH = 524288


Detailed Description

Definition at line 35 of file Db.php.


Member Function Documentation

createBackup ( Mage_Backup_Model_Backup backup  ) 

Create backup and stream write to adapter

Parameters:
Mage_Backup_Model_Backup $backup
Returns:
Mage_Backup_Model_Db

Definition at line 101 of file Db.php.

00102     {
00103         $backup->open(true);
00104 
00105         $this->getResource()->beginTransaction();
00106 
00107         $tables = $this->getResource()->getTables();
00108 
00109         $backup->write($this->getResource()->getHeader());
00110 
00111         foreach ($tables as $table) {
00112             $backup->write($this->getResource()->getTableHeader($table) . $this->getResource()->getTableDropSql($table) . "\n");
00113             $backup->write($this->getResource()->getTableCreateSql($table, false) . "\n");
00114 
00115             $tableStatus = $this->getResource()->getTableStatus($table);
00116 
00117             if ($tableStatus->getRows()) {
00118                 $backup->write($this->getResource()->getTableDataBeforeSql($table));
00119 
00120                 if ($tableStatus->getDataLength() > self::BUFFER_LENGTH) {
00121                     if ($tableStatus->getAvgRowLength() < self::BUFFER_LENGTH) {
00122                         $limit = floor(self::BUFFER_LENGTH / $tableStatus->getAvgRowLength());
00123                         $multiRowsLength = ceil($tableStatus->getRows() / $limit);
00124                     }
00125                     else {
00126                         $limit = 1;
00127                         $multiRowsLength = $tableStatus->getRows();
00128                     }
00129                 }
00130                 else {
00131                     $limit = $tableStatus->getRows();
00132                     $multiRowsLength = 1;
00133                 }
00134 
00135                 for ($i = 0; $i < $multiRowsLength; $i ++) {
00136                     $backup->write($this->getResource()->getTableDataSql($table, $limit, $i*$limit));
00137                 }
00138 
00139                 $backup->write($this->getResource()->getTableDataAfterSql($table));
00140             }
00141         }
00142         $backup->write($this->getResource()->getTableForeignKeysSql());
00143         $backup->write($this->getResource()->getFooter());
00144 
00145         $this->getResource()->commitTransaction();
00146 
00147         $backup->close();
00148 
00149         return $this;
00150     }

getFooter (  ) 

Definition at line 75 of file Db.php.

00076     {
00077         return $this->getResource()->getFooter();
00078     }

getHeader (  ) 

Definition at line 70 of file Db.php.

00071     {
00072         return $this->getResource()->getHeader();
00073     }

getResource (  ) 

Retrieve resource model

Returns:
Mage_Backup_Model_Mysql4_Db

Definition at line 50 of file Db.php.

00051     {
00052         return Mage::getResourceSingleton('backup/db');
00053     }

getTableCreateScript ( tableName,
addDropIfExists = false 
)

Definition at line 60 of file Db.php.

00061     {
00062         return $this->getResource()->getTableCreateScript($tableName, $addDropIfExists);
00063     }

getTableDataDump ( tableName  ) 

Definition at line 65 of file Db.php.

00066     {
00067         return $this->getResource()->getTableDataDump($tableName);
00068     }

getTables (  ) 

Definition at line 55 of file Db.php.

00056     {
00057         return $this->getResource()->getTables();
00058     }

renderSql (  ) 

Definition at line 80 of file Db.php.

00081     {
00082         ini_set('max_execution_time', 0);
00083         $sql = $this->getHeader();
00084 
00085         $tables = $this->getTables();
00086         foreach ($tables as $tableName) {
00087             $sql.= $this->getTableCreateScript($tableName, true);
00088             $sql.= $this->getTableDataDump($tableName);
00089         }
00090 
00091         $sql.= $this->getFooter();
00092         return $sql;
00093     }


Member Data Documentation

const BUFFER_LENGTH = 524288

Buffer length for multi rows default 512 Kb

Definition at line 43 of file Db.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:33 2009 for Magento by  doxygen 1.5.8