diff --git a/src/records/OrganizationTypeAssociation.php b/src/records/OrganizationTypeAssociation.php index 850e49d..5cff184 100644 --- a/src/records/OrganizationTypeAssociation.php +++ b/src/records/OrganizationTypeAssociation.php @@ -11,7 +11,9 @@ use Craft; use flipbox\craft\ember\records\ActiveRecord; use flipbox\craft\ember\records\SortableTrait; +use flipbox\organizations\Organizations; use flipbox\organizations\queries\OrganizationTypeAssociationQuery; +use yii\helpers\Json; /** * @author Flipbox Factory @@ -103,12 +105,29 @@ public function beforeSave($insert) */ public function afterSave($insert, $changedAttributes) { - $this->autoReOrder( - 'typeId', - [ - 'organizationId' => $this->organizationId - ] - ); + try { + $this->autoReOrder( + 'typeId', + [ + 'organizationId' => $this->organizationId + ] + ); + } catch (\Exception $e) { + Organizations::error( + sprintf( + "Exception caught while trying to reorder '%s'. Exception: [%s].", + (string)get_class($this), + (string)Json::encode([ + 'Trace' => $e->getTraceAsString(), + 'File' => $e->getFile(), + 'Line' => $e->getLine(), + 'Code' => $e->getCode(), + 'Message' => $e->getMessage() + ]) + ), + __METHOD__ + ); + } parent::afterSave($insert, $changedAttributes); } diff --git a/src/records/UserAssociation.php b/src/records/UserAssociation.php index 99f5327..e662154 100644 --- a/src/records/UserAssociation.php +++ b/src/records/UserAssociation.php @@ -19,6 +19,7 @@ use flipbox\organizations\Organizations; use flipbox\organizations\queries\UserAssociationQuery; use yii\db\ActiveQueryInterface; +use yii\helpers\Json; /** * @author Flipbox Factory @@ -182,23 +183,40 @@ public function beforeSave($insert) */ public function afterSave($insert, $changedAttributes) { - if (Organizations::getInstance()->getSettings()->getEnforceUserSortOrder()) { - $this->autoReOrder( - 'userId', - [ - 'organizationId' => $this->organizationId - ], - 'userOrder' - ); - } + try { + if (Organizations::getInstance()->getSettings()->getEnforceUserSortOrder()) { + $this->autoReOrder( + 'userId', + [ + 'organizationId' => $this->organizationId + ], + 'userOrder' + ); + } - if (Organizations::getInstance()->getSettings()->getEnforceOrganizationSortOrder()) { - $this->autoReOrder( - 'organizationId', - [ - 'userId' => $this->userId - ], - 'organizationOrder' + if (Organizations::getInstance()->getSettings()->getEnforceOrganizationSortOrder()) { + $this->autoReOrder( + 'organizationId', + [ + 'userId' => $this->userId + ], + 'organizationOrder' + ); + } + } catch (\Exception $e) { + Organizations::error( + sprintf( + "Exception caught while trying to reorder '%s'. Exception: [%s].", + (string)get_class($this), + (string)Json::encode([ + 'Trace' => $e->getTraceAsString(), + 'File' => $e->getFile(), + 'Line' => $e->getLine(), + 'Code' => $e->getCode(), + 'Message' => $e->getMessage() + ]) + ), + __METHOD__ ); } diff --git a/src/records/UserTypeAssociation.php b/src/records/UserTypeAssociation.php index 16f852a..314df23 100644 --- a/src/records/UserTypeAssociation.php +++ b/src/records/UserTypeAssociation.php @@ -12,8 +12,10 @@ use flipbox\craft\ember\helpers\ModelHelper; use flipbox\craft\ember\records\ActiveRecord; use flipbox\craft\ember\records\SortableTrait; +use flipbox\organizations\Organizations; use flipbox\organizations\queries\UserTypeAssociationQuery; use yii\db\ActiveQueryInterface; +use yii\helpers\Json; /** * @author Flipbox Factory @@ -103,12 +105,29 @@ public function beforeSave($insert) */ public function afterSave($insert, $changedAttributes) { - $this->autoReOrder( - 'typeId', - [ - 'userId' => $this->userId - ] - ); + try { + $this->autoReOrder( + 'typeId', + [ + 'userId' => $this->userId + ] + ); + } catch (\Exception $e) { + Organizations::error( + sprintf( + "Exception caught while trying to reorder '%s'. Exception: [%s].", + (string)get_class($this), + (string)Json::encode([ + 'Trace' => $e->getTraceAsString(), + 'File' => $e->getFile(), + 'Line' => $e->getLine(), + 'Code' => $e->getCode(), + 'Message' => $e->getMessage() + ]) + ), + __METHOD__ + ); + } parent::afterSave($insert, $changedAttributes); }