Ticket #13481: 20190902-singlerecording.patch

File 20190902-singlerecording.patch, 3.9 KB (added by Klaas de Waal, 5 years ago)

Update starttime in table record for single recordings when EIT updates change the starttime of a program.

  • mythtv/libs/libmythtv/programdata.cpp

    diff --git a/mythtv/libs/libmythtv/programdata.cpp b/mythtv/libs/libmythtv/programdata.cpp
    index 0ecafdfa69..b5a309cce7 100644
    a b uint DBEvent::UpdateDB( 
    608608    return UpdateDB(q, chanid, p[match]);
    609609}
    610610
     611// Update starttime in table record for single recordings
     612// when the starttime of a program is changed.
     613//
     614// Return the number of rows affected:
     615// 0    if program is not found in table record
     616// 1    if program is found and updated
     617//
     618static int change_record(MSqlQuery &query, uint chanid,
     619                          const QDateTime &old_starttime,
     620                          const QDateTime &new_starttime)
     621{
     622    query.prepare("UPDATE record "
     623                   "SET starttime = :NEWSTARTTIME, "
     624                   "    startdate = :NEWSTARTDATE "
     625                   "WHERE chanid  = :CHANID "
     626                   "AND type      = :TYPE "
     627                   "AND search    = :SEARCH "
     628                   "AND starttime = :OLDSTARTTIME "
     629                   "AND startdate = :OLDSTARTDATE ");
     630    query.bindValue(":CHANID",       chanid);
     631    query.bindValue(":TYPE",         kSingleRecord);
     632    query.bindValue(":SEARCH",       kNoSearch);
     633    query.bindValue(":OLDSTARTTIME", old_starttime.time());
     634    query.bindValue(":OLDSTARTDATE", old_starttime.date());
     635    query.bindValue(":NEWSTARTTIME", new_starttime.time());
     636    query.bindValue(":NEWSTARTDATE", new_starttime.date());
     637
     638    int rows = 0;
     639    if (!query.exec() || !query.isActive())
     640    {
     641        MythDB::DBError("Updating record", query);
     642    }
     643    else
     644    {
     645        rows = query.numRowsAffected();
     646    }
     647    if (rows > 0)
     648    {
     649        LOG(VB_EIT, LOG_DEBUG,
     650            QString("EIT: Updated record: chanid:%1 old:%3 new:%4 rows:%5")
     651            .arg(chanid)
     652            .arg(old_starttime.toString(Qt::ISODate))
     653            .arg(new_starttime.toString(Qt::ISODate))
     654            .arg(rows));
     655    }
     656    return rows;
     657}
     658
    611659// Update matched item with current data.
    612660//
    613661uint DBEvent::UpdateDB(
    uint DBEvent::UpdateDB( 
    623671    QString  linetref         = m_inetref;
    624672    QDate    loriginalairdate = m_originalairdate;
    625673
     674    // Update starttime also in database table record so that
     675    // tables program and record remain consistent.
     676    if (m_starttime != match.m_starttime)
     677    {
     678        QDateTime const &old_starttime = match.m_starttime;
     679        QDateTime const &new_starttime = m_starttime;
     680        change_record(query, chanid, old_starttime, new_starttime);
     681
     682        LOG(VB_EIT, LOG_DEBUG,
     683            QString("EIT: (U) change starttime from %1 to %2 for chanid:%3 program '%4' ")
     684                    .arg(old_starttime.toString(Qt::ISODate))
     685                    .arg(new_starttime.toString(Qt::ISODate))
     686                    .arg(chanid)
     687                    .arg(m_title.left(35)));
     688    }
     689
    626690    if (ltitle.isEmpty() && !match.m_title.isEmpty())
    627691        ltitle = match.m_title;
    628692
    bool DBEvent::MoveOutOfTheWayDB( 
    9701034            return delete_program(query, chanid, prog.m_starttime);
    9711035        }
    9721036        LOG(VB_EIT, LOG_DEBUG,
    973             QString("EIT: change '%1' starttime to %2")
    974                     .arg(prog.m_title.left(35))
    975                     .arg(m_endtime.toString(Qt::ISODate)));
     1037            QString("EIT: (M) change starttime from %1 to %2 for chanid:%3 program '%4' ")
     1038                    .arg(prog.m_starttime.toString(Qt::ISODate))
     1039                    .arg(m_endtime.toString(Qt::ISODate))
     1040                    .arg(chanid)
     1041                    .arg(prog.m_title.left(35)));
    9761042
     1043        // Update starttime in tables record and program so they stay consistent.
     1044        change_record(query, chanid, prog.m_starttime, m_endtime);
    9771045        return change_program(query, chanid, prog.m_starttime,
    9781046                              m_endtime,        // New start time is our endtime
    9791047                              prog.m_endtime);  // Keep the end time