Example #1
0
 protected function logAuditEventsListForCreatedAndModifed($newModel)
 {
     if ($newModel) {
         AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_CREATED, strval($this), $this);
     } else {
         AuditUtil::logAuditEventsListForChangedAttributeValues($this);
     }
 }
Example #2
0
 /**
  * @param RedBean_OODBBean $bean
  * @param bool $setDefaults
  * @throws NoCurrentUserSecurityException
  */
 protected function constructDerived($bean, $setDefaults)
 {
     assert('$bean === null || $bean instanceof RedBean_OODBBean');
     assert('is_bool($setDefaults)');
     parent::constructDerived($bean, $setDefaults);
     // Even though setting the requestedByUser is not technically
     // a default in the sense of a Yii default rule,
     // if true the requestedByUser is not set because blank models
     // are used for searching mass updating.
     if ($bean === null && $setDefaults) {
         $currentUser = Yii::app()->user->userModel;
         if (!$currentUser instanceof User) {
             throw new NoCurrentUserSecurityException();
         }
         AuditUtil::saveOriginalAttributeValue($this, 'requestedByUser', $currentUser);
         $this->unrestrictedSet('requestedByUser', $currentUser);
     }
 }
Example #3
0
 public function save($runValidation = true, array $attributeNames = null)
 {
     AuditUtil::throwNotSupportedExceptionIfNotCalledFromAnItem();
     return parent::save($runValidation, $attributeNames);
 }
 protected function ownerChange($newOwnerValue)
 {
     $this->checkPermissionsHasAnyOf(Permission::CHANGE_OWNER);
     $this->isSetting = true;
     try {
         if (!$this->isSaving) {
             AuditUtil::saveOriginalAttributeValue($this, 'owner', $newOwnerValue);
         }
         parent::__set('owner', $newOwnerValue);
         $this->isSetting = false;
     } catch (Exception $e) {
         $this->isSetting = false;
         throw $e;
     }
 }
Example #5
0
 public static function stringifyAuditEvent(AuditEvent $auditEvent, $format = 'long')
 {
     assert('$format == "long" || $format == "short"');
     $s = null;
     switch ($auditEvent->eventName) {
         case self::AUDIT_EVENT_ITEM_CREATED:
         case self::AUDIT_EVENT_ITEM_DELETED:
             if ($format == 'short') {
                 return $auditEvent->eventName;
             }
             $s .= strval($auditEvent);
             $name = unserialize($auditEvent->serializedData);
             $s .= ", {$name}";
             break;
         case self::AUDIT_EVENT_ITEM_MODIFIED:
             list($name, $attributeNames, $oldValue, $newValue) = unserialize($auditEvent->serializedData);
             $modelClassName = $auditEvent->modelClassName;
             $model = new $modelClassName();
             if ($format == 'long') {
                 $s .= strval($auditEvent);
                 $s .= ", {$name}";
                 $s .= ', ' . Zurmo::t('ZurmoModule', 'Changed') . ' ';
             }
             $attributeModel = $model;
             $attributeLabels = array();
             for ($i = 0; $i < count($attributeNames); $i++) {
                 $attributeName = $attributeNames[$i];
                 if (!$attributeModel instanceof RedBeanModels) {
                     $attributeLabels[] = $attributeModel->getAttributeLabel($attributeName);
                 } else {
                     // TODO - auditing of related collections
                     $attributeLabels[] = 'Collection';
                     break;
                 }
                 if ($i < count($attributeNames) - 1) {
                     $attributeModel = $attributeModel->{$attributeName};
                 }
             }
             $s .= join(' ', $attributeLabels);
             $s .= ' ' . Zurmo::t('Core', 'from') . ' ';
             $s .= AuditUtil::stringifyValue($attributeModel, $attributeName, $oldValue, $format) . ' ';
             $s .= Zurmo::t('Core', 'to') . ' ';
             $s .= AuditUtil::stringifyValue($attributeModel, $attributeName, $newValue, $format);
             break;
     }
     return $s;
 }
Example #6
0
 public function setLatestActivityDateTime($dateTime)
 {
     assert('is_string($dateTime)');
     AuditUtil::saveOriginalAttributeValue($this, 'latestActivityDateTime', $dateTime);
     $this->unrestrictedSet('latestActivityDateTime', $dateTime);
 }
Example #7
0
 protected function logAuditEventsListForModified($newModel)
 {
     if ($newModel) {
         // When the first user is created there can be no
         // current user. Log the first user as creating themselves.
         if (Yii::app()->user->userModel == null || !Yii::app()->user->userModel->id > 0) {
             Yii::app()->user->userModel = $this;
         }
     } else {
         AuditUtil::logAuditEventsListForChangedAttributeValues($this);
     }
 }
Example #8
0
 protected function logAuditEventsListForCreatedAndModifed($newModel)
 {
     if ($newModel) {
         // When the first user is created there can be no
         // current user. Log the first user as creating themselves.
         if (Yii::app()->user->userModel == null || !Yii::app()->user->userModel->id > 0) {
             Yii::app()->user->userModel = $this;
         }
         AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_CREATED, strval($this), $this);
     } else {
         AuditUtil::logAuditEventsListForChangedAttributeValues($this);
     }
 }
Example #9
0
 protected function logAuditEventsListForModified($newModel)
 {
     if (!$newModel) {
         AuditUtil::logAuditEventsListForChangedAttributeValues($this);
     }
 }