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();
}
}
use of web.AdminTask in project common by zenlunatics.
the class Pictures method recordAllSizes.
// --------------------------------------------------------------------------
@AdminTask
public void recordAllSizes(Request request) {
ResultSet rs = request.db.select(new Select("id,file").from(m_table));
try {
while (rs.next()) {
BufferedImage image = ImageIO.read(new File(request.site.getBaseFilePath().append(m_table).append(rs.getString("file")).toString()));
request.db.update(m_table, "width=" + image.getWidth() + ",height=" + image.getHeight(), rs.getInt("id"));
}
rs.getStatement().close();
} catch (SQLException e) {
request.abort(e);
} catch (IOException e) {
request.abort(e);
}
}
use of web.AdminTask in project common by zenlunatics.
the class News method rebuild.
// --------------------------------------------------------------------------
@AdminTask
public void rebuild(String provider_name, Request request) throws IOException {
NewsProvider provider = getProvider(provider_name);
if (provider == null) {
request.writer.write("provider " + provider_name + " not found");
return;
}
request.db.delete("news", "provider='" + provider_name + "'");
try {
ResultSet rs = request.db.select(new Select("*").from(provider.getTable()));
NameValuePairs name_value_pairs = new NameValuePairs();
while (rs.next()) {
name_value_pairs.clear();
name_value_pairs.set("provider", provider_name);
name_value_pairs.set("item_id", rs.getInt("id"));
name_value_pairs.set("_owner_", rs.getInt("_owner_"));
String timestamp = rs.getString("_timestamp_");
name_value_pairs.set("_timestamp_", timestamp);
name_value_pairs.set("last_update", timestamp);
for (JDBCColumn column : provider.m_duplicate_columns) name_value_pairs.set(column.name, rs.getString(column.name));
request.db.insert("news", name_value_pairs);
}
rs.getStatement().close();
} catch (SQLException e) {
request.abort(e);
}
}
Aggregations