Skip to content

Commit

Permalink
Fix #15 - Foreign constraint failure when deleting asset subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
smarineau-cyr committed Sep 13, 2017
1 parent 5b5f2c0 commit a956773
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 8 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[
{
"version": "1.1.5",
"downloadUrl": "https://github.com/surrealpistach/Craft-FocusPoint/archive/1.1.5.zip",
"date": "2017-09-13 13:45:00",
"notes": [
"Fix Foreign constraint failure when deleting asset subfolder"
]
},
{
"version": "1.1.4",
"downloadUrl": "https://github.com/surrealpistach/Craft-FocusPoint/archive/1.1.4.zip",
Expand Down
20 changes: 13 additions & 7 deletions focuspoint/FocusPointPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function getName()

public function getVersion()
{
return '1.1.4';
return '1.1.5';
}

public function getSchemaVersion()
Expand Down Expand Up @@ -47,12 +47,18 @@ public function getReleaseFeedUrl()

public function init()
{
craft()->on('elements.onBeforeDeleteElements', function (Event $event) {
$elementIds = $event->params['elementIds'];
foreach ($elementIds as $elementId) {
craft()->focusPoint_focusPoint->deleteFocusPointRecordsBySourceId($elementId);
}
});
craft()->on('elements.onBeforeDeleteElements', function (Event $event) {
$elementIds = $event->params['elementIds'];
foreach ($elementIds as $elementId) {
$element = craft()->elements->getElementById($elementId);
if ($element->elementType === "Asset") {
craft()->focusPoint_focusPoint->deleteFocusPointRecordsByAssetId($elementId);
}
else {
craft()->focusPoint_focusPoint->deleteFocusPointRecordsBySourceId($elementId);
}
}
});

craft()->on('assets.onBeforeDeleteAsset', function (Event $event) {
$asset = $event->params["asset"];
Expand Down

0 comments on commit a956773

Please sign in to comment.