|
|
@@ -69,7 +69,6 @@ class CleanDb extends BaseCronJob implements CronjobInterface
|
|
|
$maxDateAudit = DatesUtils::new();
|
|
|
$maxDateAudit->sub(new \DateInterval('P' . self::PURGE_AUDIT_RECORDS_OLDER_THAN . 'D'));
|
|
|
|
|
|
- $this->ui->print('Purge DB from temporary records modified before '.$maxDate->format('c'));
|
|
|
$this->connection->beginTransaction();
|
|
|
$this->connection->setAutoCommit(false);
|
|
|
|
|
|
@@ -132,7 +131,7 @@ class CleanDb extends BaseCronJob implements CronjobInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Purge Message table and returns the number of deleted records
|
|
|
+ * Purge Message and ReportMessage tables and returns the number of deleted records
|
|
|
*
|
|
|
* @param DateTime $maxDate
|
|
|
* @return int
|
|
|
@@ -142,23 +141,30 @@ class CleanDb extends BaseCronJob implements CronjobInterface
|
|
|
{
|
|
|
$this->ui->print('Purge DB from records of message create before ' . $maxDate->format('c'));
|
|
|
|
|
|
- $q = $this->connection->createQueryBuilder();
|
|
|
+ $sql = "DELETE r
|
|
|
+ FROM opentalent.Message m
|
|
|
+ inner join opentalent.ReportMessage r on r.message_id = m.id
|
|
|
+ where m.dateSent < :maxDate and m.isSystem = true and m.id > 0;";
|
|
|
|
|
|
- $q->delete('Message')
|
|
|
- ->andWhere( $q->expr()->gt('id', 0))
|
|
|
- ->andWhere( $q->expr()->lt('dateSent', $maxDate->format('Y-m-d')))
|
|
|
- ->andWhere( $q->expr()->eq('isSystem', true))
|
|
|
- ;
|
|
|
+ $stmt = $this->connection->prepare($sql);
|
|
|
+ $purgedReportMessage = $stmt->executeStatement(['maxDate' => $maxDate->format('c')]);
|
|
|
|
|
|
- $purged = $q->execute();
|
|
|
+ $this->ui->print('* ReportMessage : '.$purgedReportMessage.' lines to delete');
|
|
|
|
|
|
- $this->ui->print('* Message : '.$purged.' lines to delete');
|
|
|
+ $sql = "DELETE
|
|
|
+ FROM opentalent.Message
|
|
|
+ where dateSent < :maxDate and isSystem = true and id > 0;";
|
|
|
|
|
|
- return $purged;
|
|
|
+ $stmt = $this->connection->prepare($sql);
|
|
|
+ $purgedMessage = $stmt->executeStatement(['maxDate' => $maxDate->format('c')]);
|
|
|
+
|
|
|
+ $this->ui->print('* Message : '.$purgedMessage.' lines to delete');
|
|
|
+
|
|
|
+ return $purgedReportMessage + $purgedMessage;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Purge Information (Notification Discr) table and returns the number of deleted records
|
|
|
+ * Purge Information (Notification Discr) and NotificationUser tables, and returns the number of deleted records
|
|
|
*
|
|
|
* @param DateTime $maxDate
|
|
|
* @return int
|
|
|
@@ -168,17 +174,25 @@ class CleanDb extends BaseCronJob implements CronjobInterface
|
|
|
{
|
|
|
$this->ui->print('Purge DB from records of notifications create before ' . $maxDate->format('c'));
|
|
|
|
|
|
- $q = $this->connection->createQueryBuilder();
|
|
|
+ $sql = "DELETE u
|
|
|
+ FROM opentalent.Information i
|
|
|
+ inner join opentalent.NotificationUser u on u.notification_id = i.id
|
|
|
+ where i.createDate < :maxDate and i.discr = 'notification';";
|
|
|
+
|
|
|
+ $stmt = $this->connection->prepare($sql);
|
|
|
+ $purgedNotificationUser = $stmt->executeStatement(['maxDate' => $maxDate->format('c')]);
|
|
|
+
|
|
|
+ $this->ui->print('* NotificationUser : '.$purgedNotificationUser.' lines to delete');
|
|
|
|
|
|
- $q->delete('Information')
|
|
|
- ->andWhere( $q->expr()->eq('discr', '"notification"'))
|
|
|
- ->andWhere( $q->expr()->lt('createDate', $maxDate->format('Y-m-d')))
|
|
|
- ;
|
|
|
+ $sql = "DELETE
|
|
|
+ FROM opentalent.Information
|
|
|
+ where createDate < :maxDate and discr = 'notification';";
|
|
|
|
|
|
- $purged = $q->execute();
|
|
|
+ $stmt = $this->connection->prepare($sql);
|
|
|
+ $purgedNotification = $stmt->executeStatement(['maxDate' => $maxDate->format('c')]);
|
|
|
|
|
|
- $this->ui->print('* Information : '.$purged.' lines to delete');
|
|
|
+ $this->ui->print('* Information : '.$purgedNotification.' lines to delete');
|
|
|
|
|
|
- return $purged;
|
|
|
+ return $purgedNotificationUser + $purgedNotification;
|
|
|
}
|
|
|
}
|