Upgrade from Wt3 to Wt4
This commit is contained in:
@@ -19,17 +19,17 @@
|
||||
|
||||
#include <boost/make_unique.hpp>
|
||||
|
||||
#include <Wt/Dbo/FixedSqlConnectionPool>
|
||||
#include <Wt/Dbo/backend/Sqlite3>
|
||||
#include <Wt/Dbo/FixedSqlConnectionPool.h>
|
||||
#include <Wt/Dbo/backend/Sqlite3.h>
|
||||
|
||||
#include <Wt/Auth/Dbo/AuthInfo>
|
||||
#include <Wt/Auth/Dbo/UserDatabase>
|
||||
#include <Wt/Auth/AuthService>
|
||||
#include <Wt/Auth/HashFunction>
|
||||
#include <Wt/Auth/Identity>
|
||||
#include <Wt/Auth/PasswordService>
|
||||
#include <Wt/Auth/PasswordStrengthValidator>
|
||||
#include <Wt/Auth/PasswordVerifier>
|
||||
#include <Wt/Auth/Dbo/AuthInfo.h>
|
||||
#include <Wt/Auth/Dbo/UserDatabase.h>
|
||||
#include <Wt/Auth/AuthService.h>
|
||||
#include <Wt/Auth/HashFunction.h>
|
||||
#include <Wt/Auth/Identity.h>
|
||||
#include <Wt/Auth/PasswordService.h>
|
||||
#include <Wt/Auth/PasswordStrengthValidator.h>
|
||||
#include <Wt/Auth/PasswordVerifier.h>
|
||||
|
||||
#include "Setting.hpp"
|
||||
|
||||
@@ -51,24 +51,24 @@ Handler::configureAuth(void)
|
||||
{
|
||||
authService.setEmailVerificationEnabled(false);
|
||||
authService.setAuthTokensEnabled(true, "lmsauth");
|
||||
authService.setIdentityPolicy(Wt::Auth::LoginNameIdentity);
|
||||
authService.setIdentityPolicy(Wt::Auth::IdentityPolicy::LoginName);
|
||||
authService.setRandomTokenLength(32);
|
||||
authService.setTokenHashFunction(new Wt::Auth::BCryptHashFunction(8));
|
||||
|
||||
Wt::Auth::PasswordVerifier *verifier = new Wt::Auth::PasswordVerifier();
|
||||
verifier->addHashFunction(new Wt::Auth::BCryptHashFunction(8));
|
||||
passwordService.setVerifier(verifier);
|
||||
auto verifier = std::make_unique<Wt::Auth::PasswordVerifier>();
|
||||
verifier->addHashFunction(std::make_unique<Wt::Auth::BCryptHashFunction>(8));
|
||||
passwordService.setVerifier(std::move(verifier));
|
||||
passwordService.setAttemptThrottlingEnabled(true);
|
||||
|
||||
Wt::Auth::PasswordStrengthValidator* strengthValidator = new Wt::Auth::PasswordStrengthValidator();
|
||||
auto strengthValidator = std::make_unique<Wt::Auth::PasswordStrengthValidator>();
|
||||
// Reduce some constraints...
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::PassPhrase, 4);
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::OneCharClass, 4);
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::TwoCharClass, 4);
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::ThreeCharClass, 4 );
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::FourCharClass, 4 );
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::PassPhrase, 4);
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::OneCharClass, 4);
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::TwoCharClass, 4);
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::ThreeCharClass, 4 );
|
||||
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::FourCharClass, 4 );
|
||||
|
||||
passwordService.setStrengthValidator(strengthValidator);
|
||||
passwordService.setStrengthValidator(std::move(strengthValidator));
|
||||
}
|
||||
|
||||
const Wt::Auth::AuthService&
|
||||
@@ -182,24 +182,26 @@ Handler::createUser(const Wt::Auth::User& authUser)
|
||||
return User::pointer();
|
||||
}
|
||||
|
||||
User::pointer user = _session.add(new User());
|
||||
User::pointer user = _session.add(std::make_unique<User>());
|
||||
Wt::Dbo::ptr<AuthInfo> authInfo = _users->find(authUser);
|
||||
authInfo.modify()->setUser(user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
Wt::Dbo::SqlConnectionPool*
|
||||
std::unique_ptr<Wt::Dbo::SqlConnectionPool>
|
||||
Handler::createConnectionPool(boost::filesystem::path p)
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Creating connection pool on file " << p;
|
||||
|
||||
Wt::Dbo::backend::Sqlite3 *connection = new Wt::Dbo::backend::Sqlite3(p.string());
|
||||
LMS_LOG(DB, INFO) << "Creating connection pool on file " << p.string();
|
||||
|
||||
auto connection = std::make_unique<Wt::Dbo::backend::Sqlite3>(p.string());
|
||||
connection->executeSql("pragma journal_mode=WAL");
|
||||
|
||||
connection->setProperty("show-queries", "true");
|
||||
return new Wt::Dbo::FixedSqlConnectionPool(connection, 1);
|
||||
|
||||
auto pool = std::make_unique<Wt::Dbo::FixedSqlConnectionPool>(std::move(connection), 1);
|
||||
pool->setTimeout(std::chrono::seconds(1));
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <memory>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
#include <Wt/Dbo/SqlConnectionPool>
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
#include <Wt/Dbo/SqlConnectionPool.h>
|
||||
|
||||
#include <Wt/Auth/Dbo/UserDatabase>
|
||||
#include <Wt/Auth/Login>
|
||||
#include <Wt/Auth/PasswordService>
|
||||
#include <Wt/Auth/Dbo/UserDatabase.h>
|
||||
#include <Wt/Auth/Login.h>
|
||||
#include <Wt/Auth/PasswordService.h>
|
||||
|
||||
#include "Types.hpp"
|
||||
|
||||
@@ -60,7 +60,7 @@ class Handler
|
||||
static const Wt::Auth::AuthService& getAuthService();
|
||||
static const Wt::Auth::PasswordService& getPasswordService();
|
||||
|
||||
static Wt::Dbo::SqlConnectionPool* createConnectionPool(boost::filesystem::path db);
|
||||
static std::unique_ptr<Wt::Dbo::SqlConnectionPool> createConnectionPool(boost::filesystem::path db);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ Artist::getById(Wt::Dbo::Session& session, Artist::id_type id)
|
||||
Artist::pointer
|
||||
Artist::create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID)
|
||||
{
|
||||
return session.add(new Artist(name, MBID));
|
||||
return session.add(std::make_unique<Artist>(name, MBID));
|
||||
}
|
||||
|
||||
std::vector<Artist::pointer>
|
||||
@@ -75,7 +75,7 @@ Artist::getAllOrphans(Wt::Dbo::Session& session)
|
||||
static
|
||||
Wt::Dbo::Query<Artist::pointer>
|
||||
getQuery(Wt::Dbo::Session& session,
|
||||
const std::set<id_type>& clusterIds,
|
||||
const std::set<Artist::id_type>& clusterIds,
|
||||
const std::vector<std::string>& keywords)
|
||||
{
|
||||
WhereClause where;
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
#include <Wt/Dbo/QueryModel>
|
||||
|
||||
#include "SearchFilter.hpp"
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
#include <Wt/Dbo/QueryModel.h>
|
||||
|
||||
namespace Database
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ MediaDirectory::MediaDirectory(boost::filesystem::path p)
|
||||
MediaDirectory::pointer
|
||||
MediaDirectory::create(Wt::Dbo::Session& session, boost::filesystem::path p)
|
||||
{
|
||||
return session.add( new MediaDirectory(p) );
|
||||
return session.add( std::make_unique<MediaDirectory>(p) );
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
#include <Wt/Dbo/WtSqlTraits>
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
#include <Wt/Dbo/WtSqlTraits.h>
|
||||
|
||||
namespace Database {
|
||||
|
||||
class MediaDirectory
|
||||
|
||||
@@ -38,7 +38,7 @@ Playlist::Playlist(std::string name, bool isPublic, Wt::Dbo::ptr<User> user)
|
||||
Playlist::pointer
|
||||
Playlist::create(Wt::Dbo::Session& session, std::string name, bool isPublic, Wt::Dbo::ptr<User> user)
|
||||
{
|
||||
return session.add( new Playlist(name, isPublic, user) );
|
||||
return session.add( std::make_unique<Playlist>(name, isPublic, user) );
|
||||
}
|
||||
|
||||
PlaylistEntry::PlaylistEntry()
|
||||
@@ -75,7 +75,7 @@ PlaylistEntry::PlaylistEntry(Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<Playlist> p
|
||||
PlaylistEntry::pointer
|
||||
PlaylistEntry::create(Wt::Dbo::Session& session, Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<Playlist> playlist)
|
||||
{
|
||||
return session.add( new PlaylistEntry( track, playlist) );
|
||||
return session.add( std::make_unique<PlaylistEntry>( track, playlist) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef DATABASE_PLAYLIST_HPP
|
||||
#define DATABASE_PLAYLIST_HPP
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
|
||||
#include "Types.hpp"
|
||||
#include "SearchFilter.hpp"
|
||||
#include "SqlQuery.hpp"
|
||||
|
||||
namespace Database
|
||||
@@ -53,7 +52,7 @@ Release::getById(Wt::Dbo::Session& session, Release::id_type id)
|
||||
Release::pointer
|
||||
Release::create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID)
|
||||
{
|
||||
return session.add(new Release(name, MBID));
|
||||
return session.add(std::make_unique<Release>(name, MBID));
|
||||
}
|
||||
|
||||
std::vector<Release::pointer>
|
||||
@@ -74,7 +73,7 @@ Release::getAllOrphans(Wt::Dbo::Session& session)
|
||||
static
|
||||
Wt::Dbo::Query<Release::pointer>
|
||||
getQuery(Wt::Dbo::Session& session,
|
||||
const std::set<id_type>& clusterIds,
|
||||
const std::set<Release::id_type>& clusterIds,
|
||||
const std::vector<std::string> keywords)
|
||||
{
|
||||
WhereClause where;
|
||||
@@ -140,22 +139,22 @@ Release::getReleaseYear(bool original) const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
Wt::Dbo::collection<boost::posix_time::ptime> times = session()->query<boost::posix_time::ptime>(
|
||||
Wt::Dbo::collection<Wt::WDate> dates = session()->query<Wt::WDate>(
|
||||
std::string("SELECT ") + (original ? "t.original_date" : "t.date") + " FROM track t INNER JOIN release r ON r.id = t.release_id")
|
||||
.where("r.id = ?")
|
||||
.groupBy("t.date")
|
||||
.bind(this->id());
|
||||
|
||||
/* various dates, no date */
|
||||
if (times.empty() || times.size() > 1)
|
||||
if (dates.empty() || dates.size() > 1)
|
||||
return boost::none;
|
||||
|
||||
boost::gregorian::date date = times.front().date();
|
||||
auto date = dates.front();
|
||||
|
||||
if (date.is_special())
|
||||
if (!date.isValid())
|
||||
return boost::none;
|
||||
|
||||
return boost::make_optional<int>(date.year());
|
||||
return date.year();
|
||||
}
|
||||
|
||||
std::vector<Wt::Dbo::ptr<Artist>>
|
||||
|
||||
@@ -21,9 +21,7 @@
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
|
||||
#include "SearchFilter.hpp"
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
|
||||
namespace Database
|
||||
{
|
||||
@@ -68,7 +66,7 @@ class Release : public Wt::Dbo::Dbo<Release>
|
||||
// Accessors
|
||||
std::string getName() const { return _name; }
|
||||
std::string getMBID() const { return _MBID; }
|
||||
boost::posix_time::time_duration getDuration(void) const;
|
||||
std::chrono::seconds getDuration(void) const;
|
||||
|
||||
// Get the artists of this release
|
||||
std::vector<Wt::Dbo::ptr<Artist> > getArtists() const;
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
#include "SearchFilter.hpp"
|
||||
|
||||
namespace Database
|
||||
{
|
||||
|
||||
void
|
||||
SearchFilter::operator+=(const SearchFilter& filter)
|
||||
{
|
||||
}
|
||||
|
||||
SqlQuery
|
||||
SearchFilter::generatePartialQuery()
|
||||
{
|
||||
SqlQuery sqlQuery;
|
||||
return sqlQuery;
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _DB_SEARCH_FILTER_HPP_
|
||||
#define _DB_SEARCH_FILTER_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
|
||||
#include "SqlQuery.hpp"
|
||||
|
||||
namespace Database
|
||||
{
|
||||
|
||||
typedef Wt::Dbo::dbo_default_traits::IdType id_type;
|
||||
|
||||
class SearchFilter
|
||||
{
|
||||
public:
|
||||
|
||||
typedef int id_type;
|
||||
|
||||
SearchFilter() {}
|
||||
|
||||
static SearchFilter Artist(std::string name) {return SearchFilter();}
|
||||
static SearchFilter Artist(id_type id) {return SearchFilter();}
|
||||
|
||||
static SearchFilter Release(std::string name) {return SearchFilter();}
|
||||
static SearchFilter Release(id_type id) {return SearchFilter();}
|
||||
|
||||
static SearchFilter Track(std::string name) {return SearchFilter();}
|
||||
|
||||
static SearchFilter Cluster(id_type id) {return SearchFilter();}
|
||||
|
||||
// Combine search filters by add operation
|
||||
// Caution: multiple filters on different artist/release/track
|
||||
// values may lead to empty results
|
||||
void operator+=(const SearchFilter& filter);
|
||||
|
||||
SqlQuery generatePartialQuery();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Database
|
||||
|
||||
#endif // _DB_SEARCH_FILTER_HPP_
|
||||
@@ -52,8 +52,8 @@ Setting::getBool(Wt::Dbo::Session& session, std::string setting, bool defaultVal
|
||||
return (res->_value == "true");
|
||||
}
|
||||
|
||||
boost::posix_time::time_duration
|
||||
Setting::getDuration(Wt::Dbo::Session& session, std::string setting, boost::posix_time::time_duration defaultValue)
|
||||
Wt::WTime
|
||||
Setting::getTime(Wt::Dbo::Session& session, std::string setting, Wt::WTime defaultValue)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(session);
|
||||
|
||||
@@ -61,19 +61,7 @@ Setting::getDuration(Wt::Dbo::Session& session, std::string setting, boost::posi
|
||||
if (!res)
|
||||
return defaultValue;
|
||||
|
||||
return boost::posix_time::duration_from_string(res->_value);
|
||||
}
|
||||
|
||||
boost::posix_time::ptime
|
||||
Setting::getTime(Wt::Dbo::Session& session, std::string setting, boost::posix_time::ptime defaultValue)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(session);
|
||||
|
||||
pointer res = getByName(session, setting);
|
||||
if (!res)
|
||||
return defaultValue;
|
||||
|
||||
return boost::posix_time::time_from_string(res->_value);
|
||||
return Wt::WTime::fromString(res->_value);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -93,7 +81,7 @@ Setting::getInt(Wt::Dbo::Session& session, std::string setting, int defaultValue
|
||||
Setting::pointer
|
||||
Setting::create(Wt::Dbo::Session& session, std::string name)
|
||||
{
|
||||
return session.add<Setting>(new Setting(name));
|
||||
return session.add<Setting>(std::make_unique<Setting>(name));
|
||||
}
|
||||
|
||||
Setting::pointer
|
||||
@@ -127,17 +115,10 @@ Setting::setBool(Wt::Dbo::Session& session, std::string setting, bool value)
|
||||
}
|
||||
|
||||
void
|
||||
Setting::setDuration(Wt::Dbo::Session& session, std::string setting, boost::posix_time::time_duration value)
|
||||
Setting::setTime(Wt::Dbo::Session& session, std::string setting, Wt::WTime value)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(session);
|
||||
getOrCreateByName(session, setting).modify()->_value = boost::posix_time::to_simple_string(value);
|
||||
}
|
||||
|
||||
void
|
||||
Setting::setTime(Wt::Dbo::Session& session, std::string setting, boost::posix_time::ptime value)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(session);
|
||||
getOrCreateByName(session, setting).modify()->_value = boost::posix_time::to_simple_string(value);
|
||||
getOrCreateByName(session, setting).modify()->_value = value.toString().toUTF8();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
#include <Wt/WTime.h>
|
||||
|
||||
namespace Database {
|
||||
|
||||
@@ -29,7 +28,10 @@ namespace Database {
|
||||
class Setting
|
||||
{
|
||||
public:
|
||||
using pointer = Wt::Dbo::ptr<Setting>;
|
||||
|
||||
Setting() {}
|
||||
Setting(std::string name) : _name(name) {}
|
||||
|
||||
// check if a setting exists or not
|
||||
static bool exists(Wt::Dbo::Session& session, std::string setting);
|
||||
@@ -38,16 +40,14 @@ class Setting
|
||||
// Nested transactions
|
||||
static std::string getString(Wt::Dbo::Session& session, std::string setting, std::string defaultValue = "");
|
||||
static bool getBool(Wt::Dbo::Session& session, std::string setting, bool defaultValue = false);
|
||||
static boost::posix_time::time_duration getDuration(Wt::Dbo::Session& session, std::string setting, boost::posix_time::time_duration defaultDuration = boost::posix_time::seconds(0) );
|
||||
static boost::posix_time::ptime getTime(Wt::Dbo::Session& session, std::string setting, boost::posix_time::ptime defaultTime = boost::posix_time::ptime());
|
||||
static Wt::WTime getTime(Wt::Dbo::Session& session, std::string setting, Wt::WTime defaultValue = Wt::WTime());
|
||||
static int getInt(Wt::Dbo::Session& session, std::string setting, int defaultValue = 0);
|
||||
|
||||
// Setters
|
||||
// Nested transactions
|
||||
static void setString(Wt::Dbo::Session& session, std::string setting, std::string value);
|
||||
static void setBool(Wt::Dbo::Session& session, std::string setting, bool value);
|
||||
static void setDuration(Wt::Dbo::Session& session, std::string setting, boost::posix_time::time_duration value);
|
||||
static void setTime(Wt::Dbo::Session& session, std::string setting, boost::posix_time::ptime time);
|
||||
static void setTime(Wt::Dbo::Session& session, std::string setting, Wt::WTime value);
|
||||
static void setInt(Wt::Dbo::Session& session, std::string setting, int value);
|
||||
|
||||
template<class Action>
|
||||
@@ -58,10 +58,6 @@ class Setting
|
||||
}
|
||||
|
||||
private:
|
||||
Setting(std::string name) : _name(name) {}
|
||||
|
||||
typedef Wt::Dbo::ptr<Setting> pointer;
|
||||
|
||||
static pointer getByName(Wt::Dbo::Session& session, std::string name);
|
||||
static pointer create(Wt::Dbo::Session& session, std::string name);
|
||||
static pointer getOrCreateByName(Wt::Dbo::Session& session, std::string name);
|
||||
|
||||
+4
-44
@@ -17,10 +17,6 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
#include <Wt/Dbo/QueryModel>
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
#include "SqlQuery.hpp"
|
||||
@@ -75,7 +71,7 @@ Track::getByMBID(Wt::Dbo::Session& session, const std::string& mbid)
|
||||
Track::pointer
|
||||
Track::create(Wt::Dbo::Session& session, const boost::filesystem::path& p)
|
||||
{
|
||||
return session.add(new Track(p) );
|
||||
return session.add(std::make_unique<Track>(p));
|
||||
}
|
||||
|
||||
std::vector<boost::filesystem::path>
|
||||
@@ -111,7 +107,7 @@ Track::getClusters(void) const
|
||||
static
|
||||
Wt::Dbo::Query< Track::pointer >
|
||||
getQuery(Wt::Dbo::Session& session,
|
||||
const std::set<id_type>& clusterIds,
|
||||
const std::set<Cluster::id_type>& clusterIds,
|
||||
const std::vector<std::string> keywords)
|
||||
{
|
||||
WhereClause where;
|
||||
@@ -149,20 +145,6 @@ getQuery(Wt::Dbo::Session& session,
|
||||
return query;
|
||||
}
|
||||
|
||||
Track::StatsQueryResult
|
||||
Track::getStats(Wt::Dbo::Session& session, SearchFilter filter)
|
||||
{
|
||||
SqlQuery sqlQuery = filter.generatePartialQuery();
|
||||
|
||||
Wt::Dbo::Query<StatsQueryResult> query = session.query<StatsQueryResult>( "SELECT COUNT(\"id\"), SUM(\"dur\") FROM (SELECT t.id as \"id\", t.duration as \"dur\" FROM track t INNER JOIN artist a ON t.artist_id = a.id INNER JOIN cluster c ON c.id = t_c.cluster_id INNER JOIN track_cluster t_c ON t_c.track_id = t.id INNER JOIN release r ON r.id = t.release_id " + sqlQuery.where().get() + " GROUP BY t.id)");
|
||||
|
||||
for (const std::string& bindArg : sqlQuery.where().getBindArgs())
|
||||
query.bind(bindArg);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Track::pointer>
|
||||
Track::getByFilter(Wt::Dbo::Session& session,
|
||||
const std::set<id_type>& clusterIds,
|
||||
@@ -233,7 +215,7 @@ Cluster::Cluster(Wt::Dbo::ptr<ClusterType> type, std::string name)
|
||||
Cluster::pointer
|
||||
Cluster::create(Wt::Dbo::Session& session, Wt::Dbo::ptr<ClusterType> type, std::string name)
|
||||
{
|
||||
return session.add(new Cluster(type, name));
|
||||
return session.add(std::make_unique<Cluster>(type, name));
|
||||
}
|
||||
|
||||
std::vector<Cluster::pointer>
|
||||
@@ -244,28 +226,6 @@ Cluster::getAll(Wt::Dbo::Session& session)
|
||||
return std::vector<Cluster::pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
Wt::Dbo::Query<Cluster::pointer>
|
||||
Cluster::getQuery(Wt::Dbo::Session& session, SearchFilter filter)
|
||||
{
|
||||
SqlQuery sqlQuery = filter.generatePartialQuery();
|
||||
|
||||
Wt::Dbo::Query<pointer> query
|
||||
= session.query<pointer>( "SELECT g FROM cluster c INNER JOIN track_cluster t_c ON t_c.cluster_id = c.id INNER JOIN artist a ON t.artist_id = a.id INNER JOIN release r ON r.id = t.release_id INNER JOIN track t ON t.id = t_c.track_id " + sqlQuery.where().get()).groupBy("c.name").orderBy("c.name");
|
||||
|
||||
for (const std::string& bindArg : sqlQuery.where().getBindArgs())
|
||||
query.bind(bindArg);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
std::vector<Cluster::pointer>
|
||||
Cluster::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size)
|
||||
{
|
||||
Wt::Dbo::collection<pointer> res = getQuery(session, filter).limit(size).offset(offset);
|
||||
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
ClusterType::ClusterType(std::string name)
|
||||
: _name(name)
|
||||
{
|
||||
@@ -297,7 +257,7 @@ ClusterType::getAll(Wt::Dbo::Session& session)
|
||||
ClusterType::pointer
|
||||
ClusterType::create(Wt::Dbo::Session& session, std::string name)
|
||||
{
|
||||
return session.add(new ClusterType(name));
|
||||
return session.add(std::make_unique<ClusterType>(name));
|
||||
}
|
||||
|
||||
Cluster::pointer
|
||||
|
||||
+19
-31
@@ -21,17 +21,15 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
#include <Wt/Dbo/WtSqlTraits>
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
#include <Wt/Dbo/WtSqlTraits.h>
|
||||
|
||||
#include <Wt/WDateTime>
|
||||
|
||||
#include "SearchFilter.hpp"
|
||||
#include <Wt/WDateTime.h>
|
||||
|
||||
namespace Database {
|
||||
|
||||
@@ -52,7 +50,6 @@ class Cluster : public Wt::Dbo::Dbo<Cluster>
|
||||
Cluster(Wt::Dbo::ptr<ClusterType> type, std::string name);
|
||||
|
||||
// Find utility
|
||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
|
||||
|
||||
// Create utility
|
||||
@@ -75,7 +72,6 @@ class Cluster : public Wt::Dbo::Dbo<Cluster>
|
||||
}
|
||||
|
||||
private:
|
||||
static Wt::Dbo::Query<pointer> getQuery(Wt::Dbo::Session& session, SearchFilter filter);
|
||||
|
||||
static const std::size_t _maxNameLength = 128;
|
||||
|
||||
@@ -159,14 +155,6 @@ class Track
|
||||
static std::vector<pointer> getMBIDDuplicates(Wt::Dbo::Session& session);
|
||||
static std::vector<pointer> getChecksumDuplicates(Wt::Dbo::Session& session);
|
||||
|
||||
// Utility fonctions
|
||||
// Stats for a given search filter
|
||||
typedef boost::tuple<
|
||||
int, // Total tracks
|
||||
boost::posix_time::time_duration // Total duration
|
||||
> StatsQueryResult;
|
||||
static StatsQueryResult getStats(Wt::Dbo::Session& session, SearchFilter filter);
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, const boost::filesystem::path& p);
|
||||
|
||||
@@ -179,12 +167,12 @@ class Track
|
||||
void setDiscNumber(int num) { _discNumber = num; }
|
||||
void setTotalDiscNumber(int num) { _totalDiscNumber = num; }
|
||||
void setName(const std::string& name) { _name = std::string(name, 0, _maxNameLength); }
|
||||
void setDuration(boost::posix_time::time_duration duration) { _duration = duration; }
|
||||
void setLastWriteTime(boost::posix_time::ptime time) { _fileLastWrite = time; }
|
||||
void setAddedTime(boost::posix_time::ptime time) { _fileAdded = time; }
|
||||
void setDuration(std::chrono::milliseconds duration) { _duration = duration; }
|
||||
void setLastWriteTime(Wt::WDateTime time) { _fileLastWrite = time; }
|
||||
void setAddedTime(Wt::WDateTime time) { _fileAdded = time; }
|
||||
void setChecksum(const std::vector<unsigned char>& checksum) { _fileChecksum = checksum; }
|
||||
void setDate(const boost::posix_time::ptime& date) { _date = date; }
|
||||
void setOriginalDate(const boost::posix_time::ptime& date) { _originalDate = date; }
|
||||
void setDate(Wt::WDate date) { _date = date; }
|
||||
void setOriginalDate(Wt::WDate date) { _originalDate = date; }
|
||||
void setGenres(const std::string& genreList) { _genreList = genreList; }
|
||||
void setCoverType(CoverType coverType) { _coverType = coverType; }
|
||||
void setMBID(const std::string& MBID) { _MBID = MBID; }
|
||||
@@ -197,11 +185,11 @@ class Track
|
||||
boost::optional<std::size_t> getTotalDiscNumber(void) const;
|
||||
std::string getName(void) const { return _name; }
|
||||
boost::filesystem::path getPath(void) const { return _filePath; }
|
||||
boost::posix_time::time_duration getDuration(void) const { return _duration; }
|
||||
boost::posix_time::ptime getDate(void) const { return _date; }
|
||||
boost::posix_time::ptime getOriginalDate(void) const { return _originalDate; }
|
||||
boost::posix_time::ptime getLastWriteTime(void) const { return _fileLastWrite; }
|
||||
boost::posix_time::ptime getAddedTime(void) const { return _fileAdded; }
|
||||
std::chrono::milliseconds getDuration(void) const { return _duration; }
|
||||
Wt::WDate getDate(void) const { return _date; }
|
||||
Wt::WDate getOriginalDate(void) const { return _originalDate; }
|
||||
Wt::WDateTime getLastWriteTime(void) const { return _fileLastWrite; }
|
||||
Wt::WDateTime getAddedTime(void) const { return _fileAdded; }
|
||||
const std::vector<unsigned char>& getChecksum(void) const { return _fileChecksum; }
|
||||
CoverType getCoverType(void) const { return _coverType; }
|
||||
const std::string& getMBID(void) const { return _MBID; }
|
||||
@@ -244,14 +232,14 @@ class Track
|
||||
std::string _name;
|
||||
std::string _artistName;
|
||||
std::string _releaseName;
|
||||
boost::posix_time::time_duration _duration;
|
||||
boost::posix_time::ptime _date;
|
||||
boost::posix_time::ptime _originalDate; // original date time
|
||||
std::chrono::duration<int, std::milli> _duration;
|
||||
Wt::WDate _date;
|
||||
Wt::WDate _originalDate; // original date time
|
||||
std::string _genreList;
|
||||
std::string _filePath;
|
||||
std::vector<unsigned char> _fileChecksum;
|
||||
boost::posix_time::ptime _fileLastWrite;
|
||||
boost::posix_time::ptime _fileAdded;
|
||||
Wt::WDateTime _fileLastWrite;
|
||||
Wt::WDateTime _fileAdded;
|
||||
CoverType _coverType;
|
||||
std::string _MBID; // Musicbrainz Identifier
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ User::getAll(Wt::Dbo::Session& session)
|
||||
User::pointer
|
||||
User::create(Wt::Dbo::Session& session)
|
||||
{
|
||||
return session.add(new User());
|
||||
return session.add(std::make_unique<User>());
|
||||
}
|
||||
|
||||
User::pointer
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
#include <Wt/Auth/Dbo/AuthInfo>
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
#include <Wt/Auth/Dbo/AuthInfo.h>
|
||||
|
||||
namespace Database {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user