Added the ability to untag media files in core.
This commit is contained in:
parent
328957d6f7
commit
eb17561d77
@ -811,6 +811,24 @@ public class ORM {
|
||||
params)
|
||||
sql.executeInsert(insertQuery, params) } } } } }
|
||||
|
||||
public def untagMediaFiles(List<Integer> mediaFileIds,
|
||||
List<String> tagNames) {
|
||||
|
||||
withTranscation {
|
||||
List<Tag> tags = tagNames.collect(getTagByName).findAll()
|
||||
def tagPlaceholders = tags.collect { '?' }.join(', ')
|
||||
def tagIds = tags.collect { it.id }
|
||||
|
||||
String deleteQuery = """
|
||||
DELETE FROM media_files_tags
|
||||
WHERE tag_id IN ($tagPlaceHolders) AND media_file_id = ?"""
|
||||
|
||||
mediaFileIds.each { mfId ->
|
||||
def params = tagIds + mfId
|
||||
logger.debug('Removing tags.\n\tSQL: {}\n\tPARAMS: {}',
|
||||
deleteQuery, params)
|
||||
sql.execute(deleteQuery, params) } } }
|
||||
|
||||
/// ### Utility functions
|
||||
public def withTransaction(Closure c) {
|
||||
try { sql.execute('BEGIN TRANSACTION'); return c() }
|
||||
|
Loading…
Reference in New Issue
Block a user