Commit ee5eaea2 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Bump DB version to 11 to migrate Task MRL old encoding

parent df8e8984
......@@ -53,6 +53,7 @@
#include "ShowEpisode.h"
#include "database/SqliteTools.h"
#include "database/SqliteConnection.h"
#include "parser/Task.h"
#include "utils/Filename.h"
#include "utils/Url.h"
#include "VideoTrack.h"
......@@ -815,6 +816,11 @@ InitializeResult MediaLibrary::updateDatabaseModel( unsigned int previousVersion
migrateModel9to10();
previousVersion = 10;
}
if ( previousVersion == 10 )
{
migrateModel10to11();
previousVersion = 11;
}
// To be continued in the future!
// Safety check: ensure we didn't forget a migration along the way
......@@ -968,6 +974,24 @@ void MediaLibrary::migrateModel9to10()
forceRescan();
}
// Guess who forgot to migrate a table in version 10?
void MediaLibrary::migrateModel10to11()
{
const std::string req = "SELECT * FROM " + policy::TaskTable::Name +
" WHERE mrl LIKE '%#%%' ESCAPE '#'";
auto tasks = parser::Task::fetchAll<parser::Task>( this, req );
auto t = getConn()->newTransaction();
for ( const auto& t : tasks )
{
// We must not call mrl() from here. We might not have all devices yet,
// and calling mrl would crash for files stored on removable devices.
auto newMrl = utils::url::encode( utils::url::decode( t->mrl ) );
LOG_INFO( "Converting task mrl: ", t->mrl, " to ", newMrl );
t->setMrl( std::move( newMrl ) );
}
t->commit();
}
void MediaLibrary::reload()
{
if ( m_discovererWorker != nullptr )
......
......@@ -173,6 +173,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
void migrateModel7to8();
void migrateModel8to9();
void migrateModel9to10();
void migrateModel10to11();
void createAllTables();
void createAllTriggers();
void registerEntityHooks();
......
......@@ -32,7 +32,7 @@
namespace medialibrary
{
const uint32_t Settings::DbModelVersion = 10u;
const uint32_t Settings::DbModelVersion = 11u;
Settings::Settings( MediaLibrary* ml )
: m_ml( ml )
......
......@@ -193,6 +193,17 @@ bool Task::restoreLinkedEntities( )
return true;
}
void Task::setMrl( std::string newMrl )
{
if ( mrl == newMrl )
return;
static const std::string req = "UPDATE " + policy::TaskTable::Name + " SET "
"mrl = ? WHERE id_task = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, newMrl, m_id ) == false )
return;
mrl = std::move( newMrl );
}
void Task::createTable( sqlite::Connection* dbConnection )
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::TaskTable::Name + "("
......
......@@ -123,6 +123,7 @@ public:
// Restore attached entities such as media/files
bool restoreLinkedEntities();
void setMrl( std::string mrl );
std::shared_ptr<Media> media;
std::shared_ptr<File> file;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment