## Class mr_db_dump

Description

MR DB Dump

Generates a MySQL dump file from a recordset.

Example:

1. <?php
2. // Create a new instance
3. $dump = new mr_db_dump("$CFG->dataroot/archive/plugin/logs.sql");
4. // Get a resultset
5. $rs = $DB->get_recordset_sql('SELECT * FROM tablename');
6. // Run the dump and zip it up
7. $zipfile = $dump->run('tablename', $rs)->zip();
9. // Later, call clean in some way if you want
10. // to delete any of the files...
11. $dump->clean();
12. ?>

WARNING: Works only with mysqli

- author: Mark Nielsen

Located in /db/dump.php (line 61)

Variable Summary
string $file
int $rowsdumped
Method Summary
mr_db_dump __construct (string $file, [boolean $mustnotexist = true], [boolean $appendtime = true])
mr_db_dump archive (mixed $table, moodle_recordset $rs)
mr_db_dump clean ([boolean $deletezip = true], [boolean $deletesql = true], [boolean $deleteifempty = true])
mr_db_dump dump (string|mr_db_table $table, moodle_recordset $rs, [bool $archive = false])
int get_rows_dumped ()
string get_zip_file ()
mr_db_dump run (mixed $table, moodle_recordset $rs)
mr_db_dump validate_file ()
string zip ()
Variables
string $file (line 74)

Full file path to the SQL dump file

- access: protected

int $rowsdumped = 0 (line 67)

Counter - counts number of rows sent to the dump file

- access: protected

Methods
Constructor __construct (line 84)

Constructor

- throws: coding_exception
- access: public

mr_db_dump __construct (string $file, [boolean $mustnotexist = true], [boolean $appendtime = true])

- string $file: The full path to creat the SQL dump file, EG: $CFG->dataroot.'/archive/plugin/logs.sql'
- boolean $mustnotexist: If the file must not exist beforehand. Prevents overwriting files on accident.
- boolean $appendtime: Append the time to the file name, helps with uniqueness and informative. EG: Appends _YYYYMMDDHHMMSS

archive (line 159)

Run the dump and delete records that get added to the dump

One of the primary entry points. Don't use this method when exporting very very large amounts of rows. It is better to use separate delete SQL to remove the rows.

- throws: coding_exception
- access: public

mr_db_dump archive (mixed $table, moodle_recordset $rs)

- mixed $table: The table name or an instance of mr_db_table
- moodle_recordset $rs: The recordset to iterate over and add to the dump file

clean (line 311)

Cleanup!

Can delete the zip file and the SQL file

- access: public

mr_db_dump clean ([boolean $deletezip = true], [boolean $deletesql = true], [boolean $deleteifempty = true])

- boolean $deletezip: Delete the zip file
- boolean $deletesql: Delete the SQL file
- boolean $deleteifempty: Force the deletion of both files if they are empty

dump (line 172)

Actually runs the dump and optionally the archive

- throws: coding_exception
- access: protected

mr_db_dump dump (string|mr_db_table $table, moodle_recordset $rs, [bool $archive = false])

- string|mr_db_table $table: The table name or an instance of mr_db_table
- moodle_recordset $rs: The recordset to iterate over and add to the dump file
- bool $archive: If true, then records dumped will also be deleted

get_rows_dumped (line 263)

Get the number of rows dumped

- access: public

int get_rows_dumped ()
get_zip_file (line 297)

Get the zip file path (may not exist!)

- access: protected

string get_zip_file ()
run (line 142)

Run the dump

One of the primary entry points.

- throws: coding_exception
- access: public

mr_db_dump run (mixed $table, moodle_recordset $rs)

- mixed $table: The table name or an instance of mr_db_table
- moodle_recordset $rs: The recordset to iterate over and add to the dump file

validate_file (line 110)

Validates the file path

Validation steps:

- The path must be set.
- The file extension must be 'sql'
- The file's directory must exist, but this will try to make it first.
- The file and directory must be writable.

- throws: coding_exception
- access: protected

mr_db_dump validate_file ()
zip (line 273)

Zip the SQL file

- return: The path to the zip file
- throws: coding_exception
- access: public

string zip ()

Documentation generated on Thu, 28 Jun 2012 16:33:48 -0700 by phpDocumentor 1.4.3