Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/model/doctrine/PluginCommunityEvent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 8 additions & 0 deletions lib/model/doctrine/PluginCommunityEventComment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions lib/model/doctrine/PluginCommunityTopic.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
8 changes: 8 additions & 0 deletions lib/model/doctrine/PluginCommunityTopicComment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
39 changes: 39 additions & 0 deletions test/fixtures/999_test_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ CommunityMemberPosition:

CommunityTopic:
community_topic_a_2:
id: 1
name: "_aトピ主"
body: "こんにちは"
Community: community_a
Expand Down Expand Up @@ -253,8 +254,18 @@ 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
body: "こんにちは"
CommunityTopic: community_topic_a_2
Member: member_5
Expand Down Expand Up @@ -292,8 +303,18 @@ 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:
id: 1
Community: community_a
Member: member_2
name: '_aイベ主'
Expand All @@ -320,9 +341,18 @@ 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:
id: 1
CommunityEvent: community_event_a_2
Member: member_5
body: 'こんにちは'
Expand All @@ -336,6 +366,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
Expand Down
26 changes: 26 additions & 0 deletions test/unit/model/CommunityEventCommentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

require_once __DIR__.'/../../bootstrap/unit.php';
require_once __DIR__.'/../../bootstrap/database.php';

$t = new lime_test(4);

$eventCommentTable = Doctrine_Core::getTable('CommunityEventComment');
$conn = $eventCommentTable->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();
40 changes: 40 additions & 0 deletions test/unit/model/CommunityEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

require_once __DIR__.'/../../bootstrap/unit.php';
require_once __DIR__.'/../../bootstrap/database.php';

$t = new lime_test(8);

//------------------------------------------------------------
$t->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();
26 changes: 26 additions & 0 deletions test/unit/model/CommunityTopicCommentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

require_once __DIR__.'/../../bootstrap/unit.php';
require_once __DIR__.'/../../bootstrap/database.php';

$t = new lime_test(4);

$topicCommentTable = Doctrine_Core::getTable('CommunityTopicComment');
$conn = $topicCommentTable->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();
36 changes: 35 additions & 1 deletion test/unit/model/CommunityTopicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();