Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/dtl/database_exporter.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00043 abstract class database_exporter {
00045     protected $mdb;
00047     protected $manager;
00049     protected $schema;
00055     protected $check_schema;
00056 
00066     public function __construct(moodle_database $mdb, $check_schema=true) {
00067         $this->mdb          = $mdb;
00068         $this->manager      = $mdb->get_manager();
00069         $this->schema       = $this->manager->get_install_xml_schema();
00070         $this->check_schema = $check_schema;
00071     }
00072 
00084     public abstract function begin_database_export($version, $release, $timestamp, $description);
00085 
00094     public abstract function begin_table_export(xmldb_table $table);
00095 
00102     public abstract function finish_table_export(xmldb_table $table);
00103 
00108     public abstract function finish_database_export();
00109 
00120     public abstract function export_table_data(xmldb_table $table, $data);
00121 
00131     public function export_database($description=null) {
00132         global $CFG;
00133 
00134         if ($this->check_schema and $errors = $this->manager->check_database_schema($this->schema)) {
00135             $details = '';
00136             foreach ($errors as $table=>$items) {
00137                 $details .= '<div>'.get_string('table').' '.$table.':';
00138                 $details .= '<ul>';
00139                 foreach ($items as $item) {
00140                     $details .= '<li>'.$item.'</li>';
00141                 }
00142                 $details .= '</ul></div>';
00143             }
00144             throw new dbtransfer_exception('exportschemaexception', $details);
00145         }
00146         $tables = $this->schema->getTables();
00147         $this->begin_database_export($CFG->version, $CFG->release, date('c'), $description);
00148         foreach ($tables as $table) {
00149             $rs = $this->mdb->get_recordset_sql('SELECT * FROM {'.$table->getName().'}');
00150             if (!$rs) {
00151                 throw new ddl_table_missing_exception($table->getName());
00152             }
00153             $this->begin_table_export($table);
00154             foreach ($rs as $row) {
00155                 $this->export_table_data($table, $row);
00156             }
00157             $this->finish_table_export($table);
00158         }
00159         $this->finish_database_export();
00160     }
00161 
00162 }
 All Data Structures Namespaces Files Functions Variables Enumerations