mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 06:53:47 +08:00
Disassociate child tag when parent is deleted. fixes flarum/core#962
This commit is contained in:
parent
1dc495dfdd
commit
020d850a3a
21
extensions/tags/js/admin/dist/extension.js
vendored
21
extensions/tags/js/admin/dist/extension.js
vendored
|
@ -793,11 +793,26 @@ System.register('flarum/tags/components/EditTagModal', ['flarum/components/Modal
|
|||
}, {
|
||||
key: 'delete',
|
||||
value: function _delete() {
|
||||
var _this4 = this;
|
||||
|
||||
if (confirm(app.translator.trans('flarum-tags.admin.edit_tag.delete_tag_confirmation'))) {
|
||||
this.tag.delete().then(function () {
|
||||
return m.redraw();
|
||||
(function () {
|
||||
var children = app.store.all('tags').filter(function (tag) {
|
||||
return tag.parent() === _this4.tag;
|
||||
});
|
||||
this.hide();
|
||||
|
||||
_this4.tag.delete().then(function () {
|
||||
children.forEach(function (tag) {
|
||||
return tag.pushData({
|
||||
attributes: { isChild: false },
|
||||
relationships: { parent: null }
|
||||
});
|
||||
});
|
||||
m.redraw();
|
||||
});
|
||||
|
||||
_this4.hide();
|
||||
})();
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
|
|
@ -110,7 +110,16 @@ export default class EditTagModal extends Modal {
|
|||
|
||||
delete() {
|
||||
if (confirm(app.translator.trans('flarum-tags.admin.edit_tag.delete_tag_confirmation'))) {
|
||||
this.tag.delete().then(() => m.redraw());
|
||||
const children = app.store.all('tags').filter(tag => tag.parent() === this.tag);
|
||||
|
||||
this.tag.delete().then(() => {
|
||||
children.forEach(tag => tag.pushData({
|
||||
attributes: {isChild: false},
|
||||
relationships: {parent: null}
|
||||
}));
|
||||
m.redraw();
|
||||
});
|
||||
|
||||
this.hide();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,10 @@ class DeleteTagHandler
|
|||
|
||||
$this->assertCan($actor, 'delete', $tag);
|
||||
|
||||
$this->tags->query()
|
||||
->where('parent_id', $tag->id)
|
||||
->update(['parent_id' => null]);
|
||||
|
||||
$tag->delete();
|
||||
|
||||
return $tag;
|
||||
|
|
|
@ -143,7 +143,7 @@ class Tag extends AbstractModel
|
|||
foreach ($tags as $tag) {
|
||||
$can = $canForTag($tag);
|
||||
|
||||
if ($can && $tag->parent_id) {
|
||||
if ($can && $tag->parent) {
|
||||
$can = $canForTag($tag->parent);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,16 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
|
||||
class TagRepository
|
||||
{
|
||||
/**
|
||||
* Get a new query builder for the tags table.
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return Tag::query();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a tag by ID, optionally making sure it is visible to a certain
|
||||
* user, or throw an exception.
|
||||
|
|
Loading…
Reference in New Issue
Block a user