+ try (GigiPreparedStatement statmt = new GigiPreparedStatement("SELECT 1 FROM `emailPinglog` WHERE `email`=? AND `uid`=? AND `type`='active' AND `status`='success'")) {
+ statmt.setString(1, address);
+ statmt.setInt(2, owner.getId());
+ GigiResultSet e = statmt.executeQuery();
+ return e.next();
+ }
+ }
+
+ public Date getLastPing(boolean onlySuccess) {
+ Date lastExecution;
+ try (GigiPreparedStatement statmt = new GigiPreparedStatement("SELECT MAX(`when`) FROM `emailPinglog` WHERE `email`=? AND `uid`=? AND `type`='active'" + (onlySuccess ? " AND `status`='success'" : ""))) {
+ statmt.setString(1, address);
+ statmt.setInt(2, owner.getId());
+ GigiResultSet e = statmt.executeQuery();
+ if ( !e.next()) {
+ return null;
+ }
+ lastExecution = e.getTimestamp(1);
+ }
+ return lastExecution;
+ }
+
+ public synchronized void requestReping(Language l) throws IOException, GigiApiException {
+ Date lastExecution = getLastPing(false);
+
+ if (lastExecution != null && lastExecution.getTime() + REPING_MINIMUM_DELAY >= System.currentTimeMillis()) {
+ throw new GigiApiException(SprintfCommand.createSimple("Reping is only allowed after {0} minutes, yours end at {1}.", REPING_MINIMUM_DELAY / 60 / 1000, new Date(lastExecution.getTime() + REPING_MINIMUM_DELAY)));
+ }
+ ping(l);
+ return;