begin_database_import($attributes['version'], $attributes['timestamp']); break; case 'table' : if (isset($this->current_table)) { throw new dbtransfer_exception('malformedxmlexception'); } if (empty($attributes['name']) || empty($attributes['schemaHash'])) { throw new dbtransfer_exception('malformedxmlexception'); } $this->current_table = $attributes['name']; $this->begin_table_import($this->current_table, $attributes['schemaHash']); break; case 'record' : if (isset($this->current_row) || !isset($this->current_table)) { throw new dbtransfer_exception('malformedxmlexception'); } $this->current_row = new object(); break; case 'field' : if (isset($this->current_field) || !isset($this->current_row)) { throw new dbtransfer_exception('malformedxmlexception'); } $this->current_field = $attributes['name']; $this->current_data = ''; if (isset($attributes['value']) and $attributes['value'] === 'null') { $this->current_data_is_null = true; } else { $this->current_data_is_null = false; } break; default : throw new dbtransfer_exception('malformedxmlexception'); } } /** * Callback function. Called by the XML parser for closing tags processing. * * @param resource $parser XML parser resource. * @param string $tag name of opening tag * @return void */ protected function tag_close($parser, $tag) { switch ($tag) { case 'moodle_database' : $this->finish_database_import(); break; case 'table' : $this->finish_table_import($this->current_table); $this->current_table = null; break; case 'record' : $this->import_table_data($this->current_table, $this->current_row); $this->current_row = null;; break; case 'field' : $field = $this->current_field; if ($this->current_data_is_null) { $this->current_row->$field = null; } else { $this->current_row->$field = $this->current_data; } $this->current_field = null; $this->current_data = null; $this->current_data_is_null = null; break; default : throw new dbtransfer_exception('malformedxmlexception'); } } /** * Callback function. Called by the XML parser for character data processing. * * @param resource $parser XML parser resource. * @param string $data character data to be processed * @return void */ protected function cdata($parser, $cdata) { if (isset($this->current_field)) { $this->current_data .= $cdata; } } }