Example #1
0
 public function testPrepare()
 {
     $this->_initSequenceTables();
     // test audit first
     $audit = new Audit();
     $audit->_ormPersist = true;
     $audit->objectClass = 'StdClass';
     $audit->persist();
     $this->assertTrue($audit->auditId > 0, 'Audit: Failed to persist');
     if ($audit->auditId > 0) {
         $audit->setPersistMode(WebVista_Model_ORM::DELETE);
         $audit->persist();
     }
     $auditValue = new AuditValue();
     $auditValue->_ormPersist = true;
     $auditValue->key = 'Key';
     $auditValue->value = 'Value';
     $auditValue->persist();
     $this->assertTrue($auditValue->auditValueId > 0, 'AuditValue: Failed to persist');
     if ($auditValue->auditValueId > 0) {
         $auditValue->setPersistMode(WebVista_Model_ORM::DELETE);
         $auditValue->persist();
     }
     if ($this->_autoLoggedIn) {
         $this->_setupAutoLogin();
     }
 }
Example #2
0
 /** 
  * Store changes to the audit log
  */
 function audit($obj)
 {
     $audit = new Audit();
     $audit->objectClass = get_class($obj);
     $classObjectIdKey = lcfirst($audit->objectClass);
     $objectIdKey = $classObjectIdKey . "Id";
     $objectLegacyIdKey = strtolower(preg_replace('/([A-Z]{1})/', '_\\1', $classObjectIdKey)) . "_id";
     if (!isset($obj->{$objectIdKey}) && !isset($obj->{$objectLegacyIdKey})) {
         //trigger_error("objIdKey not found: $objectIdKey for " . get_class($obj),E_USER_NOTICE);
         return false;
     }
     $audit->objectId = $obj->{$objectIdKey};
     $audit->userId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $audit->type = $obj->_persistMode;
     $audit->dateTime = date('Y-m-d H:i:s');
     $audit->persist();
     if ($obj instanceof ORM) {
         foreach ($obj->ORMFields() as $field) {
             $auditValue = new AuditValue();
             $auditValue->auditId = $audit->auditId;
             $auditValue->key = $field;
             if (is_object($obj->{$field})) {
                 $auditValue->value = get_class($obj->{$field});
             } else {
                 $auditValue->value = (string) $obj->{$field};
             }
             $auditValue->persist();
         }
     }
 }