Skip to content

Commit

Permalink
Deleting elements for sites where the redirect should not exist. Keep…
Browse files Browse the repository at this point in the history
…ing this in the afterSave callback will have it run for each time the records are saved on the sites.
  • Loading branch information
leigh-ochsner committed Aug 1, 2019
1 parent 4874513 commit 8ffafa9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ public function actionSaveRedirect()

return null;
} else {
// remove form other sites
Craft::$app->getDb()->createCommand()
->delete('{{%elements_sites}}', [
'AND',
['elementId' => $redirect->id],
['!=', 'siteId', $siteId]
])
->execute();

if ($request->getAcceptsJson()) {
return $this->asJson([
'success' => true,
Expand Down
8 changes: 0 additions & 8 deletions src/elements/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,6 @@ public function afterSave(bool $isNew)

$record->save(false);

// remove form other sites
Craft::$app->getDb()->createCommand()
->delete('{{%elements_sites}}', [
'AND',
['elementId' => $record->id],
['!=', 'siteId', $this->siteId]
])
->execute();
parent::afterSave($isNew);
}

Expand Down

0 comments on commit 8ffafa9

Please sign in to comment.