Exemplo n.º 1
0
 public static function import($datafile)
 {
     db('import')->echoOn();
     db('import')->beginTransaction();
     $data = Yaml::read($datafile);
     $schema = $data['schema'];
     $tables = $data['data'];
     $automap = array();
     foreach ($tables as $tableName => $rows) {
         foreach ($rows as $row) {
             $values = array();
             foreach ($row as $fieldName => $fieldValue) {
                 if (!isset($schema[$tableName]['auto']) || !in_array($fieldName, $schema[$tableName]['auto'])) {
                     $values[$fieldName] = $fieldValue;
                 }
             }
             if (isset($schema[$tableName]['refs'])) {
                 foreach ($schema[$tableName]['refs'] as $fieldName => $referee) {
                     $values[$fieldName] = $automap[$referee[0]][$referee[1]][$row[$fieldName]];
                 }
             }
             $id = db('import')->insertArray($tableName, $values);
             if (isset($row['id'])) {
                 $automap[$tableName]['id'][$row['id']] = $id;
             }
         }
     }
     db('import')->rollbackTransaction();
 }
Exemplo n.º 2
0
 public static function insist($file, $prefix = NULL)
 {
     if ($prefix) {
         $root =& self::getReference($prefix);
     } else {
         $root =& self::$info;
     }
     $root = self::mergeArray($root, Yaml::read($file), false);
 }
Exemplo n.º 3
0
 public function testRead()
 {
     $data = [['key1' => 'value1'], ['key2' => 'value2']];
     $fileReader = new DummyFileReader();
     $fileReader->write(json_encode($data));
     $yaml = new Yaml($fileReader, new Parser(), new Dumper());
     $result = $yaml->read();
     $this->assertSame($data, $result);
 }
Exemplo n.º 4
0
 public static function insist($file, $prefix = NULL)
 {
     // echo "inisting: $file<br>";
     if ($prefix) {
         $root =& self::getReference($prefix);
     } else {
         $root =& self::$info;
     }
     $root = self::mergeArray($root, Yaml::read($file));
 }
Exemplo n.º 5
0
 /**
  * @covers Xoops\Core\Yaml::save
  * @covers Xoops\Core\Yaml::read
  */
 public function testSaveAndRead()
 {
     $tmpfname = tempnam(sys_get_temp_dir(), 'TEST');
     $inputArray = array('one' => 1, 'two' => array(1, 2), 'three' => '');
     $byteCount = Yaml::save($inputArray, $tmpfname);
     $this->assertFalse($byteCount === false);
     $this->assertGreaterThan(0, $byteCount);
     $outputArray = Yaml::read($tmpfname);
     $this->assertTrue(is_array($outputArray));
     $this->assertSame($inputArray, $outputArray);
     unlink($tmpfname);
 }
Exemplo n.º 6
0
 public static function insist($file, $prefix = NULL)
 {
     $root = $prefix ? self::getReference($prefix) : self::$info;
     self::$info = self::mergeArray($root, Yaml::read($file));
 }