Skip to content

Commit

Permalink
Fix redirects with query params
Browse files Browse the repository at this point in the history
  • Loading branch information
Mosnar committed Jan 29, 2020
1 parent 538e2cd commit 533c491
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Characteristic Changelog

## 1.0.0 - 1/28/20
## Unreleased
## Fixed
Fixed error when saving an existing group (#40)

## 1.0.0-beta.1 - 1/28/20
### Added
- Initial release
12 changes: 10 additions & 2 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@

use Craft;
use craft\behaviors\FieldLayoutBehavior;
use craft\errors\MissingComponentException;
use craft\errors\SectionNotFoundException;
use craft\helpers\UrlHelper;
use craft\web\Controller;
use Throwable;
use venveo\characteristic\Characteristic;
use venveo\characteristic\elements\Characteristic as CharacteristicElement;
use venveo\characteristic\elements\CharacteristicValue as CharacteristicValueElement;
use venveo\characteristic\models\CharacteristicGroup;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;

Expand Down Expand Up @@ -115,13 +119,17 @@ public function actionEditGroup(int $groupId = null, CharacteristicGroup $group
*
* @return Response|null
* @throws BadRequestHttpException if any invalid site IDs are specified in the request
* @throws Throwable
* @throws MissingComponentException
* @throws SectionNotFoundException
* @throws ForbiddenHttpException
*/
public function actionSaveGroup()
{
$this->requirePostRequest();
$this->requireAdmin();

$request = Craft::$app->getRequest();

$group = new CharacteristicGroup();

// Main section settings
Expand Down Expand Up @@ -155,7 +163,7 @@ public function actionSaveGroup()
return null;
}

Craft::$app->getSession()->setNotice(Craft::t('characteristic', 'Group saved.'));
Craft::$app->getSession()->setNotice(Craft::t('characteristic', 'Characteristic group saved.'));

return $this->redirectToPostedUrl($group);
}
Expand Down
15 changes: 12 additions & 3 deletions src/services/CharacteristicGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Throwable;
use venveo\characteristic\elements\Characteristic;
use venveo\characteristic\elements\CharacteristicValue;
use venveo\characteristic\errors\CharacteristicGroupNotFoundException;
use venveo\characteristic\events\CharacteristicGroupEvent;
use venveo\characteristic\models\CharacteristicGroup;
use venveo\characteristic\records\CharacteristicGroup as CharacteristicGroupRecord;
Expand Down Expand Up @@ -308,9 +309,17 @@ public function saveGroup(CharacteristicGroup $group, bool $runValidation = true
if ($isNewGroup) {
$group->uid = StringHelper::UUID();
$structureUid = StringHelper::UUID();
} else if (!$group->uid) {
$group->uid = Db::uidById(CharacteristicGroupRecord::tableName(), $group->id);
$structureUid = Db::uidById(Table::STRUCTURES, $group->structureId);
} else {
$existingGroupRecord = CharacteristicGroupRecord::find()
->where(['id' => $group->id])
->one();

if (!$existingGroupRecord) {
throw new CharacteristicGroupNotFoundException("No characteristic group exists with the ID '{$group->id}'");
}

$group->uid = $existingGroupRecord->uid;
$structureUid = Db::uidById(Table::STRUCTURES, $existingGroupRecord->structureId);
}

// Assemble the section config
Expand Down

0 comments on commit 533c491

Please sign in to comment.