mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 22:51:59 +01:00
Improved the export-attachments contrib script
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
4b79925c60
commit
0d1d6cd012
@ -472,6 +472,8 @@ define('HEALTH_WORKER_URL', SITE_URL . 'index.php?route=health/worker');
|
||||
|
||||
define('LDAP_TYPE_GENERIC', 'generic_ldap');
|
||||
|
||||
define('ATTACHMENT_DUMP_CHECKPOINT', 'attachment_dump_checkpoint');
|
||||
|
||||
define('ACTION_ALL', 0);
|
||||
define('ACTION_UNKNOWN', 1);
|
||||
define('ACTION_LOGIN', 2);
|
||||
|
@ -25,7 +25,9 @@ Registry::set('db', $db);
|
||||
Registry::set('auditor_user', 1);
|
||||
|
||||
$outdir = "/path/to/attachments";
|
||||
$limit = 1000;
|
||||
|
||||
openlog("export-attachments", LOG_PID, LOG_MAIL);
|
||||
|
||||
|
||||
$domain = new ModelDomainDomain();
|
||||
$attachment = new ModelMessageAttachment();
|
||||
@ -33,8 +35,13 @@ $message = new ModelSearchMessage();
|
||||
|
||||
$domains = $domain->get_mapped_domains();
|
||||
|
||||
$last_id = $attachment->get_last_attachment_id();
|
||||
$start_id = $attachment->get_checkpoint();
|
||||
|
||||
for($i=1; $i<$limit; $i++) {
|
||||
syslog(LOG_INFO, "start: $start, limit: $limit");
|
||||
|
||||
|
||||
for($i=$start_id; $i<$last_id; $i++) {
|
||||
$a = $attachment->get_attachment_by_id($i);
|
||||
$m = $message->get_message_addresses_by_piler_id($a['piler_id'], $domains);
|
||||
|
||||
@ -43,4 +50,8 @@ for($i=1; $i<$limit; $i++) {
|
||||
foreach($m['rcpt'] as $rcpt) {
|
||||
$attachment->dump_attachment($outdir, "in", $rcpt, $i, $a);
|
||||
}
|
||||
|
||||
if($i % 100 == 0) { $attachment->update_checkpoint($i); }
|
||||
}
|
||||
|
||||
$attachment->update_checkpoint($i);
|
@ -2,7 +2,6 @@
|
||||
|
||||
class ModelMessageAttachment extends Model {
|
||||
|
||||
|
||||
public function get_attachment_by_id($id = 0) {
|
||||
if($id <= 0) { return []; }
|
||||
|
||||
@ -101,4 +100,30 @@ class ModelMessageAttachment extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_last_attachment_id() {
|
||||
$query = $this->db->query("SELECT id FROM " . TABLE_ATTACHMENT . " ORDER BY id DESC LIMIT 1");
|
||||
|
||||
if(isset($query->row['id'])) {
|
||||
return $query->row['id'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public function get_checkpoint() {
|
||||
$query = $this->db->query("SELECT value FROM `" . TABLE_OPTION . "` WHERE `key`=?", [ATTACHMENT_DUMP_CHECKPOINT]);
|
||||
if(isset($query->row['value'])) {
|
||||
return $query->row['value'];
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . TABLE_OPTION . "` (`key`, value) VALUES(?,0)", [ATTACHMENT_DUMP_CHECKPOINT]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function update_checkpoint($value=0) {
|
||||
$this->db->query("UPDATE `" . TABLE_OPTION . "` SET value=? WHERE `key`=?", [$value, ATTACHMENT_DUMP_CHECKPOINT]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user