Exemplo n.º 1
0
 /**
  * Load data from XML to the structure
  */
 function arr2xmldb_structure($xmlarr)
 {
     global $CFG;
     $result = true;
     /// Debug the structure
     /// traverse_xmlize($xmlarr);                   //Debug
     /// print_object ($GLOBALS['traverse_array']);  //Debug
     /// $GLOBALS['traverse_array']="";              //Debug
     /// Process structure attributes (path, comment and version)
     if (isset($xmlarr['XMLDB']['@']['PATH'])) {
         $this->path = trim($xmlarr['XMLDB']['@']['PATH']);
     } else {
         $this->errormsg = 'Missing PATH attribute';
         $this->debug($this->errormsg);
         $result = false;
     }
     if (isset($xmlarr['XMLDB']['@']['VERSION'])) {
         $this->version = trim($xmlarr['XMLDB']['@']['VERSION']);
     } else {
         $this->errormsg = 'Missing VERSION attribute';
         $this->debug($this->errormsg);
         $result = false;
     }
     if (isset($xmlarr['XMLDB']['@']['COMMENT'])) {
         $this->comment = trim($xmlarr['XMLDB']['@']['COMMENT']);
     } else {
         if (!empty($CFG->xmldbdisablecommentchecking)) {
             $this->comment = '';
         } else {
             $this->errormsg = 'Missing COMMENT attribute';
             $this->debug($this->errormsg);
             $result = false;
         }
     }
     /// Iterate over tables
     if (isset($xmlarr['XMLDB']['#']['TABLES']['0']['#']['TABLE'])) {
         foreach ($xmlarr['XMLDB']['#']['TABLES']['0']['#']['TABLE'] as $xmltable) {
             if (!$result) {
                 //Skip on error
                 continue;
             }
             $name = trim($xmltable['@']['NAME']);
             $table = new xmldb_table($name);
             $table->arr2xmldb_table($xmltable);
             $this->tables[] = $table;
             if (!$table->isLoaded()) {
                 $this->errormsg = 'Problem loading table ' . $name;
                 $this->debug($this->errormsg);
                 $result = false;
             }
         }
     } else {
         $this->errormsg = 'Missing TABLES section';
         $this->debug($this->errormsg);
         $result = false;
     }
     /// Perform some general checks over tables
     if ($result && $this->tables) {
         /// Check tables names are ok (lowercase, a-z _-)
         if (!$this->checkNameValues($this->tables)) {
             $this->errormsg = 'Some TABLES name values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Check previous & next are ok (duplicates and existing tables)
         $this->fixPrevNext($this->tables);
         if ($result && !$this->checkPreviousNextValues($this->tables)) {
             $this->errormsg = 'Some TABLES previous/next values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Order tables
         if ($result && !$this->orderTables($this->tables)) {
             $this->errormsg = 'Error ordering the tables';
             $this->debug($this->errormsg);
             $result = false;
         }
     }
     /// Iterate over statements
     if (isset($xmlarr['XMLDB']['#']['STATEMENTS']['0']['#']['STATEMENT'])) {
         foreach ($xmlarr['XMLDB']['#']['STATEMENTS']['0']['#']['STATEMENT'] as $xmlstatement) {
             if (!$result) {
                 //Skip on error
                 continue;
             }
             $name = trim($xmlstatement['@']['NAME']);
             $statement = new xmldb_statement($name);
             $statement->arr2xmldb_statement($xmlstatement);
             $this->statements[] = $statement;
             if (!$statement->isLoaded()) {
                 $this->errormsg = 'Problem loading statement ' . $name;
                 $this->debug($this->errormsg);
                 $result = false;
             }
         }
     }
     /// Perform some general checks over statements
     if ($result && $this->statements) {
         /// Check statements names are ok (lowercase, a-z _-)
         if (!$this->checkNameValues($this->statements)) {
             $this->errormsg = 'Some STATEMENTS name values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Check previous & next are ok (duplicates and existing statements)
         $this->fixPrevNext($this->statements);
         if ($result && !$this->checkPreviousNextValues($this->statements)) {
             $this->errormsg = 'Some STATEMENTS previous/next values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Order statements
         if ($result && !$this->orderStatements($this->statements)) {
             $this->errormsg = 'Error ordering the statements';
             $this->debug($this->errormsg);
             $result = false;
         }
     }
     /// Set some attributes
     if ($result) {
         $this->loaded = true;
     }
     $this->calculateHash();
     return $result;
 }