Changeset 19


Ignore:
Timestamp:
Sep 6, 2019, 9:44:30 AM (5 years ago)
Author:
chronos
Message:
  • Fixed: Teams were not imported correctly. Some of them had empty names.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Database.php

    r10 r19  
    5757    $this->LogFile = dirname(__FILE__).'/../../Query.log';
    5858  }
    59  
     59
    6060
    6161  function Connect($Host, $User, $Password, $Database)
     
    109109      $this->insert_id = $this->PDO->lastInsertId();
    110110    } else
    111     {     
     111    {
    112112      $this->Error = $this->PDO->errorInfo();
    113113      $this->Error = $this->Error[2];
     
    134134    $this->insert_id = $this->PDO->lastInsertId();
    135135  }
    136  
     136
    137137  function GetInsert($Table, $Data)
    138138  {
     
    158158    $this->query($this->GetUpdate($Table, $Condition, $Data));
    159159  }
    160  
     160
    161161  function GetUpdate($Table, $Condition, $Data)
    162162  {
     
    219219  {
    220220  }
    221  
     221
    222222  public function Transaction($Queries)
    223223  {
    224       $this->PDO->beginTransaction();
    225       foreach ($Queries as $Query)
    226       {
    227         $Statement = $this->PDO->prepare($Query);
    228         $Statement->execute();
    229       }         
    230       $this->PDO->commit();
     224    $this->PDO->beginTransaction();
     225    foreach ($Queries as $Query)
     226    {
     227      $Statement = $this->PDO->prepare($Query);
     228      $Statement->execute();
     229    }
     230    if (!$this->PDO->commit())
     231    {
     232      $this->Error = $this->PDO->errorInfo();
     233      $this->Error = $this->Error[2];
     234      if(($this->Error != '') and ($this->ShowSQLError == true))
     235        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     236      throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query);
     237    }
    231238  }
    232239}
  • trunk/index.php

    r18 r19  
    2828  var $Database;
    2929  var $Config;
    30   var $Year;
     30  var $LeaderboardURL;
    3131
    3232  function __construct()
    3333  {
     34    $this->LeaderboardURL = 'https://registrace.teribear.cz/Leaderboard';
    3435  }
    3536
     
    9394  function QueryRunners($Category, $Page = 0, $TeamId = null, $Query = null, $StartNumber = null, $Count = null)
    9495  {
    95       $URL = 'https://registrace.teribear.cz/Leaderboard/Home/GetRunners?category='.$Category;
     96      $URL = $this->LeaderboardURL.'/Home/GetRunners?category='.$Category;
    9697      if ($Page != 0) $URL .= '&page='.$Page;
    9798      if ($TeamId != null) $URL .= '&teamId='.$TeamId;
     
    179180          } else
    180181          {
    181           if (!array_key_exists($Item['TeamId'], $Teams))
    182           {
    183             $TeamId = $NextTeamId;
    184             $Queries[] = $this->Database->GetInsert('Team', array(
    185               'Id' => $TeamId,
    186               'Name' => '',
    187               'WebId' => $Item['TeamId'],
    188               'Year' => $Year,
    189             ));
    190             $Teams[$Item['TeamId']] = array('Id' => $TeamId, 'Distance' => -1);
    191             $NextTeamId++;
    192           } else
    193             $TeamId = $Teams[$Item['TeamId']]['Id'];
     182            if (!array_key_exists($Item['TeamId'], $Teams))
     183            {
     184              $TeamId = $NextTeamId;
     185              $Queries[] = $this->Database->GetInsert('Team', array(
     186                'Id' => $TeamId,
     187                'Name' => '',
     188                'WebId' => $Item['TeamId'],
     189                'Year' => $Year,
     190                'IsFamily' => 0,
     191              ));
     192              $Teams[$Item['TeamId']] = array('Id' => $TeamId, 'Distance' => -1);
     193              $NextTeamId++;
     194            } else
     195              $TeamId = $Teams[$Item['TeamId']]['Id'];
    194196          }
    195197
     
    223225      if (($Item['Type'] == 'team') or ($Item['Type'] == 'rodina'))
    224226      {
     227        if ($Item['Type'] == 'rodina') $IsFamily = 1;
     228          else $IsFamily = 0;
    225229        if (!array_key_exists($Item['GroupId'], $Teams))
    226230        {
    227           if ($Item['Type'] == 'rodina') $IsFamily = 1;
    228             else $IsFamily = 0;
    229231          $Queries[] = $this->Database->GetInsert('Team', array(
    230232            'Id' => $NextTeamId,
     
    240242          $TeamId = $Teams[$Item['GroupId']]['Id'];
    241243
     244
    242245        // Update missing team names
    243         if ($Teams['Name'] == "")
     246        if ($Teams[$Item['GroupId']]['Name'] == "")
    244247        {
    245           $Queries[] = $this->Database->GetUpdate('Team', 'Id='.$Team['Id'], array('Name' => $Item['Name']));
    246           $Teams['Name'] = $Item['Name'];
    247           echo($Team['Name'].' ');
     248          $Queries[] = $this->Database->GetUpdate('Team', 'Id='.$TeamId, array(
     249            'Name' => $Item['Name'],
     250            'IsFamily' => $IsFamily
     251          ));
     252          $Teams[$Item['GroupId']]['Name'] = $Item['Name'];
     253          $Teams[$Item['GroupId']]['IsFamily'] = $IsFamily;
    248254        }
    249255
     
    262268    }
    263269    //print_r($Queries);
     270    //foreach ($Queries as $Query) $this->Database->query($Query);
    264271    $this->Database->Transaction($Queries);
    265272  }
     
    269276    $Time = time();
    270277    $Items = $this->QueryRunnersAll();
    271     //print_r($Items);
    272278    $ItemsWithoutProgress = array();
    273279    foreach ($Items as $Item)
     
    292298        'ItemCount' => count($Items)
    293299      ));
    294       file_put_contents('/home/teribear/www/import/'.$Hash.'.txt', print_r($Items, true));
     300      //file_put_contents('import/'.$Hash.'.txt', print_r($Items, true));
    295301    }
    296302  }
     
    301307    $Output .= '<div class="page-title">Families</div>';
    302308
    303     $Year = 1;
     309    $Year = 0;
    304310    if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != ''))
    305311      $Year = $this->PathItems[count($this->PathItems) - 1] * 1;
     
    419425    $Output .= '<div class="page-title">Teams</div>';
    420426
    421     $Year = 1;
     427    $Year = 0;
    422428    if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != ''))
    423429      $Year = $this->PathItems[count($this->PathItems) - 1] * 1;
     
    537543    $Output = '<div class="page-title">Runners</div>';
    538544
    539     $Year = 1;
     545    $Year = 0;
    540546    if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != ''))
    541547      $Year = $this->PathItems[count($this->PathItems) - 1] * 1;
     
    711717  {
    712718    $Output = '';
    713     $Output .= '<p>This website collects data from offical <a href="http://leaderboard.teribear.cz/">leaderboard</a> site and tracks and presents progress of runners.</p>';
    714     $Output .= '<div class="page-title">Summary '.$Year.'</div>';
     719    $Output .= '<p>This website collects data from offical <a href="'.$this->LeaderboardURL.'">leaderboard</a> site and tracks and presents progress of runners.</p>';
     720    $Output .= '<div class="page-title">Summary</div>';
    715721
    716722    $Year = 0;
     
    772778    $this->Database->Prefix = $this->Config['Database']['Prefix'];
    773779    $this->Database->charset($this->Config['Database']['Charset']);
     780    //$this->Database->ShowSQLError = true;
    774781    $this->PathItems = $this->ProcessURL();
    775782
Note: See TracChangeset for help on using the changeset viewer.