WIP. Improved database cleanup + various db fixes

This commit is contained in:
emeric
2014-08-07 15:29:54 +02:00
parent 5bdabec325
commit 2fbb1a7260
15 changed files with 274 additions and 128 deletions
+7 -9
View File
@@ -1,8 +1,7 @@
[ServiceManager] [ServiceManager]
- Rework the whole start/stop/try/cach/thread/interrupts things - Rework the whole start/stop/try/cach/thread/interrupts things
- Rework the io_service thread pool thing - Use our own WIOService
- Use our own WIOService
[Services] [Services]
- [UI] generate argc/argv from a config file (crypto, port info, db path) - [UI] generate argc/argv from a config file (crypto, port info, db path)
@@ -17,28 +16,27 @@
- Scaling: find something more "reliable" than GIL and its customs extensions (adobe work, io_new)? - Scaling: find something more "reliable" than GIL and its customs extensions (adobe work, io_new)?
[Database] [Database]
- Remove Audio/Video distinction - Optim, use SQL query to get genre orphans
- When removing a track, make sure to remove genre/artist/release if last of it
- Use Inotify like system to watch modified/added files? - Use Inotify like system to watch modified/added files?
- Implement a video database cleanup - Implement a video database cleanup
- Group video in "video groups". Each video may has sub groups (current "Path" class) - Group video in "video groups". Each video may has sub groups (current "Path" class)
-> Simplify database and remove the Path class -> Simplify database and remove the Path class
- Use size limits for strings (artist, release, genre)? - Use size limits for strings (artist, release, genre)?
- Process only files whose extensions are well known in audio/video world (avoid useless parsing/errors) - Process only files whose extensions are well known in audio/video world (avoid useless parsing/errors)?
[Metadata]
- Skip trailing non printable characters (spaces) in track name, artist, etc.
[Transcode] [Transcode]
- some zombies seem to be remaining after a week of use - some zombies seem to be remaining after a week of use
- some early playback end spotted on flac files - some early playback end spotted on flac files (windows chrome only?)
[UI] [UI]
[Settings] [Settings]
- logout users that are being changed (loss of admin admin rights), or make sure they are still admin when they make changes - logout users that are being changed (loss of admin admin rights), or make sure they are still admin when they make changes
- "signal not exposed" problem if a user logout and login again. bad resource destruction? - "signal not exposed" problem if a user logout and login again. bad resource destruction?
[admin/DB] [admin/DB]
- Add a dedicated Menu to add/delete and view the Media pathes (see Users for the idea)
- Do not make the update start time field active when update perdiod is "Never" - Do not make the update start time field active when update perdiod is "Never"
- Do not restart the db update service if user applied no changes
- Uncheck the "Request immediate scan" once setins are applied
[user/transcoding] [user/transcoding]
- Prefered codecs for audio/video? - Prefered codecs for audio/video?
+157 -81
View File
@@ -14,6 +14,23 @@ namespace DatabaseUpdater {
using namespace Database; using namespace Database;
namespace {
std::vector<boost::filesystem::path>
getRootDirectoriesByType(Wt::Dbo::Session& session, Database::MediaDirectory::Type type)
{
std::vector<boost::filesystem::path> res;
std::vector<Database::MediaDirectory::pointer> rootDirs = Database::MediaDirectory::getByType(session, type);
BOOST_FOREACH(Database::MediaDirectory::pointer rootDir, rootDirs)
res.push_back(rootDir->getPath());
return res;
}
}
Updater::Updater(boost::filesystem::path dbPath, MetaData::Parser& parser) Updater::Updater(boost::filesystem::path dbPath, MetaData::Parser& parser)
: _running(false), : _running(false),
_scheduleTimer(_ioService), _scheduleTimer(_ioService),
@@ -53,11 +70,7 @@ Updater::processNextJob(void)
MediaDirectorySettings::pointer settings = MediaDirectorySettings::get(_db.getSession()); MediaDirectorySettings::pointer settings = MediaDirectorySettings::get(_db.getSession());
if (settings->getManualScanRequested()) if (settings->getManualScanRequested())
{
settings.modify()->setManualScanRequested(false);
// Schedule immediate scan
scheduleScan( boost::posix_time::seconds(0) ); scheduleScan( boost::posix_time::seconds(0) );
}
else else
{ {
// boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); // boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
@@ -86,47 +99,49 @@ Updater::process(boost::system::error_code err)
{ {
if (!err) if (!err)
{ {
removeMissingAudioFiles(_result.audioStats); Stats stats;
checkAudioFiles(stats);
// TODO video files // TODO video files
// TODO remove files that do not belong to a root directory
std::vector<boost::filesystem::path> pathes;
typedef std::pair<boost::filesystem::path, Database::MediaDirectory::Type> RootDirectory;
std::vector<RootDirectory> rootDirectories;
{ {
Wt::Dbo::Transaction transaction(_db.getSession()); Wt::Dbo::Transaction transaction(_db.getSession());
std::vector<MediaDirectory::pointer> mediaDirectories = MediaDirectory::getAll(_db.getSession()); std::vector<MediaDirectory::pointer> mediaDirectories = MediaDirectory::getAll(_db.getSession());
BOOST_FOREACH(MediaDirectory::pointer directory, mediaDirectories) BOOST_FOREACH(MediaDirectory::pointer directory, mediaDirectories)
{ rootDirectories.push_back( std::make_pair( directory->getPath(), directory->getType() ));
if (directory->getType() == Database::MediaDirectory::Audio)
pathes.push_back(directory->getPath());
}
} }
BOOST_FOREACH( boost::filesystem::path p, pathes) BOOST_FOREACH( RootDirectory rootDirectory, rootDirectories)
refreshAudioDirectory(p, _result.audioStats); processDirectory(rootDirectory.first, rootDirectory.first, rootDirectory.second, stats);
std::cout << "Audio changes = " << _result.audioStats.nbChanges() << std::endl; std::cout << "Changes = " << stats.nbChanges() << std::endl;
std::cout << "Video changes = " << _result.videoStats.nbChanges() << std::endl;
// Update database stats only if it has not been interrupted // Update database stats
if (_running) boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
{ {
boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); Wt::Dbo::Transaction transaction(_db.getSession());
{
Wt::Dbo::Transaction transaction(_db.getSession());
Database::MediaDirectorySettings::pointer settings = Database::MediaDirectorySettings::get(_db.getSession()); Database::MediaDirectorySettings::pointer settings = Database::MediaDirectorySettings::get(_db.getSession());
if (_result.audioStats.nbChanges() + _result.videoStats.nbChanges() > 0) if (stats.nbChanges() > 0)
settings.modify()->setLastUpdate(now); settings.modify()->setLastUpdate(now);
// Save the last scan only if it has been completed
if (_running)
settings.modify()->setLastScan(now); settings.modify()->setLastScan(now);
}
processNextJob(); // If the manual scan was required we can now set it to done
// Update only if the scan is complete!
if (settings->getManualScanRequested() & _running)
settings.modify()->setManualScanRequested(false);
} }
if (_running)
processNextJob();
} }
} }
@@ -145,13 +160,6 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
if (track && track->getLastWriteTime() == lastWriteTime) if (track && track->getLastWriteTime() == lastWriteTime)
return; return;
std::vector<unsigned char> checksum;
computeCrc( file, checksum );
// Skip file if its checksum is still the same
if (track && track->getChecksum() == checksum)
return;
MetaData::Items items; MetaData::Items items;
_metadataParser.parse(file, items); _metadataParser.parse(file, items);
@@ -262,7 +270,6 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
assert(track); assert(track);
track.modify()->setChecksum(checksum);
track.modify()->setLastWriteTime(lastWriteTime); track.modify()->setLastWriteTime(lastWriteTime);
track.modify()->setName(title); track.modify()->setName(title);
@@ -304,70 +311,139 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
void void
Updater::refreshAudioDirectory( const boost::filesystem::path& p, Stats& stats) Updater::processDirectory(const boost::filesystem::path& rootDirectory,
const boost::filesystem::path& p,
Database::MediaDirectory::Type type,
Stats& stats)
{ {
if (!_running) if (!_running)
{
std::cerr << "Not running! Stopping scan" << std::endl;
return; return;
}
if (boost::filesystem::exists(p) && boost::filesystem::is_directory(p)) { if (!boost::filesystem::exists(p) || !boost::filesystem::is_directory(p))
return;
typedef std::vector<boost::filesystem::path> Paths; // store paths, boost::filesystem::recursive_directory_iterator itPath(rootDirectory);
boost::filesystem::recursive_directory_iterator itEnd;
while (itPath != itEnd)
{
if (!_running)
return;
// TODO use a recursive directory iterator instead if (boost::filesystem::is_regular(*itPath)) {
Paths files; switch( type )
std::copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), std::back_inserter(files)); {
case Database::MediaDirectory::Audio:
processAudioFile( *itPath, stats );
BOOST_FOREACH(const boost::filesystem::path& file, files) { break;
boost::this_thread::interruption_point(); case Database::MediaDirectory::Video:
// processVideoFile( rootDirectory, *itPath, stats);
try { break;
if (boost::filesystem::is_directory(file)) {
refreshAudioDirectory( file, stats );
}
else if (boost::filesystem::is_regular(file)) {
processAudioFile( file, stats );
}
else {
std::cout << "Skipped '" << file << "' (not regular)" << std::endl;
}
}
catch(std::exception& e) {
std::cerr << "Exception while accessing '" << file << ": " << e.what() << std::endl;
} }
} }
++itPath;
} }
} }
void bool
Updater::removeMissingAudioFiles( Stats& stats ) Updater::checkFile(const boost::filesystem::path& p, const std::vector<boost::filesystem::path>& rootDirs)
{ {
std::cerr << "Removing missing files..." << std::endl; bool status = true;
Wt::Dbo::Transaction transaction(_db.getSession());
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Track> > Tracks; // For each track, make sure the the file still exists
// and still belongs to a root directory
Tracks tracks = Track::getAll(_db.getSession()); if (!boost::filesystem::exists( p )
for (Tracks::iterator i = tracks.begin(); i != tracks.end(); ++i)
{
const boost::filesystem::path p ((*i)->getPath() );
if (!boost::filesystem::exists( p )
|| !boost::filesystem::is_regular( p ) ) || !boost::filesystem::is_regular( p ) )
{
std::cerr << "Missing file '" << p << "'" << std::endl;
status = false;
}
else
{
bool foundRoot = false;
BOOST_FOREACH(const boost::filesystem::path& rootDir, rootDirs)
{ {
(*i).remove(); if (p.string().find( rootDir.string() ) != std::string::npos)
stats.nbRemoved++; {
std::cerr << "Removing file '" << p << "'" << std::endl; foundRoot = true;
break;
}
}
if (!foundRoot)
{
std::cerr << "Out of root file '" << p << "'" << std::endl;
status = false;
} }
} }
transaction.commit(); return status;
}
std::cerr << "Refreshing missing files done!" << std::endl;
void
Updater::checkAudioFiles( Stats& stats )
{
std::cerr << "Checking audio files..." << std::endl;
Wt::Dbo::Transaction transaction(_db.getSession());
std::vector<boost::filesystem::path> rootDirs = getRootDirectoriesByType(_db.getSession(), Database::MediaDirectory::Audio);
std::cerr << "Checking tracks..." << std::endl;
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Track> > Tracks;
Tracks tracks = Track::getAll(_db.getSession());
for (Tracks::iterator it = tracks.begin(); it != tracks.end(); ++it)
{
Track::pointer track = (*it);
if (!checkFile(track->getPath(), rootDirs))
{
track.remove();
stats.nbRemoved++;
}
}
std::cerr << "Checking Artists..." << std::endl;
// Now process orphan Artists (no track)
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Artist> > Artists;
Artists artists = Artist::getAllOrphans(_db.getSession());
for (Artists::iterator it = artists.begin(); it != artists.end(); ++it)
{
std::cout << "Removing orphan artist " << (*it)->getName() << std::endl;
(*it).remove();
}
std::cerr << "Checking Releases..." << std::endl;
// Now process orphan Release (no track)
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Release> > Releases;
Releases releases = Release::getAllOrphans(_db.getSession());
for (Releases::iterator it = releases.begin(); it != releases.end(); ++it)
{
std::cout << "Removing orphan release " << (*it)->getName() << std::endl;
(*it).remove();
}
std::cerr << "Checking Genres..." << std::endl;
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Genre> > Genres;
Genres genres = Genre::getAll(_db.getSession());
for (Genres::iterator it = genres.begin(); it != genres.end(); ++it)
{
Genre::pointer genre = (*it);
if (genre->getTracks().size() == 0)
genre.remove();
}
// Now process orphan Genre (no track)
std::cerr << "Check audio files done!" << std::endl;
} }
Path::pointer Path::pointer
@@ -393,7 +469,7 @@ Updater::getAddPath(const boost::filesystem::path& path)
} }
void /*void
Updater::refreshVideoDirectory( const boost::filesystem::path& path) Updater::refreshVideoDirectory( const boost::filesystem::path& path)
{ {
std::cout << "Refreshing video directory " << path << std::endl; std::cout << "Refreshing video directory " << path << std::endl;
@@ -430,8 +506,8 @@ Updater::refreshVideoDirectory( const boost::filesystem::path& path)
} }
} }
std::cout << "Refreshing video directory " << path << ": DONE" << std::endl; std::cout << "Refreshing video directory " << path << ": DONE" << std::endl;
} }*/
/*
void void
Updater::processVideoFile( const boost::filesystem::path& file) Updater::processVideoFile( const boost::filesystem::path& file)
{ {
@@ -510,5 +586,5 @@ Updater::processVideoFile( const boost::filesystem::path& file)
std::cerr << "Exception while parsing video file : '" << file << "': '" << e.what() << "' => skipping!" << std::endl; std::cerr << "Exception while parsing video file : '" << file << "': '" << e.what() << "' => skipping!" << std::endl;
} }
} }
*/
} // namespace DatabaseUpdater } // namespace DatabaseUpdater
+15 -13
View File
@@ -5,9 +5,10 @@
#include <Wt/WIOService> #include <Wt/WIOService>
#include "metadata/MetaData.hpp" #include "metadata/MetaData.hpp"
#include "database/DatabaseHandler.hpp"
#include "database/FileTypes.hpp" #include "database/DatabaseHandler.hpp"
#include "database/MediaDirectory.hpp"
#include "database/FileTypes.hpp" // to remove
#include "database/DatabaseHandler.hpp" #include "database/DatabaseHandler.hpp"
namespace DatabaseUpdater { namespace DatabaseUpdater {
@@ -30,30 +31,32 @@ class Updater
std::size_t nbModified; std::size_t nbModified;
Stats() : nbAdded(0), nbRemoved(0), nbModified(0) {} Stats() : nbAdded(0), nbRemoved(0), nbModified(0) {}
void clear(void) { nbAdded = 0; nbRemoved = 0; nbModified = 0; }
std::size_t nbChanges() const { return nbAdded + nbRemoved + nbModified;} std::size_t nbChanges() const { return nbAdded + nbRemoved + nbModified;}
}; };
struct Result
{
Stats audioStats;
Stats videoStats;
};
// Job handling // Job handling
void processNextJob(); void processNextJob();
void scheduleScan(boost::posix_time::time_duration duration); void scheduleScan(boost::posix_time::time_duration duration);
void scheduleScan(boost::posix_time::ptime time); void scheduleScan(boost::posix_time::ptime time);
// Update database // Update database (scheduled callback)
void process(boost::system::error_code ec); void process(boost::system::error_code ec);
// Check if a file exists and is still in a root directory
static bool checkFile(const boost::filesystem::path& p, const std::vector<boost::filesystem::path>& rootDirectories);
// Video // Video
void refreshVideoDirectory( const boost::filesystem::path& directory );
void processDirectory( const boost::filesystem::path& rootDirectory,
const boost::filesystem::path& directory,
Database::MediaDirectory::Type type,
Stats& stats);
void processVideoFile( const boost::filesystem::path& file); void processVideoFile( const boost::filesystem::path& file);
// Audio // Audio
void removeMissingAudioFiles( Stats& stats ); void checkAudioFiles( Stats& stats );
void refreshAudioDirectory( const boost::filesystem::path& directory, Stats& stats);
void processAudioFile( const boost::filesystem::path& file, Stats& stats); void processAudioFile( const boost::filesystem::path& file, Stats& stats);
Database::Path::pointer getAddPath(const boost::filesystem::path& path); Database::Path::pointer getAddPath(const boost::filesystem::path& path);
@@ -67,7 +70,6 @@ class Updater
MetaData::Parser& _metadataParser; MetaData::Parser& _metadataParser;
Result _result; // update results
}; // class Updater }; // class Updater
} // DatabaseUpdater } // DatabaseUpdater
+6
View File
@@ -38,5 +38,11 @@ Artist::getAll(Wt::Dbo::Session& session, int offset, int size)
return session.find<Artist>().offset(offset).limit(size); return session.find<Artist>().offset(offset).limit(size);
} }
Wt::Dbo::collection<Artist::pointer>
Artist::getAllOrphans(Wt::Dbo::Session& session)
{
return session.query< Wt::Dbo::ptr<Artist> >("select a from artist a LEFT OUTER JOIN Track t ON a.id = t.artist_id WHERE t.id IS NULL");
}
} // namespace Database } // namespace Database
+6 -3
View File
@@ -31,8 +31,10 @@ class Artist
static pointer getByName(Wt::Dbo::Session& session, const std::string& name); static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getNone(Wt::Dbo::Session& session); static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, int size = -1); static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, int size = -1);
static Wt::Dbo::collection<pointer> getAllOrphans(Wt::Dbo::Session& session);
const std::string& getName(void) const { return _name; } const std::string& getName(void) const { return _name; }
const Wt::Dbo::collection< Wt::Dbo::ptr<Track> >& getTracks(void) const { return _tracks;}
// Create // Create
static pointer create(Wt::Dbo::Session& session, const std::string& name); static pointer create(Wt::Dbo::Session& session, const std::string& name);
@@ -70,7 +72,7 @@ class Release
static pointer getByName(Wt::Dbo::Session& session, const std::string& name); static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getById(Wt::Dbo::Session& session, id_type id); static pointer getById(Wt::Dbo::Session& session, id_type id);
static pointer getNone(Wt::Dbo::Session& session); static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAllOrphans(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::vector<Artist::id_type> artistIds, int offset = -1, int size = -1); static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::vector<Artist::id_type> artistIds, int offset = -1, int size = -1);
// Create // Create
@@ -78,7 +80,7 @@ class Release
std::string getName() const { return _name; } std::string getName() const { return _name; }
bool isNone(void) const; bool isNone(void) const;
Wt::Dbo::collection<Wt::Dbo::ptr<Track> > getTracks(void) const { return _tracks;} const Wt::Dbo::collection<Wt::Dbo::ptr<Track> >& getTracks(void) const { return _tracks;}
boost::posix_time::time_duration getDuration(void) const; boost::posix_time::time_duration getDuration(void) const;
@@ -110,7 +112,7 @@ class Genre
// Find utility // Find utility
static pointer getByName(Wt::Dbo::Session& session, const std::string& name); static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getNone(Wt::Dbo::Session& session); static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset, std::size_t size); static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset = -1, std::size_t size = -1);
// Create utility // Create utility
static pointer create(Wt::Dbo::Session& session, const std::string& name); static pointer create(Wt::Dbo::Session& session, const std::string& name);
@@ -118,6 +120,7 @@ class Genre
// Accessors // Accessors
const std::string& getName(void) const { return _name; } const std::string& getName(void) const { return _name; }
bool isNone(void) const; bool isNone(void) const;
const Wt::Dbo::collection< Wt::Dbo::ptr<Track> >& getTracks() const { return _tracks;}
template<class Action> template<class Action>
void persist(Action& a) void persist(Action& a)
+12 -3
View File
@@ -44,10 +44,19 @@ MediaDirectory::getAll(Wt::Dbo::Session& session)
return std::vector<MediaDirectory::pointer>(res.begin(), res.end()); return std::vector<MediaDirectory::pointer>(res.begin(), res.end());
} }
MediaDirectory::pointer
MediaDirectory::getByPath(Wt::Dbo::Session& session, boost::filesystem::path p) std::vector<MediaDirectory::pointer>
MediaDirectory::getByType(Wt::Dbo::Session& session, Type type)
{ {
return session.find<MediaDirectory>().where("path = ?").bind( p.string() ); Wt::Dbo::collection< MediaDirectory::pointer > res = session.find<MediaDirectory>().where("type = ?").bind (type);
return std::vector<MediaDirectory::pointer>(res.begin(), res.end());
}
MediaDirectory::pointer
MediaDirectory::get(Wt::Dbo::Session& session, boost::filesystem::path p, Type type)
{
return session.find<MediaDirectory>().where("path = ?").where("type = ?").bind( p.string()).bind(type);
} }
} // namespace Database } // namespace Database
+2 -1
View File
@@ -76,7 +76,8 @@ class MediaDirectory
// Accessors // Accessors
static pointer create(Wt::Dbo::Session& session, boost::filesystem::path p, Type type); static pointer create(Wt::Dbo::Session& session, boost::filesystem::path p, Type type);
static std::vector<MediaDirectory::pointer> getAll(Wt::Dbo::Session& session); static std::vector<MediaDirectory::pointer> getAll(Wt::Dbo::Session& session);
static pointer getByPath(Wt::Dbo::Session& session, boost::filesystem::path p); static std::vector<MediaDirectory::pointer> getByType(Wt::Dbo::Session& session, Type type);
static pointer get(Wt::Dbo::Session& session, boost::filesystem::path p, Type type);
static void eraseAll(Wt::Dbo::Session& session); static void eraseAll(Wt::Dbo::Session& session);
+7
View File
@@ -73,5 +73,12 @@ Release::getDuration(void) const
return res; return res;
} }
Wt::Dbo::collection<Release::pointer>
Release::getAllOrphans(Wt::Dbo::Session& session)
{
return session.query< Wt::Dbo::ptr<Release> >("select r from release r LEFT OUTER JOIN Track t ON r.id = t.release_id WHERE t.id IS NULL");
}
} // namespace Database } // namespace Database
+28 -2
View File
@@ -9,6 +9,9 @@
#include "SettingsMediaDirectories.hpp" #include "SettingsMediaDirectories.hpp"
#include "SettingsUsers.hpp" #include "SettingsUsers.hpp"
#include "service/ServiceManager.hpp"
#include "service/DatabaseUpdateService.hpp"
#include "Settings.hpp" #include "Settings.hpp"
namespace UserInterface { namespace UserInterface {
@@ -35,8 +38,14 @@ _sessionData(sessionData)
menu->addItem("Audio", new AudioFormView(sessionData, Database::User::getId(user))); menu->addItem("Audio", new AudioFormView(sessionData, Database::User::getId(user)));
if (user->isAdmin()) if (user->isAdmin())
{ {
menu->addItem("Media Folders", new MediaDirectories(sessionData)); MediaDirectories* mediaDirectory = new MediaDirectories(sessionData);
menu->addItem("Database Update", new DatabaseFormView(sessionData)); mediaDirectory->changed().connect(this, &Settings::handleDatabaseSettingsChanged);
menu->addItem("Media Folders", mediaDirectory);
DatabaseFormView* databaseFormView = new DatabaseFormView(sessionData);
databaseFormView->changed().connect(this, &Settings::handleDatabaseSettingsChanged);
menu->addItem("Database Update", databaseFormView);
menu->addItem("Users", new Users(sessionData)); menu->addItem("Users", new Users(sessionData));
} }
else else
@@ -47,5 +56,22 @@ _sessionData(sessionData)
addWidget(contents); addWidget(contents);
} }
void
Settings::handleDatabaseSettingsChanged()
{
// On settings change, request an immediate scan
{
Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession());
Database::MediaDirectorySettings::get(_sessionData.getDatabaseHandler().getSession()).modify()->setManualScanRequested(true);
}
// Restarting the update service
boost::lock_guard<boost::mutex> serviceLock (ServiceManager::instance().mutex());
DatabaseUpdateService::pointer service = ServiceManager::instance().getService<DatabaseUpdateService>();
if (service)
service->restart();
}
} // namespace Settings } // namespace Settings
} // namespace UserInterface } // namespace UserInterface
+2
View File
@@ -12,6 +12,8 @@ class Settings : public Wt::WContainerWidget
private: private:
void handleDatabaseSettingsChanged();
SessionData& _sessionData; SessionData& _sessionData;
}; };
+1 -11
View File
@@ -10,9 +10,6 @@
#include "database/MediaDirectory.hpp" #include "database/MediaDirectory.hpp"
#include "service/ServiceManager.hpp"
#include "service/DatabaseUpdateService.hpp"
#include "common/DirectoryValidator.hpp" #include "common/DirectoryValidator.hpp"
#include "SettingsDatabaseFormView.hpp" #include "SettingsDatabaseFormView.hpp"
@@ -291,14 +288,7 @@ DatabaseFormView::processSave()
// Make the model to commit data into DB // Make the model to commit data into DB
model->saveData(); model->saveData();
// Restarting the update service _sigChanged.emit();
{
boost::lock_guard<boost::mutex> serviceLock (ServiceManager::instance().mutex());
DatabaseUpdateService::pointer service = ServiceManager::instance().getService<DatabaseUpdateService>();
if (service)
service->restart();
}
// uncheck the special button // uncheck the special button
model->setValue(DatabaseFormModel::UpdateRequestImmediateField, false); model->setValue(DatabaseFormModel::UpdateRequestImmediateField, false);
+5
View File
@@ -4,6 +4,7 @@
#include <Wt/WContainerWidget> #include <Wt/WContainerWidget>
#include <Wt/WTemplateFormView> #include <Wt/WTemplateFormView>
#include <Wt/WText> #include <Wt/WText>
#include <Wt/WSignal>
#include "common/SessionData.hpp" #include "common/SessionData.hpp"
@@ -17,8 +18,12 @@ class DatabaseFormView : public Wt::WTemplateFormView
public: public:
DatabaseFormView(SessionData& sessionData, Wt::WContainerWidget *parent = 0); DatabaseFormView(SessionData& sessionData, Wt::WContainerWidget *parent = 0);
Wt::Signal<void>& changed() { return _sigChanged; }
private: private:
Wt::Signal<void> _sigChanged;
void processSave(); void processSave();
void processDiscard(); void processDiscard();
+12 -4
View File
@@ -75,14 +75,14 @@ MediaDirectories::refresh(void)
Wt::WPushButton* delBtn = new Wt::WPushButton("Delete"); Wt::WPushButton* delBtn = new Wt::WPushButton("Delete");
delBtn->setStyleClass("btn-danger"); delBtn->setStyleClass("btn-danger");
_table->elementAt(id, 3)->addWidget(delBtn); _table->elementAt(id, 3)->addWidget(delBtn);
delBtn->clicked().connect(boost::bind( &MediaDirectories::handleDelMediaDirectory, this, mediaDirectory->getPath() ) ); delBtn->clicked().connect(boost::bind( &MediaDirectories::handleDelMediaDirectory, this, mediaDirectory->getPath(), mediaDirectory->getType() ) );
++id; ++id;
} }
} }
void void
MediaDirectories::handleDelMediaDirectory(boost::filesystem::path p) MediaDirectories::handleDelMediaDirectory(boost::filesystem::path p, Database::MediaDirectory::Type type)
{ {
Wt::WMessageBox *messageBox = new Wt::WMessageBox Wt::WMessageBox *messageBox = new Wt::WMessageBox
("Delete Folder", ("Delete Folder",
@@ -98,12 +98,15 @@ MediaDirectories::handleDelMediaDirectory(boost::filesystem::path p)
Wt::Dbo::Transaction transaction(_db.getSession()); Wt::Dbo::Transaction transaction(_db.getSession());
// Delete the media diretory // Delete the media diretory
Database::MediaDirectory::pointer mediaDirectory = Database::MediaDirectory::getByPath(_db.getSession(), p); Database::MediaDirectory::pointer mediaDirectory = Database::MediaDirectory::get(_db.getSession(), p, type);
if (mediaDirectory) if (mediaDirectory)
mediaDirectory.remove(); mediaDirectory.remove();
} }
refresh(); refresh();
// Emit something changed in the settings
_sigChanged.emit();
} }
delete messageBox; delete messageBox;
@@ -129,10 +132,15 @@ MediaDirectories::handleMediaDirectoryFormCompleted(bool changed)
{ {
_stack->setCurrentIndex(0); _stack->setCurrentIndex(0);
// Refresh the user table if a change has been made
if (changed) if (changed)
{
// Refresh the user table if a change has been made
refresh(); refresh();
// Emit something changed in the settings
_sigChanged.emit();
}
// Delete the form view // Delete the form view
delete _stack->widget(1); delete _stack->widget(1);
+8 -1
View File
@@ -4,6 +4,9 @@
#include <Wt/WStackedWidget> #include <Wt/WStackedWidget>
#include <Wt/WContainerWidget> #include <Wt/WContainerWidget>
#include <Wt/WTable> #include <Wt/WTable>
#include <Wt/WSignal>
#include "database/MediaDirectory.hpp"
#include "common/SessionData.hpp" #include "common/SessionData.hpp"
@@ -17,11 +20,15 @@ class MediaDirectories : public Wt::WContainerWidget
void refresh(); void refresh();
Wt::Signal<void>& changed() { return _sigChanged; }
private: private:
Wt::Signal<void> _sigChanged;
void handleMediaDirectoryFormCompleted(bool changed); void handleMediaDirectoryFormCompleted(bool changed);
void handleDelMediaDirectory(boost::filesystem::path p); void handleDelMediaDirectory(boost::filesystem::path p, Database::MediaDirectory::Type type);
void handleCreateMediaDirectory(void); void handleCreateMediaDirectory(void);
Database::Handler& _db; Database::Handler& _db;
@@ -51,6 +51,12 @@ class MediaDirectoryFormModel : public Wt::WFormModel
Database::MediaDirectory::Type type Database::MediaDirectory::Type type
= (valueText(TypeField) == "Audio") ? Database::MediaDirectory::Audio : Database::MediaDirectory::Video; = (valueText(TypeField) == "Audio") ? Database::MediaDirectory::Audio : Database::MediaDirectory::Video;
if (Database::MediaDirectory::get(_db.getSession(), valueText(PathField).toUTF8(), type))
{
error = "This Path/Type already exists!";
return false;
}
Database::MediaDirectory::create(_db.getSession(), valueText(PathField).toUTF8(), type); Database::MediaDirectory::create(_db.getSession(), valueText(PathField).toUTF8(), type);
} }