Add the ability to clear a playlist.
This commit is contained in:
parent
83ffa2aafa
commit
a1230dddfd
@ -116,9 +116,10 @@ public class ORM {
|
||||
.append(model.id)
|
||||
.toString()
|
||||
|
||||
logger.debug("Updating model.\n\tSQL: {}\n\tPARAMS: {}", query, params)
|
||||
sql.executeUpdate(query, params)
|
||||
return model }
|
||||
return withTransaction {
|
||||
logger.debug("Updating model.\n\tSQL: {}\n\tPARAMS: {}", query, params)
|
||||
sql.executeUpdate(query, params)
|
||||
return refresh(model) } }
|
||||
|
||||
public def create(def model) {
|
||||
def columns = []
|
||||
@ -164,7 +165,7 @@ public class ORM {
|
||||
String col1 = nameFromModel(modelClass1.simpleName) + "_id"
|
||||
String col2 = nameFromModel(modelClass2.simpleName) + "_id"
|
||||
|
||||
withTransaction {
|
||||
return withTransaction {
|
||||
def query = """\
|
||||
SELECT * FROM $linkTable
|
||||
WHERE "${col1}" = ? AND "${col2}" = ?"""
|
||||
@ -475,11 +476,24 @@ public class ORM {
|
||||
|
||||
public Playlist addToPlaylist(int playlistId, int mediaFileId) {
|
||||
return withTransaction {
|
||||
associate(Playlist, MediaFile, p, mf)
|
||||
def p = getById(Playlist, playlistId)
|
||||
if (!p) return null
|
||||
associate(Playlist, MediaFile, p, mf)
|
||||
p.mediaFileCount++
|
||||
update(p)
|
||||
return refresh(p) } }
|
||||
return update(p) } }
|
||||
|
||||
public Playlist removeAllFromPlaylist(int playlistId) {
|
||||
return withTransaction {
|
||||
def p = getById(Playlist, playlistId)
|
||||
if (!p) return null
|
||||
String query =
|
||||
"DELETE FROM playlists_media_files WHERE playlist_id = ?"
|
||||
def sqlParams = [playlistId]
|
||||
logger.debug("Clearing playlist.\n\tSQL: {}\n\tPARAMS: {}",
|
||||
query, sqlParams)
|
||||
sql.execute(query, sqlParams)
|
||||
p.mediaFileCount = 0
|
||||
return update(p) } }
|
||||
|
||||
public List<Playlist> removeEmptyPlaylists() {
|
||||
throw new UnsupportedOperationException("Not yet implemented.");
|
||||
@ -525,8 +539,8 @@ public class ORM {
|
||||
sqlParams << params.name } }
|
||||
|
||||
/// ### Utility functions
|
||||
public void withTransaction(Closure c) {
|
||||
try { sql.execute("BEGIN TRANSACTION"); c() }
|
||||
public def withTransaction(Closure c) {
|
||||
try { sql.execute("BEGIN TRANSACTION"); return c() }
|
||||
finally { sql.execute("COMMIT") }
|
||||
}
|
||||
public static String nameToModel(String name) {
|
||||
|
@ -11,7 +11,7 @@ public class Playlist extends Model {
|
||||
public int mediaFileCount = 0;
|
||||
public Integer copiedFromId = null;
|
||||
|
||||
public String toString() {
|
||||
public String toString() {
|
||||
if (userCreated) return name;
|
||||
return name + " (auto)"; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user