From 0083917f91f8f02f863f130291bcc06e7b4f3c28 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Mon, 5 Jan 2015 16:51:42 +0900 Subject: [PATCH 1/4] fix CommunityTopicComment::delete() doesn't delete related File (fixes #2591) --- .../PluginCommunityTopicComment.class.php | 8 ++++++ test/fixtures/999_test_data.yml | 10 +++++++ test/unit/model/CommunityTopicCommentTest.php | 26 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/unit/model/CommunityTopicCommentTest.php diff --git a/lib/model/doctrine/PluginCommunityTopicComment.class.php b/lib/model/doctrine/PluginCommunityTopicComment.class.php index 6afed79..60cf4fa 100644 --- a/lib/model/doctrine/PluginCommunityTopicComment.class.php +++ b/lib/model/doctrine/PluginCommunityTopicComment.class.php @@ -31,4 +31,12 @@ public function preSave($event) $this->setNumber(Doctrine::getTable('CommunityTopicComment')->getMaxNumber($this->getCommunityTopicId()) + 1); } } + + public function preDelete($event) + { + foreach ($this->Images as $topicCommentImage) + { + $topicCommentImage->delete(); + } + } } diff --git a/test/fixtures/999_test_data.yml b/test/fixtures/999_test_data.yml index 6c456ce..248d7f9 100644 --- a/test/fixtures/999_test_data.yml +++ b/test/fixtures/999_test_data.yml @@ -255,6 +255,7 @@ CommunityTopic: CommunityTopicComment: community_topic_comment_a_2: + id: 1 body: "こんにちは" CommunityTopic: community_topic_a_2 Member: member_5 @@ -292,6 +293,15 @@ CommunityTopicComment: CommunityTopic: community_topic_html_1 Member: member_html_1 +CommunityTopicCommentImage: + community_topic_comment_a_2_image: + CommunityTopicComment: community_topic_comment_a_2 + number: 1 + File: + name: dummy_community_topic_comment_a_2_image + type: text/plain + FileBin: { bin: hogehoge } + CommunityEvent: community_event_a_2: Community: community_a diff --git a/test/unit/model/CommunityTopicCommentTest.php b/test/unit/model/CommunityTopicCommentTest.php new file mode 100644 index 0000000..cb775f0 --- /dev/null +++ b/test/unit/model/CommunityTopicCommentTest.php @@ -0,0 +1,26 @@ +getConnection(); + +//------------------------------------------------------------ +$t->diag('CommunityTopicComment: Cascading Delete'); +$conn->beginTransaction(); + +$topicComment = $topicCommentTable->find(1); +$topicCommentImage = $topicComment->Images[0]; +$fileId = $topicCommentImage->file_id; + +$topicComment->delete($conn); + +$t->ok(!Doctrine_Core::getTable('CommunityTopicComment')->find($topicComment->id), 'community_topic_comment is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityTopicCommentImage')->find($topicCommentImage->id), 'community_topic_comment_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($fileId), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($fileId), 'file_bin is deleted.'); + +$conn->rollback(); From 23adeab0703b63c695d1bda07582600374368de8 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Mon, 5 Jan 2015 16:56:04 +0900 Subject: [PATCH 2/4] fix CommunityEventComment::delete() doesn't delete related File (fixes #2591) --- .../PluginCommunityEventComment.class.php | 8 ++++++ test/fixtures/999_test_data.yml | 10 +++++++ test/unit/model/CommunityEventCommentTest.php | 26 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/unit/model/CommunityEventCommentTest.php diff --git a/lib/model/doctrine/PluginCommunityEventComment.class.php b/lib/model/doctrine/PluginCommunityEventComment.class.php index 7936e5c..47b7755 100644 --- a/lib/model/doctrine/PluginCommunityEventComment.class.php +++ b/lib/model/doctrine/PluginCommunityEventComment.class.php @@ -32,6 +32,14 @@ public function preSave($event) } } + public function preDelete($event) + { + foreach ($this->Images as $eventCommentImage) + { + $eventCommentImage->delete(); + } + } + public function toggleEventMember($memberId) { $this->getCommunityEvent()->toggleEventMember($memberId); diff --git a/test/fixtures/999_test_data.yml b/test/fixtures/999_test_data.yml index 248d7f9..156c91e 100644 --- a/test/fixtures/999_test_data.yml +++ b/test/fixtures/999_test_data.yml @@ -333,6 +333,7 @@ CommunityEvent: CommunityEventComment: community_event_comment_a_2: + id: 1 CommunityEvent: community_event_a_2 Member: member_5 body: 'こんにちは' @@ -346,6 +347,15 @@ CommunityEventComment: Member: member_html_1 body: "<&\"'>CommunityEventComment.body ESCAPING HTML TEST DATA" +CommunityEventCommentImage: + community_event_comment_a_2_image: + CommunityEventComment: community_event_comment_a_2 + number: 1 + File: + name: dummy_community_event_comment_a_2_image + type: text/plain + FileBin: { bin: hogehoge } + CommunityEventMember: community_event_member_a_1: CommunityEvent: community_event_a_2 diff --git a/test/unit/model/CommunityEventCommentTest.php b/test/unit/model/CommunityEventCommentTest.php new file mode 100644 index 0000000..7a5787a --- /dev/null +++ b/test/unit/model/CommunityEventCommentTest.php @@ -0,0 +1,26 @@ +getConnection(); + +//------------------------------------------------------------ +$t->diag('CommunityEventComment: Cascading Delete'); +$conn->beginTransaction(); + +$eventComment = $eventCommentTable->find(1); +$eventCommentImage = $eventComment->Images[0]; +$fileId = $eventCommentImage->file_id; + +$eventComment->delete($conn); + +$t->ok(!Doctrine_Core::getTable('CommunityEventComment')->find($eventComment->id), 'community_event_comment is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityEventCommentImage')->find($eventCommentImage->id), 'community_event_comment_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($fileId), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($fileId), 'file_bin is deleted.'); + +$conn->rollback(); From ca6c885536c24f86c4ce2e87740d3bdc28bb566f Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Mon, 5 Jan 2015 17:53:17 +0900 Subject: [PATCH 3/4] fix CommunityTopic::delete() doesn't delete related File (fixes #2591) --- .../doctrine/PluginCommunityTopic.class.php | 13 +++++++ test/fixtures/999_test_data.yml | 10 ++++++ test/unit/model/CommunityTopicTest.php | 36 ++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/model/doctrine/PluginCommunityTopic.class.php b/lib/model/doctrine/PluginCommunityTopic.class.php index a228312..9b720d6 100644 --- a/lib/model/doctrine/PluginCommunityTopic.class.php +++ b/lib/model/doctrine/PluginCommunityTopic.class.php @@ -47,6 +47,19 @@ public function preSave($event) } } + public function preDelete($event) + { + foreach ($this->Images as $topicImage) + { + $topicImage->delete(); + } + + foreach ($this->CommunityTopicComment as $topicComment) + { + $topicComment->delete(); + } + } + // for pager public function getImageFilename() { diff --git a/test/fixtures/999_test_data.yml b/test/fixtures/999_test_data.yml index 156c91e..7f1b58d 100644 --- a/test/fixtures/999_test_data.yml +++ b/test/fixtures/999_test_data.yml @@ -207,6 +207,7 @@ CommunityMemberPosition: CommunityTopic: community_topic_a_2: + id: 1 name: "_aトピ主" body: "こんにちは" Community: community_a @@ -253,6 +254,15 @@ CommunityTopic: Community: community_a Member: member_html_1 +CommunityTopicImage: + community_topic_a_2_image: + CommunityTopic: community_topic_a_2 + number: 1 + File: + name: dummy_community_topic_a_2_image + type: text/plain + FileBin: { bin: hogehoge } + CommunityTopicComment: community_topic_comment_a_2: id: 1 diff --git a/test/unit/model/CommunityTopicTest.php b/test/unit/model/CommunityTopicTest.php index c613b66..db24b22 100644 --- a/test/unit/model/CommunityTopicTest.php +++ b/test/unit/model/CommunityTopicTest.php @@ -3,7 +3,7 @@ include(dirname(__FILE__).'/../../bootstrap/unit.php'); include(dirname(__FILE__).'/../../bootstrap/database.php'); -$t = new lime_test(64, new lime_output_color()); +$t = new lime_test(72); $members = Doctrine::getTable('Member')->createQuery()->orderBy('id')->execute(); $communities = Doctrine::getTable('Community')->createQuery()->orderBy('id')->execute(); @@ -192,3 +192,37 @@ function getAcl($object) $t->cmp_ok($acl->isAllowed(1, null, 'view'), '===', true, 'returns true for the community admin'); $t->cmp_ok($acl->isAllowed(3, null, 'view'), '===', true, 'returns true for a community member'); $t->cmp_ok($acl->isAllowed(4, null, 'view'), '===', true, 'returns true for a non-community member'); + +//------------------------------------------------------------ +$t->diag('CommunityTopic: Cascading Delete'); +$conn->beginTransaction(); + +$topic = Doctrine_Core::getTable('CommunityTopic')->find(1); +$topicImage = $topic->Images[0]; +$file1Id = $topicImage->file_id; +$topicComment = Doctrine_Core::getTable('CommunityTopicComment')->find(1); +$topicCommentImage = $topicComment->Images[0]; +$file2Id = $topicCommentImage->file_id; + +/* + * community_topic + * |- community_topic_image + * | +- file + * | +- file_bin + * +- community_topic_comment + * +- community_topic_comment_image + * +- file + * +- file_bin + */ +$topic->delete($conn); + +$t->ok(!Doctrine_Core::getTable('CommunityTopic')->find($topic->id), 'community_topic is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityTopicImage')->find($topicImage->id), 'community_topic_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($file1Id), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($file1Id), 'file_bin is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityTopicComment')->find($topicComment->id), 'community_topic_comment is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityTopicCommentImage')->find($topicCommentImage->id), 'community_topic_comment_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($file2Id), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($file2Id), 'file_bin is deleted.'); + +$conn->rollback(); From 3c81e4dd705ac5b7c78f486926731ee8ef46a563 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Mon, 5 Jan 2015 18:02:21 +0900 Subject: [PATCH 4/4] fix CommunityEvent::delete() doesn't delete related File (fixes #2591) --- .../doctrine/PluginCommunityEvent.class.php | 13 ++++++ test/fixtures/999_test_data.yml | 9 +++++ test/unit/model/CommunityEventTest.php | 40 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 test/unit/model/CommunityEventTest.php diff --git a/lib/model/doctrine/PluginCommunityEvent.class.php b/lib/model/doctrine/PluginCommunityEvent.class.php index 6b090f0..02d3280 100644 --- a/lib/model/doctrine/PluginCommunityEvent.class.php +++ b/lib/model/doctrine/PluginCommunityEvent.class.php @@ -53,6 +53,19 @@ public function preSave($event) } } + public function preDelete($event) + { + foreach ($this->Images as $eventImage) + { + $eventImage->delete(); + } + + foreach ($this->CommunityEventComment as $eventComment) + { + $eventComment->delete(); + } + } + public function toggleEventMember($memberId) { if ($this->isClosed()) diff --git a/test/fixtures/999_test_data.yml b/test/fixtures/999_test_data.yml index 7f1b58d..a152137 100644 --- a/test/fixtures/999_test_data.yml +++ b/test/fixtures/999_test_data.yml @@ -314,6 +314,7 @@ CommunityTopicCommentImage: CommunityEvent: community_event_a_2: + id: 1 Community: community_a Member: member_2 name: '_aイベ主' @@ -340,6 +341,14 @@ CommunityEvent: open_date: '2009-06-11' open_date_comment: "<&\"'>CommunityEvent.open_date_comment ESCAPING HTML TEST DATA" area: "<&\"'>CommunityEvent.area ESCAPING HTML TEST DATA" +CommunityEventImage: + community_event_a_2_image: + CommunityEvent: community_event_a_2 + number: 1 + File: + name: dummy_community_event_a_2_image + type: text/plain + FileBin: { bin: hogehoge } CommunityEventComment: community_event_comment_a_2: diff --git a/test/unit/model/CommunityEventTest.php b/test/unit/model/CommunityEventTest.php new file mode 100644 index 0000000..afff016 --- /dev/null +++ b/test/unit/model/CommunityEventTest.php @@ -0,0 +1,40 @@ +diag('CommunityEvent: Cascading Delete'); +$conn->beginTransaction(); + +$event = Doctrine_Core::getTable('CommunityEvent')->find(1); +$eventImage = $event->Images[0]; +$file1Id = $eventImage->file_id; +$eventComment = Doctrine_Core::getTable('CommunityEventComment')->find(1); +$eventCommentImage = $eventComment->Images[0]; +$file2Id = $eventCommentImage->file_id; + +/* + * community_event + * |- community_event_image + * | +- file + * | +- file_bin + * +- community_event_comment + * +- community_event_comment_image + * +- file + * +- file_bin + */ +$event->delete($conn); + +$t->ok(!Doctrine_Core::getTable('CommunityEvent')->find($event->id), 'community_event is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityEventImage')->find($eventImage->id), 'community_event_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($file1Id), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($file1Id), 'file_bin is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityEventComment')->find($eventComment->id), 'community_event_comment is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityEventCommentImage')->find($eventCommentImage->id), 'community_event_comment_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($file2Id), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($file2Id), 'file_bin is deleted.'); + +$conn->rollback();