|
@@ -46,80 +46,6 @@ class AuditDataService
|
|
|
$this->entityManager = $entityManager;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get all revisions filtered for user and timestamp
|
|
|
- *
|
|
|
- * @param string $user
|
|
|
- * @param DateTime $dateFrom
|
|
|
- * @param DateTime $dateTo
|
|
|
- * @param int $page
|
|
|
- *
|
|
|
- * @return type
|
|
|
- */
|
|
|
- public function getRevisionsData($user, $dateFrom, $dateTo, $page)
|
|
|
- {
|
|
|
- //Set default page
|
|
|
- $show = 25;
|
|
|
-
|
|
|
- if (!$page) {
|
|
|
- $page = 1;
|
|
|
- }
|
|
|
-
|
|
|
- $sqlct = "SELECT Count(id) AS Total FROM revisions WHERE (id <> 0 AND username <> '') ";
|
|
|
- foreach ($user as $key => $usr) {
|
|
|
- if ($key == 0) {
|
|
|
- $sqlct .= "AND username LIKE '%{$usr}%' ";
|
|
|
- } else {
|
|
|
- $sqlct .= "OR username LIKE '%{$usr}%' ";
|
|
|
- }
|
|
|
- }
|
|
|
- if ($dateFrom != '') {
|
|
|
- $sqlct .= "AND (timestamp >= '{$dateFrom} 00:00:00') ";
|
|
|
- }
|
|
|
- if ($dateTo != '') {
|
|
|
- $sqlct .= "AND (timestamp <= '{$dateTo} 23:59:59') ";
|
|
|
- }
|
|
|
-
|
|
|
- // Sql for get data
|
|
|
- $sqlrev = "SELECT timestamp,id AS rev FROM revisions WHERE (id <> 0 AND username <> '') ";
|
|
|
- foreach ($user as $key => $usr) {
|
|
|
- if ($key == 0) {
|
|
|
- $sqlrev .= "AND username LIKE '%{$usr}%' ";
|
|
|
- } else {
|
|
|
- $sqlrev .= "OR username LIKE '%{$usr}%' ";
|
|
|
- }
|
|
|
- }
|
|
|
- if ($dateFrom != '') {
|
|
|
- $sqlrev .= "AND (timestamp >= '{$dateFrom} 00:00:00') ";
|
|
|
- }
|
|
|
- if ($dateTo != '') {
|
|
|
- $sqlrev .= "AND (timestamp <= '{$dateTo} 23:59:59') ";
|
|
|
- }
|
|
|
-
|
|
|
- // Count results
|
|
|
- $regs = $this->connection->fetchColumn($sqlct, array(1), 0);
|
|
|
-
|
|
|
- // Set pagination
|
|
|
- $from = ($page - 1) * $show;
|
|
|
- $To = ($page) * $show;
|
|
|
-
|
|
|
- if ($To > $regs) {
|
|
|
- $To = $regs;
|
|
|
- }
|
|
|
-
|
|
|
- $sqlrev .= "ORDER BY timestamp DESC LIMIT " . $from . ", " . $To;
|
|
|
-
|
|
|
- $query_result = $this->connection->fetchAll($sqlrev);
|
|
|
- $results_processed_changes = $this->results_with_processed_changes($query_result);
|
|
|
-
|
|
|
- $tdata = array(
|
|
|
- 'regs' => $regs,
|
|
|
- 'revisions' => $results_processed_changes,
|
|
|
- );
|
|
|
-
|
|
|
- return ($tdata);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @return array
|
|
|
*/
|
|
@@ -135,55 +61,6 @@ class AuditDataService
|
|
|
return $usernames;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get all revisions with the changes processed
|
|
|
- *
|
|
|
- * @param array $query_result
|
|
|
- *
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function results_with_processed_changes($query_result)
|
|
|
- {
|
|
|
- $param_query_result = $query_result;
|
|
|
- foreach ($param_query_result as $key => &$data) {
|
|
|
- $entity_results = array();
|
|
|
- $data['rev_data'] = $this->reader->findRevision($data['rev']);
|
|
|
- $data['rev_entities_data'] = $this->reader->findEntitiesChangedAtRevision($data['rev']);
|
|
|
- #Get entity of the revision
|
|
|
- $entity_revs = $data['rev_entities_data'];
|
|
|
-
|
|
|
- foreach ($entity_revs as $result) {
|
|
|
- $changes_all = array();
|
|
|
- #Get all revisions for each class in table revision
|
|
|
- $history_for_class = $this->reader->findRevisions($result->getClassName(), $result->getId());
|
|
|
-
|
|
|
- foreach ($history_for_class as $rev_history) {
|
|
|
- if ($rev_history->getRev() < $data['rev']) {
|
|
|
- $diff = $this->reader->diff($result->getClassName(), $result->getId(), $rev_history->getRev(), $data['rev']);
|
|
|
- foreach ($diff as $field => $value) {
|
|
|
- if ($value['old'] != "") {
|
|
|
- if (!is_a($value['old'], 'DateTime')) {
|
|
|
- $changes = array();
|
|
|
- $changes['field'] = $field;
|
|
|
- $changes['old'] = $value['old'];
|
|
|
- $changes['new'] = $value['new'];
|
|
|
- array_push($changes_all, $changes);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!isset($changes_all)) {
|
|
|
- $changes_all = array();
|
|
|
- }
|
|
|
- $data['changed_field'] = $changes_all;
|
|
|
- }
|
|
|
-
|
|
|
- return $param_query_result;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Applied diff between revisions
|
|
|
*
|