Ticket #1919: mythmusic_schema_mythweb_schema_only.diff

File mythmusic_schema_mythweb_schema_only.diff, 7.7 KB (added by Colin Guthrie <mythtv@…>, 14 years ago)

v2 Myth Web Only Schema Fixup (No change)

  • handler.php

     
    9696
    9797        /**** If alphalink set, then change offset to new value ****/
    9898        if ($_GET['alphalink']) {
    99             $alphalink = $_GET['alphalink'];
    100             $result=mysql_query("select count(1) from musicmetadata where upper(artist) < ".escape($alphalink));
    101             $alphaoffset=mysql_fetch_row($result);
    102             $this->offset=$alphaoffset[0];
    103             mysql_free_result($result);
     99            $alphalink = mysql_real_escape_string($_GET['alphalink']);
     100
     101            $result = mysql_query(sprintf("SELECT COUNT(*) FROM music_songs ".
     102                                          "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id ".
     103                                          "WHERE UPPER(music_artists.artist_name) < %s ".
     104                                          "ORDER BY music_artists.artist_name;",
     105                                          escape($_GET['alphalink'])));
     106            if ($result)
     107                        {
     108                $alphaoffset=mysql_fetch_row($result);
     109                $this->offset=$alphaoffset[0];
     110                mysql_free_result($result);
     111            }
    104112        }
    105113
    106114        if($_GET['filterPlaylist'])
     
    193201
    194202    function prepFilter()
    195203    {
    196         $prevFilter=0;
    197         $thisFilter="";
     204        $this->filter="1=1"; // A true statement that will always return everything in SQL.
    198205
    199206        if($this->filterPlaylist != "_All_")
    200207        {
    201             $playlistResult = mysql_query("select playlistid,name,songlist,hostname from musicplaylist where playlistid=".escape($this->filterPlaylist));
     208            $playlistResult = mysql_query("SELECT playlist_id,playlist_name,playlist_songs,hostname FROM music_playlists WHERE playlist_id=".escape($this->filterPlaylist));
    202209            if($playlistResult)
    203210            {
    204211                if(mysql_num_rows($playlistResult)==1)
    205212                {
    206213                    $row=mysql_fetch_row($playlistResult);
    207                     if($row)
     214                    if($row && !empty($row[2]))
    208215                    {
    209 
    210216                        $this->filterSonglist=$row[2];
    211                         if($prevFilter==1)
    212                             $this->filter=$this->filter . "and intid in (" . $this->filterSonglist . ")";
    213                         else
    214                         {
    215                             $this->filter="intid in (" . $this->filterSonglist . ")";
    216                             $prevFilter=1;
    217                         }
    218217
    219                         $this->keepFilters="&amp;filterPlaylist=" . urlencode($this->filterPlaylist);
    220 
     218                        $this->filter .= " AND song_id IN (" . $this->filterSonglist . ")";
     219                        $this->keepFilters .= "&amp;filterPlaylist=" . urlencode($this->filterPlaylist);
    221220                    }
    222221                }
    223222            }
     
    225224
    226225        if($this->filterArtist != "_All_" )
    227226        {
    228             if($prevFilter==1)
    229                 $this->filter=$this->filter . "and artist=".escape($this->filterArtist);
    230             else
    231             {
    232                 $this->filter="artist=".escape($this->filterArtist);
    233                 $prevFilter=1;
    234             }
    235 
    236             $this->keepFilters="&amp;filterArtist=" . urlencode($this->filterArtist);
    237 
     227            $this->filter .= " AND artist_name=".escape($this->filterArtist);
     228            $this->keepFilters .= "&amp;filterArtist=" . urlencode($this->filterArtist);
    238229        }
     230
    239231        if($this->filterAlbum != "_All_")
    240232        {
    241             if($prevFilter==1)
    242             {
    243                 $this->filter= $this->filter . "and album=\"" . $this->filterAlbum . "\"";
    244             }
    245             else
    246             {
    247                 $this->filter="album=\"" . $this->filterAlbum . "\"";
    248                 $prevFilter=1;
    249             }
    250             $this->keepFilters =$this->keepFilters . "&amp;filterAlbum=" . urlencode($this->filterAlbum) ;
    251 
     233            $this->filter .= " AND album_name=" . escape($this->filterAlbum);
     234            $this->keepFilters .= "&amp;filterAlbum=" . urlencode($this->filterAlbum) ;
    252235        }
     236
    253237        if($this->filterGenre != "_All_")
    254238        {
    255             if($prevFilter==1)
    256             {
    257                 $this->filter= $this->filter . "and genre=" . $this->filterGenre ;
    258             }
    259             else
    260             {
    261                 $this->filter="genre=\"" . $this->filterGenre . "\"";
    262                 $prevFilter=1;
    263             }
    264             $this->keepFilters =$this->keepFilters . "&amp;filterGenre=" . urlencode($this->filterGenre);
    265 
     239            $this->filter .= " AND genre=" . escape($this->filterGenre);
     240            $this->keepFilters .= "&amp;filterGenre=" . urlencode($this->filterGenre);
    266241        }
    267242
    268243        if($this->filterRank != "_All_")
    269244        {
    270             if($prevFilter==1)
    271             {
    272                 $this->filter=$this->filter . "and rank=" . $this->filterRank;
    273             }
    274             else
    275             {
    276                 $this->filter="rank=" . $this->filterRank;
    277                 $prevFilter=1;
    278             }
    279             $this->keepFilters =$this->keepFilters . "&amp;filterRank=" . urlencode($this->filterRank);
     245            $this->filter .= " AND rank=" . escape($this->filterRank);
     246            $this->keepFilters .= "&amp;filterRank=" . urlencode($this->filterRank);
    280247        }
    281 
    282 
    283 
    284248    }
    285249
    286250    function init($maxPerPage) {
    287251        global $db;
    288252        $this->prepFilter();
    289         if (empty($this->filter))
    290             $this->totalCount = $db->query_col('SELECT COUNT(*) FROM musicmetadata');
    291         else
    292             $this->totalCount = $db->query_col('SELECT COUNT(*) FROM musicmetadata WHERE '.$this->filter);
     253        $query_base = ' FROM music_songs'.
     254                      ' LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id'.
     255                      ' LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id'.
     256                      ' LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id'.
     257                      ' WHERE '.$this->filter.
     258                      ' ORDER BY artist_name,album_name,track';
     259       
     260        // Cannot use $db->query_col here as the preg_replace kills PHP when using large filterSongList queries
     261        $this->totalCount = 0;
     262        $result = mysql_query('SELECT COUNT(*)'.$query_base);
     263        if ($result)
     264        {
     265            $row=mysql_fetch_row($result);
     266            $this->totalCount=$row[0];
     267            mysql_free_result($result);
     268        }
    293269
    294270        if ($this->totalCount > 0) {
    295             if($this->offset > 0) {
    296                 $limitText='LIMIT ' . $this->offset . ',' . $maxPerPage;
    297             }
     271            if($this->offset > 0)
     272                $query_base .= ' LIMIT ' . $this->offset . ',' . $maxPerPage;
    298273            else
    299                 $limitText='LIMIT ' . $maxPerPage;
    300 
    301             if (empty($this->filter))
    302                 $this->result=mysql_query("select intid,artist,album,title,genre,length,rating,filename from musicmetadata order by artist,album,tracknum " . $limitText);
    303             else
    304                 $this->result=mysql_query("select intid,artist,album,title,genre,length,rating,filename from musicmetadata where $this->filter order by artist,album,tracknum $limitText");
     274                $query_base .= ' LIMIT ' . $maxPerPage;
     275           
     276                $this->result = mysql_query('SELECT music_songs.song_id, music_artists.artist_name, music_albums.album_name, music_songs.name, music_genres.genre, music_songs.length, music_songs.rating, music_songs.filename '.$query_base);
    305277        }
    306278    }
    307279}