Skip to content

Commit

Permalink
Merge pull request #20 from NicolasBarbey/main
Browse files Browse the repository at this point in the history
Thelia 2.5 compatibility
  • Loading branch information
julescournut authored Oct 7, 2021
2 parents 1156982 + 921f53b commit 791aa30
Show file tree
Hide file tree
Showing 24 changed files with 218 additions and 3,763 deletions.
25 changes: 13 additions & 12 deletions Action/CommentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
use DateTime;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Thelia\Core\Template\ParserInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Log\Tlog;
Expand Down Expand Up @@ -81,11 +82,15 @@ class CommentAction implements EventSubscriberInterface
/** @var null|MailerFactory */
protected $mailer = null;

public function __construct(TranslatorInterface $translator, ParserInterface $parser, MailerFactory $mailer)
/** @var null|EventDispatcherInterface */
protected $dispatcher = null;

public function __construct(TranslatorInterface $translator, ParserInterface $parser, MailerFactory $mailer, EventDispatcherInterface $dispatcher)
{
$this->translator = $translator;
$this->parser = $parser;
$this->mailer = $mailer;
$this->dispatcher = $dispatcher;
}

public function create(CommentCreateEvent $event)
Expand All @@ -111,7 +116,6 @@ public function create(CommentCreateEvent $event)

if (Comment::ACCEPTED === $comment->getStatus()) {
$this->dispatchRatingCompute(
$event->getDispatcher(),
$comment->getRef(),
$comment->getRefId()
);
Expand All @@ -138,7 +142,6 @@ public function update(CommentUpdateEvent $event)
$event->setComment($comment);

$this->dispatchRatingCompute(
$event->getDispatcher(),
$comment->getRef(),
$comment->getRefId()
);
Expand All @@ -154,7 +157,6 @@ public function delete(CommentDeleteEvent $event)

if (Comment::ACCEPTED === $comment->getStatus()) {
$this->dispatchRatingCompute(
$event->getDispatcher(),
$comment->getRef(),
$comment->getRefId()
);
Expand Down Expand Up @@ -184,7 +186,6 @@ public function statusChange(CommentChangeStatusEvent $event)
$event->setComment($comment);

$this->dispatchRatingCompute(
$event->getDispatcher(),
$comment->getRef(),
$comment->getRefId()
);
Expand Down Expand Up @@ -230,17 +231,17 @@ public function productRatingCompute(CommentComputeRatingEvent $event)
* @param string $ref
* @param int $refId
*/
protected function dispatchRatingCompute($dispatcher, $ref, $refId)
protected function dispatchRatingCompute($ref, $refId)
{
$ratingEvent = new CommentComputeRatingEvent();

$ratingEvent
->setRef($ref)
->setRefId($refId);

$dispatcher->dispatch(
CommentEvents::COMMENT_RATING_COMPUTE,
$ratingEvent
$this->dispatcher->dispatch(
$ratingEvent,
CommentEvents::COMMENT_RATING_COMPUTE
);
}

Expand Down Expand Up @@ -292,7 +293,7 @@ public function getDefinition(CommentDefinitionEvent $event)
}

$eventName = CommentEvents::COMMENT_GET_DEFINITION . "." . $event->getRef();
$event->getDispatcher()->dispatch($eventName, $event);
$this->dispatcher->dispatch($event, $eventName);

// is only customer is authorized to publish
if ($config['only_customer'] && null === $event->getCustomer()) {
Expand Down Expand Up @@ -612,7 +613,7 @@ public function notifyAdminOfNewComment(CommentCreateEvent $event)
$comment->getRefId(),
$shopLocale
);
$event->getDispatcher()->dispatch(CommentEvents::COMMENT_REFERENCE_GETTER, $getCommentRefEvent);
$this->dispatcher->dispatch($getCommentRefEvent, CommentEvents::COMMENT_REFERENCE_GETTER);

$this->mailer->sendEmailToShopManagers(
'new_comment_notification_admin',
Expand Down
30 changes: 19 additions & 11 deletions Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Comment\Model\CommentQuery;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Thelia\Core\Translation\Translator;
use Thelia\Install\Database;
use Thelia\Model\ConfigQuery;
Expand Down Expand Up @@ -57,7 +58,7 @@ class Comment extends BaseModule
const CONFIG_NOTIFY_ADMIN_NEW_COMMENT = true;


public function postActivation(ConnectionInterface $con = null)
public function postActivation(ConnectionInterface $con = null): void
{
// Config
if (null === ConfigQuery::read('comment_activated')) {
Expand Down Expand Up @@ -89,11 +90,10 @@ public function postActivation(ConnectionInterface $con = null)
}

// Schema
try {
CommentQuery::create()->findOne();
} catch (\Exception $ex) {
$database = new Database($con->getWrappedConnection());
if (!self::getConfigValue('is_initialized', false)) {
$database = new Database($con);
$database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
self::setConfigValue('is_initialized', true);
}

// Messages
Expand Down Expand Up @@ -180,30 +180,38 @@ public static function getConfig()
{
$config = [
'activated' => (
intval(ConfigQuery::read('comment_activated', self::CONFIG_ACTIVATED)) === 1
(int)ConfigQuery::read('comment_activated', self::CONFIG_ACTIVATED) === 1
),
'moderate' => (
intval(ConfigQuery::read('comment_moderate', self::CONFIG_MODERATE)) === 1
(int)ConfigQuery::read('comment_moderate', self::CONFIG_MODERATE) === 1
),
'ref_allowed' => explode(
',',
ConfigQuery::read('comment_ref_allowed', self::CONFIG_REF_ALLOWED)
),
'only_customer' => (
intval(ConfigQuery::read('comment_only_customer', self::CONFIG_ONLY_CUSTOMER)) === 1
(int)ConfigQuery::read('comment_only_customer', self::CONFIG_ONLY_CUSTOMER) === 1
),
'only_verified' => (
intval(ConfigQuery::read('comment_only_verified', self::CONFIG_ONLY_VERIFIED)) === 1
(int)ConfigQuery::read('comment_only_verified', self::CONFIG_ONLY_VERIFIED) === 1
),
'request_customer_ttl' => (
intval(ConfigQuery::read('comment_request_customer_ttl', self::CONFIG_REQUEST_CUSTOMMER_TTL))
(int)ConfigQuery::read('comment_request_customer_ttl', self::CONFIG_REQUEST_CUSTOMMER_TTL)
),
'notify_admin_new_comment' => (
intval(ConfigQuery::read('comment_notify_admin_new_comment', self::CONFIG_NOTIFY_ADMIN_NEW_COMMENT))
(int)ConfigQuery::read('comment_notify_admin_new_comment', self::CONFIG_NOTIFY_ADMIN_NEW_COMMENT)
=== 1
),
];

return $config;
}

public static function configureServices(ServicesConfigurator $servicesConfigurator): void
{
$servicesConfigurator->load(self::getModuleCode().'\\', __DIR__)
->exclude([THELIA_MODULE_DIR . ucfirst(self::getModuleCode()). "/I18n/*"])
->autowire(true)
->autoconfigure(true);
}
}
12 changes: 6 additions & 6 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</loops>

<forms>
<form name="comment.add.form" class="Comment\Form\AddCommentForm" />
<form name="comment.abuse.form" class="Comment\Form\CommentAbuseForm" />
<form name="comment.configuration.form" class="Comment\Form\ConfigurationForm" />
<form name="admin.comment.modification.form" class="Comment\Form\CommentModificationForm" />
<form name="comment_add_form" class="Comment\Form\AddCommentForm" />
<form name="comment_abuse_form" class="Comment\Form\CommentAbuseForm" />
<form name="comment_configuration_form" class="Comment\Form\ConfigurationForm" />
<form name="admin_comment_modification_form" class="Comment\Form\CommentModificationForm" />
</forms>

<commands>
Expand All @@ -21,7 +21,7 @@
-->
</commands>

<services>
<!--<services>
<service id="comment.action" class="Comment\Action\CommentAction" scope="request">
<argument type="service" id="thelia.translator" />
Expand All @@ -36,7 +36,7 @@
<tag name="thelia.form.type" />
</service>
</services>
</services>-->

<!--
<exports>
Expand Down
4 changes: 2 additions & 2 deletions Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.3.0</version>
<version>2.0.0</version>
<author>
<name>Julien Chanséaume</name>
<email>jchanseaume@openstudio.fr</email>
</author>
<type>classic</type>
<thelia>2.1.0</thelia>
<thelia>2.5.0</thelia>
<stability>alpha</stability>
</module>
15 changes: 5 additions & 10 deletions Config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- Front -->

<route id="front.comment.get" path="/comment/get">
<!--<route id="front.comment.get" path="/comment/get">
<default key="_controller">Comment\Controller\Front\CommentController::getAction</default>
</route>
Expand All @@ -21,14 +21,9 @@
<route id="front.comment.abuse" path="/comment/abuse" methods="post">
<default key="_controller">Comment\Controller\Front\CommentController::abuseAction</default>
</route>

<!-- Admin -->
<route id="admin.comment.configuration" path="/admin/module/comment/configuration" methods="post">
<default key="_controller">Comment\Controller\Back\CommentController::saveConfiguration</default>
</route>
</route>-->

<!-- crud -->
<!-- crud -->

<route id="admin.comment.comments.default" path="/admin/module/comments">
<default key="_controller">Comment\Controller\Back\CommentController::defaultAction</default>
Expand All @@ -52,7 +47,7 @@
<default key="_controller">Comment\Controller\Back\CommentController::deleteAction</default>
</route>

<route id="admin.comment.comments.status" path="/admin/module/comment/status" methods="post">
<!--<route id="admin.comment.comments.status" path="/admin/module/comment/status" methods="post">
<default key="_controller">Comment\Controller\Back\CommentController::changeStatusAction</default>
</route>
Expand All @@ -64,6 +59,6 @@
<route id="admin.comment.comments.request-customer-comment" path="/admin/module/comment/request-customer">
<default key="_controller">Comment\Controller\Back\CommentController::requestCustomerCommentAction</default>
</route>
</route>-->

</routes>
2 changes: 1 addition & 1 deletion Config/schema.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia" namespace="Comment\Model">
<database defaultIdMethod="native" name="TheliaMain" namespace="Comment\Model">

<table name="comment">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
Expand Down
Loading

0 comments on commit 791aa30

Please sign in to comment.