stmt.execute()
}
- uris.forEach { uri ->
- // disable all feeds first and then re-activate all feeds from the uri list
- conn.prepareStatement("update feeds set disabled = TRUE where feedcollection_id = ?").use { stmt ->
+ var updateList = true
+ // check if the old and new list only contain a single uri
+ if(uris.size == 1) {
+ conn.prepareStatement("select count(*) from feeds where feedcollection_id = ? and disabled = FALSE").use { stmt ->
stmt.setInt(1, feed.id)
+ stmt.executeQuery().use { rs ->
+ if(rs.next() && rs.getInt(1) == 1) {
+ updateList = false
+ }
+ }
+ }
+ }
+
+ if(updateList) {
+ // disable all feeds first and then re-activate all feeds from the uri list
+ conn.prepareStatement("""
+ update feeds set auth_user = ?, auth_password = ?, certpath = ?, disabled = TRUE
+ where feedcollection_id = ?
+ """.trimIndent()).use { stmt ->
+ stmt.setString(1, user)
+ stmt.setString(2, password)
+ stmt.setString(3, cert)
+ stmt.setInt(4, feed.id)
stmt.execute()
}
+ // merge url list
+ uris.forEach { uri ->
+ conn.prepareStatement("""
+ merge into feeds f
+ using (select cast(? as int) as feedcollection_id, cast(? as varchar) as url) v
+ on (f.feedcollection_id = v.feedcollection_id and f.url = v.url)
+ when matched then update set
+ f.disabled = false
+ when not matched then insert(feedcollection_id, url, auth_user, auth_password, certpath)
+ values (v.feedcollection_id, v.url, ?, ?, ?)
+ """.trimMargin()).use { stmt ->
+ stmt.setInt(1, feed.id)
+ stmt.setString(2, uri)
+ stmt.setString(3, user)
+ stmt.setString(4, password)
+ stmt.setString(5, cert)
+ stmt.execute()
+ }
+ }
+ } else {
+ // just update the single feed
conn.prepareStatement("""
update feeds set
url = ?,
auth_user = ?,
auth_password = ?,
- certpath = ?,
- disabled = FALSE
- where feedcollection_id = ? and url = ?
- """.trimMargin()).use { stmt ->
- stmt.setString(1, uri)
+ certpath = ?
+ where feedcollection_id = ?
+ """.trimIndent()).use { stmt ->
+ stmt.setString(1, uris.first())
stmt.setString(2, user)
stmt.setString(3, password)
stmt.setString(4, cert)
stmt.setInt(5, feed.id)
- stmt.setString(6, uri)
stmt.execute()
}
}
itemStateMode = 0
}
println("groupSel: ${groups.selectedIndex}, feedName: $feedName, urlStr: $urlStr")
+ var u:String? = user.toString()
+ var p:String? = password.toString()
+
+ if(u?.isEmpty() == true) {
+ u = null
+ }
+ if(p?.isEmpty() == true) {
+ p = null
+ }
parent?.let {
FeedConfig.PreviousGroup = it
try {
parent = it,
name = feedName,
uris = uris,
- user = user.toString(),
- password = password.toString(),
- cert = cert.toString(),
+ user = u,
+ password = p,
+ cert = null, //cert.toString(),
internalBrowser = internalBrowser,
updateInterval = updateIntv,
maxItemAge = maxItemAge,
}
public fun updateFeed() {
- val parent = groups.selected
val feedName = name.toString()
val urlStr = urls.toString()
val uris = urlStr.split("\n").map { it.trim() }.filter { it.isNotBlank() }
itemStateMode = 0
}
- var user: String? = null
- var password: String? = null
- var cert: String? = null
+ var u:String? = user.toString()
+ var p:String? = password.toString()
- val u = user.toString()
- val p = password.toString()
- if(u.isNotBlank()) {
- user = u
+ if(u?.isEmpty() == true) {
+ u = null
}
- if(p.isNotBlank()) {
- password = p
+ if(p?.isEmpty() == true) {
+ p = null
}
feedCollection?.let {
it.internalBrowser = internalBrowser
it.maxItemAge = maxItemAge
try {
- Database.updateFeedCollection(it, uris, user, password, cert)
+ Database.updateFeedCollection(it, uris, u, p, null)
} catch (e: Exception) {
e.printStackTrace()
}