Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

General database importer class

Copyright: 2008 Andrei Bautu
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 218 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: database_importer  - X-Ref

Base class for database import operations. This class implements
basic callbacks for import operations and defines the @see import_database
method as a common method for all importers. In general, subclasses will
override import_database and call other methods in appropriate moments.
Between a single pair of calls to @see begin_database_import and

__construct(moodle_database $mdb, $check_schema=true)   X-Ref
Object constructor.

param: moodle_database $mdb Connection to the target database (a
param: boolean $check_schema - whether or not to check that XML database

set_transaction_mode($mode)   X-Ref
How to use transactions during the import.

param: string $mode 'pertable', 'allinone' or 'none'.

begin_database_import($version, $timestamp)   X-Ref
Callback function. Should be called only once database per import
operation, before any database changes are made. It will check the database
schema if @see check_schema is true

param: float $version the version of the system which generated the data
param: string $timestamp the timestamp of the data (in ISO 8601) format.
return: void

begin_table_import($tablename, $schemaHash)   X-Ref
Callback function. Should be called only once per table import operation,
before any table changes are made. It will delete all table data.

param: string $tablename - the name of the table that will be imported
param: string $schemaHash - the hash of the xmldb_table schema of the table
return: void

finish_table_import($tablename)   X-Ref
Callback function. Should be called only once per table import operation,
after all table changes are made. It will reset table sequences if any.

param: string $tablename
return: void

finish_database_import()   X-Ref
Callback function. Should be called only once database per import
operation, after all database changes are made. It will commit changes.

return: void

import_table_data($tablename, $data)   X-Ref
Callback function. Should be called only once per record import operation, only
between @see begin_table_import and @see finish_table_import calls.
It will insert table data.

param: string $tablename - the name of the table in which data will be
param: object $data - data object (fields and values will be inserted
return: void

import_database()   X-Ref
Common import method

return: void