Disassociate child tag when parent is deleted. fixes flarum/core#962

This commit is contained in:
Toby Zerner 2016-06-04 16:25:57 +09:30
parent 1dc495dfdd
commit 020d850a3a
5 changed files with 44 additions and 6 deletions

View File

@ -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();
})();
}
}
}]);

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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.