]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Domain.java
Merge "Fix error message"
[gigi.git] / src / org / cacert / gigi / dbObjects / Domain.java
index 043277cf4ab3f2108a90efe040635e25d172ec12..3ecf728567f6c166aa5dc960091c8c26061c6f28 100644 (file)
@@ -66,9 +66,12 @@ public class Domain implements IdCachable, Verifyable {
         if (id == 0) {
             throw new GigiApiException("not inserted.");
         }
-        try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domains` SET `deleted`=CURRENT_TIMESTAMP WHERE `id`=?")) {
-            ps.setInt(1, id);
-            ps.execute();
+        synchronized (Domain.class) {
+            myCache.remove(this);
+            try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domains` SET `deleted`=CURRENT_TIMESTAMP WHERE `id`=?")) {
+                ps.setInt(1, id);
+                ps.execute();
+            }
         }
     }
 
@@ -107,7 +110,7 @@ public class Domain implements IdCachable, Verifyable {
     public void addPing(DomainPingType type, String config) throws GigiApiException {
         try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `pingconfig` SET `domainid`=?, `type`=?::`pingType`, `info`=?")) {
             ps.setInt(1, id);
-            ps.setString(2, type.toString().toLowerCase());
+            ps.setEnum(2, type);
             ps.setString(3, config);
             ps.execute();
         }
@@ -126,7 +129,9 @@ public class Domain implements IdCachable, Verifyable {
         try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `state`='open' AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=? AND `type`='email')")) {
             ps.setString(1, hash);
             ps.setInt(2, id);
-            ps.executeUpdate();
+            if ( !ps.executeMaybeUpdate()) {
+                throw new IllegalArgumentException("Given token could not be found to complete the verification process (Domain Ping).");
+            }
         }
     }
 
@@ -170,8 +175,8 @@ public class Domain implements IdCachable, Verifyable {
         return em;
     }
 
-    public static Domain searchUserIdByDomain(String domain) {
-        try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `domains` WHERE `domain` = ?")) {
+    public static Domain searchDomain(String domain) {
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `domains` WHERE `domain` = ? AND `deleted` IS NULL")) {
             ps.setString(1, domain);
             GigiResultSet res = ps.executeQuery();
             if (res.next()) {