Example #1
0
 /** @inheritdoc */
 public static function boot()
 {
     parent::boot();
     //  Ensure user is active upon creation
     static::creating(function (ServiceUser $model) {
         $model->active_ind = true;
     });
     static::created(function (ServiceUser $model) {
         AppKey::createKeyForEntity($model, OwnerTypes::SERVICE_USER);
     });
 }
Example #2
0
 /**
  * @param \DreamFactory\Enterprise\Database\Models\EnterpriseModel|mixed $row
  */
 protected static function enforceBusinessLogic($row)
 {
     parent::enforceBusinessLogic($row);
     $row->checkStorageKey();
 }
Example #3
0
 /**
  * Get an entity's owner and type
  *
  * @param EnterpriseModel $entity
  *
  * @return array|bool Array of attributes ['owner_id' => int, 'owner_type_nbr' => int] or FALSE if no key required
  */
 protected static function _getOwnerType(EnterpriseModel $entity)
 {
     //  Don't bother with archive or assignment tables
     if (!in_array(substr($entity->getTable(), -7), ['_asgn_t', '_arch_t'])) {
         //  Try user/service_user first
         if ($entity instanceof User) {
             return [$entity->id, OwnerTypes::USER];
         }
         if ($entity instanceof ServiceUser) {
             return [$entity->id, OwnerTypes::SERVICE_USER];
         }
         //  Anything with owner and type get tagged
         if (isset($entity->owner_id, $entity->owner_type_nbr)) {
             //  No owner to speak of...
             if (empty($entity->owner_id) && empty($entity->owner_type_nbr)) {
                 return [null, null];
             }
             return [$entity->owner_id, $entity->owner_type_nbr];
         }
         //  A user_id only means a user owns the entity (can't be zero either...)
         if (isset($entity->user_id) && !empty($entity->user_id)) {
             return [$entity->user_id, OwnerTypes::USER];
         }
     }
     return [null, null];
 }
 /**
  * @param \DreamFactory\Enterprise\Database\Models\EnterpriseModel|mixed $row
  */
 protected static function enforceBusinessLogic($row)
 {
     $_time = $row->freshTimestamp();
     //  Make sure the create_date is set
     if (!$row->exists && !$row->isDirty(static::CREATED_AT)) {
         $row->setCreatedAt($_time);
     }
     //  Make sure the lmod_date is set
     if ($row->exists && !$row->isDirty(static::CREATED_AT)) {
         $row->setUpdatedAt($_time);
     }
     //  Make sure owner type is set properly
     if (isset($row->owner_id, $row->owner_type_nbr)) {
         if (null !== $row->owner_id && null === $row->owner_type_nbr) {
             $row->owner_type_nbr = $row->getMorphClass();
         }
     }
 }