コード例 #1
0
 /**
  * Construct
  * @param string $fileName
  */
 public function __construct($fileName)
 {
     $Reader = new GZipReader(FRONTEND_PATH . $fileName);
     while (!$Reader->eof()) {
         $Line = trim($Reader->readLine());
         if (substr($Line, 0, 8) == '{"TABLE"') {
             $TableName = substr($Line, 10, -2);
             $this->NumberOf[$TableName] = 0;
         } elseif ($Line != '' && $Line[0] == '{') {
             $this->NumberOf[$TableName]++;
         }
     }
     $Reader->close();
 }
コード例 #2
0
 /**
  * Import table
  * @param string $TableName
  */
 private function importTable($TableName)
 {
     $Line = $this->Reader->readLine();
     if ($Line[0] != '{') {
         return;
     }
     $CompleteRow = json_decode($Line, true);
     $Row = array_shift($CompleteRow);
     $Columns = array_keys($Row);
     $BulkInsert = new RunalyzeBulkInsert($TableName, $Columns, $this->AccountID);
     while ($Line[0] == '{') {
         $CompleteRow = json_decode($Line, true);
         $ID = key($CompleteRow);
         $Row = current($CompleteRow);
         $Values = array_values($Row);
         if (in_array($TableName, array('runalyze_equipment', 'runalyze_equipment_type', 'runalyze_plugin', 'runalyze_route', 'runalyze_sport', 'runalyze_type', 'runalyze_tag'))) {
             if (isset($this->ExistingData[$TableName][$Values[0]])) {
                 $this->ReplaceIDs[$TableName][$ID] = $this->ExistingData[$TableName][$Values[0]];
             } else {
                 $this->correctValues($TableName, $Row);
                 $this->ReplaceIDs[$TableName][$ID] = $BulkInsert->insert(array_values($Row));
                 $this->Results->addInserts($TableName, 1);
             }
         } elseif ($TableName == 'runalyze_equipment_sport' && $this->equipmentSportRelationDoesExist($Row['sportid'], $Row['equipment_typeid'])) {
             // Hint: Don't insert this relation, it does exist already!
         } else {
             $this->correctValues($TableName, $Row);
             if ($TableName == 'runalyze_training') {
                 $this->ReplaceIDs[$TableName][$ID] = $BulkInsert->insert(array_values($Row));
             } else {
                 $BulkInsert->insert(array_values($Row));
             }
             $this->Results->addInserts($TableName, 1);
         }
         $Line = $this->Reader->readLine();
     }
 }