use of web.AdminTask in project common by zenlunatics.
the class MailLists method readAndSend.
// --------------------------------------------------------------------------
@AdminTask
public void readAndSend() {
DBConnection db = new DBConnection(m_site);
Session session = Session.getInstance(new Properties(), null);
new File(m_site.getBaseFilePath().append("inbox").toString()).listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isDirectory() && file.getName().charAt(0) != '.')
readAndSend(file, session, db);
return false;
}
});
db.close();
}
use of web.AdminTask in project common by zenlunatics.
the class MailLists method checkAll.
// --------------------------------------------------------------------------
@AdminTask
public void checkAll(Request request) throws IOException {
HTMLWriter writer = request.writer;
List<String[]> rows = request.db.readRows(new Select("host,username,password,id,name").from("mail_lists").where("active"));
Session session = Session.getInstance(new Properties(), null);
for (String[] row : rows) if (row.length == 5 && row[0] != null && row[2] != null)
try {
Store store = session.getStore(((MailLists) request.site.getModule("MailLists")).m_store_protocol);
String account = accountName(row[1], Integer.parseInt(row[3]));
writer.h4(row[4]);
store.connect(row[0], account, row[2]);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message[] messages = folder.getMessages();
if (messages.length > 0) {
writer.write("<table border=\"1\">");
for (Message message : messages) {
writer.write("<tr><td>");
Date date = message.getReceivedDate();
if (date != null)
writer.write(date);
writer.write("</td><td>");
writer.write(message.getFrom()[0]);
writer.write("</td><td>");
writer.write(message.getSubject());
writer.write("</td><td>");
writer.write(message.getSize());
writer.write("</td></tr>");
}
writer.write("</table>");
} else
writer.write("0 messages");
folder.close(false);
store.close();
} catch (MessagingException e) {
writer.write(e.toString());
} catch (IOException e) {
writer.write(e.toString());
}
}
use of web.AdminTask in project common by zenlunatics.
the class FileColumn method checkFilesInDatabase.
// --------------------------------------------------------------------------
@AdminTask({ "table", "column", "show only problems" })
public static void checkFilesInDatabase(String table, String column, boolean show_only_problems, Request request) {
HTMLWriter writer = request.writer;
try {
FileColumn file_column = (FileColumn) request.site.getViewDef(table, request.db).getColumn(column);
String dir_column = file_column.getDirColumn();
StringBuilder sql = new StringBuilder("SELECT ").append(column);
if (dir_column != null)
sql.append(',').append(dir_column);
sql.append(" FROM ").append(table).append(" ORDER BY ");
if (dir_column != null)
sql.append(dir_column).append(',');
sql.append(column);
ResultSet rs = request.db.select(sql.toString());
writer.write("<table class=\"table table-condensed table-bordered\" style=\"width:auto;\"><tr><th>filename</th>");
if (dir_column != null)
writer.write("<th>dir column</th>");
writer.write("<th>status</th></tr>");
while (rs.next()) {
String dir_column_value = null;
String filename = rs.getString(1);
String problem = null;
if (filename == null)
problem = column + " is null";
else {
if (dir_column != null)
dir_column_value = rs.getString(2);
FilePathStringBuilder file_path = file_column.getDirectory(dir_column_value, request.site);
file_path.append(filename);
if (!new File(file_path.toString()).exists())
problem = "missing";
}
if (problem != null || !show_only_problems) {
writer.write("<tr><td>");
if (filename != null)
writer.write(filename);
if (dir_column != null) {
writer.write("</td><td>");
if (dir_column_value != null)
writer.write(dir_column_value);
}
writer.write("</td><td>").write(problem == null ? "ok" : problem).write("</td></tr>");
}
}
writer.write("</table>");
rs.getStatement().close();
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of web.AdminTask in project common by zenlunatics.
the class FileColumn method checkFilesNotInDatabase.
// --------------------------------------------------------------------------
@AdminTask({ "table", "column" })
public static void checkFilesNotInDatabase(final String table, final String column, final Request request) {
try {
FileColumn file_column = (FileColumn) request.site.getViewDef(table, request.db).getColumn(column);
request.writer.h3("Files not in database");
new File(file_column.getDirectory(request).toString()).list(new FilenameFilter() {
@Override
public boolean accept(File file, String filename) {
if (!request.db.rowExists(table, column + "='" + DBConnection.escape(filename) + "'"))
try {
request.writer.write(filename).br();
} catch (IOException e) {
}
return false;
}
});
} catch (IOException e) {
request.abort(e);
}
}
use of web.AdminTask in project common by zenlunatics.
the class Pictures method syncPictures.
// --------------------------------------------------------------------------
@AdminTask
public void syncPictures(Request request) {
FilePathStringBuilder file_path = request.site.getBaseFilePath();
file_path.append(m_table);
String pictures_directory = file_path.toString() + File.separator;
String[] files = new File(pictures_directory).list();
for (String file : files) {
String id = file;
int index = id.indexOf('.');
if (index != -1)
id = id.substring(0, index);
if (Character.isDigit(file.charAt(0)) && request.db.lookupString("id", "pictures", Integer.parseInt(id)) == null)
new File(pictures_directory + file).delete();
}
files = new File(pictures_directory + "thumbs/").list();
for (String file : files) if (Character.isDigit(file.charAt(0))) {
String id = file;
int index = id.indexOf('.');
if (index != -1)
id = id.substring(0, index);
if (request.db.lookupString("id", "pictures", Integer.parseInt(id)) == null)
new File(pictures_directory + "thumbs/" + file).delete();
}
}
Aggregations