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
1 change: 1 addition & 0 deletions Entity/Paper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Paper

/**
* @ORM\ManyToOne(targetEntity="UJM\ExoBundle\Entity\Exercise")
* @ORM\JoinColumn(onDelete="SET NULL", nullable=true)
*/
private $exercise;

Expand Down
55 changes: 19 additions & 36 deletions Listener/ExerciseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,55 +97,38 @@ public function onOpen(OpenResourceEvent $event)

public function onDelete(DeleteResourceEvent $event)
{
$em = $this->container->get('doctrine.orm.entity_manager');
$em = $this->container->get('claroline.persistence.object_manager');

$papers = $em->getRepository('UJMExoBundle:Paper')
->findOneBy(array(
'exercise' => $event->getResource()->getId()
)
);

if (count($papers) == 0) {

$eqs = $em->getRepository('UJMExoBundle:ExerciseQuestion')
->findBy(array(
'exercise' => $event->getResource()->getId()
)
);

foreach ($eqs as $eq) {
$em->remove($eq);
}

$subscriptions = $em->getRepository('UJMExoBundle:Subscription')
->findBy(array(
'exercise' => $event->getResource()->getId()
)
);

foreach ($subscriptions as $subscription) {
$em->remove($subscription);
}

$em->flush();

$em->remove($event->getResource());
$eqs = $em->getRepository('UJMExoBundle:ExerciseQuestion')
->findBy(array(
'exercise' => $event->getResource()->getId()
)
);

} else {
foreach ($eqs as $eq) {
$em->remove($eq);
}

$exercise = $em->getRepository('UJMExoBundle:Exercise')->find($event->getResource()->getId());
$resourceNode = $em->getRepository('ClarolineCoreBundle:Resource\ResourceNode')->find(
$exercise->getResourceNode()->getId()
$subscriptions = $em->getRepository('UJMExoBundle:Subscription')
->findBy(array(
'exercise' => $event->getResource()->getId()
)
);

$em->remove($resourceNode);

$exercise->archiveExercise();
$em->persist($exercise);
$em->flush();
exit();
foreach ($subscriptions as $subscription) {
$em->remove($subscription);
}

$em->flush();

$em->remove($event->getResource());

$event->stopPropagation();
}

Expand Down
41 changes: 41 additions & 0 deletions Migrations/pdo_mysql/Version20151123143814.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace UJM\ExoBundle\Migrations\pdo_mysql;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated migration based on mapping information: modify it with caution
*
* Generation date: 2015/11/23 02:38:15
*/
class Version20151123143814 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->addSql("
ALTER TABLE ujm_paper
DROP FOREIGN KEY FK_82972E4BE934951A
");
$this->addSql("
ALTER TABLE ujm_paper
ADD CONSTRAINT FK_82972E4BE934951A FOREIGN KEY (exercise_id)
REFERENCES ujm_exercise (id)
ON DELETE SET NULL
");
}

public function down(Schema $schema)
{
$this->addSql("
ALTER TABLE ujm_paper
DROP FOREIGN KEY FK_82972E4BE934951A
");
$this->addSql("
ALTER TABLE ujm_paper
ADD CONSTRAINT FK_82972E4BE934951A FOREIGN KEY (exercise_id)
REFERENCES ujm_exercise (id)
");
}
}