Get all audit recordes for a module with Sugar Query?!

Is it possible to get all audit records for a specific module, Similar to a database query to load the table. Not only the ones linked to specific record.

What is the sugar query equivalent of this MySQL call;

SELECT *

FROM accounts_audit

Best regards

Gustav Lindstrom

Parents
  • 1) For example, you need get audit for module Accounts:

    $bean = new Account();

    $bean->retrieve($id); //audit log only for record

    $audit = new Audit();

    $audit_for_module = $audit->getAuditLog($bean);

    2) By custom query:

    $auditTable = 'Account';

    $query = "SELECT {$auditTable}.*

      FROM {$auditTable}

      ORDER BY {$auditTable}.date_created DESC";

    $db = DBManagerFactory::getInstance();

    $results = $db->query($query);


Reply
  • 1) For example, you need get audit for module Accounts:

    $bean = new Account();

    $bean->retrieve($id); //audit log only for record

    $audit = new Audit();

    $audit_for_module = $audit->getAuditLog($bean);

    2) By custom query:

    $auditTable = 'Account';

    $query = "SELECT {$auditTable}.*

      FROM {$auditTable}

      ORDER BY {$auditTable}.date_created DESC";

    $db = DBManagerFactory::getInstance();

    $results = $db->query($query);


Children
  • Not sure if I understand the answer, non of the alternatives is utilizing sugarquery. The second one seem to be loading the accounts table not the accounts_audit table?!

  • There is no sugar query funktion for retriving all audit row for example all accounts.

    You can look at the getAuditLog function in '\modules\Audit\audit.php' and rewrite the code too get all aduit row not only the ones linked to a record

    I ended up doing doing something like this (I'm gonna add date formating as well)

    $auditTable = 'accounts_audit';
    $query = "SELECT {$auditTable}.*
    FROM {$auditTable}
    ORDER BY {$auditTable}.date_created DESC";
    $db = DBManagerFactory::getInstance();
    $results = $db->query($query);
    $return = array();
    while ($row = $db->fetchByAssoc($results)) {
             $return[] = $row;

            }

            return $return;