Exemplo n.º 1
0
 /**
  * Initialise CFG using data from fresh new install.
  * @static
  */
 public static function initialise_cfg()
 {
     global $CFG, $DB;
     if (!file_exists("{$CFG->dataroot}/phpunit/tabledata.ser")) {
         // most probably PHPUnit CLI installer
         return;
     }
     if (!$DB->get_manager()->table_exists('config') or !$DB->count_records('config')) {
         @unlink("{$CFG->dataroot}/phpunit/tabledata.ser");
         @unlink("{$CFG->dataroot}/phpunit/versionshash.txt");
         self::$tabledata = null;
         return;
     }
     $data = self::get_tabledata();
     foreach ($data['config'] as $record) {
         $name = $record->name;
         $value = $record->value;
         if (property_exists($CFG, $name)) {
             // config.php settings always take precedence
             continue;
         }
         $CFG->{$name} = $value;
     }
 }
Exemplo n.º 2
0
 /**
  * Returns contents of all tables right after installation.
  * @static
  * @return array $table=>$records
  */
 protected static function get_tabledata()
 {
     global $CFG;
     if (!file_exists("{$CFG->dataroot}/phpunit/tabledata.ser")) {
         // not initialised yet
         return array();
     }
     if (!isset(self::$tabledata)) {
         $data = file_get_contents("{$CFG->dataroot}/phpunit/tabledata.ser");
         self::$tabledata = unserialize($data);
     }
     if (!is_array(self::$tabledata)) {
         phpunit_bootstrap_error(1, 'Can not read dataroot/phpunit/tabledata.ser or invalid format, reinitialize test database.');
     }
     return self::$tabledata;
 }