-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ThomasDaSilva/feat/site_reviews
Add Pagination for loop + Site Review import + loop and improve reviews import
- Loading branch information
Showing
16 changed files
with
419 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace GuaranteedOpinion\Command; | ||
|
||
use Exception; | ||
use GuaranteedOpinion\Api\GuaranteedOpinionClient; | ||
use GuaranteedOpinion\Service\SiteReviewService; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Thelia\Command\ContainerAwareCommand; | ||
|
||
class GetSiteReviewCommand extends ContainerAwareCommand | ||
{ | ||
public function __construct( | ||
protected GuaranteedOpinionClient $client, | ||
protected SiteReviewService $siteReviewService | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function configure(): void | ||
{ | ||
$this | ||
->setName('module:GuaranteedOpinion:GetSiteReview') | ||
->setDescription('Get site review from API Avis-Garantis'); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$siteReviewsAdded = 0; | ||
|
||
try { | ||
$siteReviews = $this->client->getReviewsFromApi(); | ||
|
||
$output->write("Site Review synchronization start \n"); | ||
|
||
foreach ($siteReviews as $key => $siteRow) { | ||
if ($key % 100 === 0) { | ||
$output->write("Rows treated : " . $key . "\n"); | ||
} | ||
if ($this->siteReviewService->addGuaranteedOpinionSiteRow($siteRow)) { | ||
$siteReviewsAdded ++; | ||
} | ||
} | ||
} catch (Exception $exception) { | ||
$output->write($exception->getMessage()); | ||
} | ||
|
||
$output->write("End of Site Review synchronization\n"); | ||
$output->write("Site Review Added : " .$siteReviewsAdded. "\n"); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# This is a fix for InnoDB in MySQL >= 4.1.x | ||
# It "suspends judgement" for fkey relationships until are tables are set. | ||
SET FOREIGN_KEY_CHECKS = 0; | ||
|
||
-- --------------------------------------------------------------------- | ||
-- guaranteed_opinion_product_review | ||
-- --------------------------------------------------------------------- | ||
|
||
DROP TABLE IF EXISTS `guaranteed_opinion_product_review`; | ||
|
||
CREATE TABLE `guaranteed_opinion_product_review` | ||
( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`product_review_id` VARCHAR(55) NOT NULL, | ||
`name` VARCHAR(255), | ||
`rate` DECIMAL(2,1) DEFAULT 0, | ||
`review` VARBINARY(10000), | ||
`review_date` DATETIME, | ||
`product_id` INTEGER, | ||
`order_id` VARCHAR(255), | ||
`order_date` DATETIME, | ||
`reply` VARCHAR(255), | ||
`reply_date` DATETIME, | ||
PRIMARY KEY (`id`), | ||
UNIQUE INDEX `guaranteed_opinion_product_review_id_unique` (`product_review_id`) | ||
) ENGINE=InnoDB; | ||
|
||
-- --------------------------------------------------------------------- | ||
-- guaranteed_opinion_order_queue | ||
-- --------------------------------------------------------------------- | ||
|
||
DROP TABLE IF EXISTS `guaranteed_opinion_order_queue`; | ||
|
||
CREATE TABLE `guaranteed_opinion_order_queue` | ||
( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`order_id` INTEGER NOT NULL, | ||
`treated_at` DATETIME, | ||
`status` INTEGER, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB; | ||
|
||
-- --------------------------------------------------------------------- | ||
-- guaranteed_opinion_site_review | ||
-- --------------------------------------------------------------------- | ||
|
||
DROP TABLE IF EXISTS `guaranteed_opinion_site_review`; | ||
|
||
CREATE TABLE `guaranteed_opinion_site_review` | ||
( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`site_review_id` INTEGER NOT NULL, | ||
`name` VARCHAR(255), | ||
`rate` DECIMAL(2,1) DEFAULT 0, | ||
`review` VARBINARY(10000), | ||
`review_date` DATETIME, | ||
`order_id` VARCHAR(255), | ||
`order_date` DATETIME, | ||
`reply` VARCHAR(255), | ||
`reply_date` DATETIME, | ||
PRIMARY KEY (`id`,`site_review_id`), | ||
UNIQUE INDEX `guaranteed_opinion_site_review_id_unique` (`site_review_id`) | ||
) ENGINE=InnoDB; | ||
|
||
# This restores the fkey checks, after having unset them earlier | ||
SET FOREIGN_KEY_CHECKS = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace GuaranteedOpinion\Loop; | ||
|
||
use GuaranteedOpinion\Model\GuaranteedOpinionProductReviewQuery; | ||
use GuaranteedOpinion\Model\GuaranteedOpinionSiteReviewQuery; | ||
use Propel\Runtime\ActiveQuery\Criteria; | ||
use Propel\Runtime\ActiveQuery\ModelCriteria; | ||
use Thelia\Core\Template\Element\BaseLoop; | ||
use Thelia\Core\Template\Element\LoopResult; | ||
use Thelia\Core\Template\Element\LoopResultRow; | ||
use Thelia\Core\Template\Element\PropelSearchLoopInterface; | ||
use Thelia\Core\Template\Loop\Argument\Argument; | ||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; | ||
|
||
/** | ||
* @method getMinRate() | ||
* @method getPage() | ||
* @method getLimit() | ||
*/ | ||
class GuaranteedSiteLoop extends BaseLoop implements PropelSearchLoopInterface | ||
{ | ||
public function parseResults(LoopResult $loopResult): LoopResult | ||
{ | ||
foreach ($loopResult->getResultDataCollection() as $review) { | ||
$loopResultRow = new LoopResultRow($review); | ||
|
||
$loopResultRow | ||
->set('ID', $review->getId()) | ||
->set('PRODUCT_REVIEW_ID', $review->getSiteReviewId()) | ||
->set('NAME', $review->getName()) | ||
->set('RATE', $review->getRate()) | ||
->set('REVIEW', $review->getReview()) | ||
->set('REVIEW_DATE', $review->getReviewDate()?->format('Y-m-d')) | ||
->set('ORDER_ID', $review->getOrderId()) | ||
->set('ORDER_DATE', $review->getOrderDate()?->format('Y-m-d')) | ||
->set('REPLY', $review->getReply()) | ||
->set('REPLY_DATE', $review->getReplyDate()?->format('Y-m-d')) | ||
; | ||
$this->addOutputFields($loopResultRow, $review); | ||
|
||
$loopResult->addRow($loopResultRow); | ||
} | ||
|
||
return $loopResult; | ||
} | ||
|
||
public function buildModelCriteria(): GuaranteedOpinionProductReviewQuery|ModelCriteria | ||
{ | ||
$search = GuaranteedOpinionSiteReviewQuery::create(); | ||
|
||
if (null !== $minRate = $this->getMinRate()) { | ||
$search->filterByRate($minRate, Criteria::GREATER_EQUAL); | ||
} | ||
|
||
if ((null !== $page = $this->getPage()) && (null !== $limit = $this->getLimit())) { | ||
$search->paginate($page, $limit); | ||
} | ||
|
||
return $search; | ||
} | ||
|
||
protected function getArgDefinitions(): ArgumentCollection | ||
{ | ||
return new ArgumentCollection( | ||
Argument::createIntTypeArgument('min_rate'), | ||
Argument::createIntTypeArgument('limit', 5), | ||
Argument::createIntTypeArgument('page', 0) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace GuaranteedOpinion\Model; | ||
|
||
use GuaranteedOpinion\Model\Base\GuaranteedOpinionSiteReview as BaseGuaranteedOpinionSiteReview; | ||
|
||
/** | ||
* Skeleton subclass for representing a row from the 'guaranteed_opinion_site_review' table. | ||
* | ||
* | ||
* | ||
* You should add additional methods to this class to meet the | ||
* application requirements. This class will only be generated as | ||
* long as it does not already exist in the output directory. | ||
*/ | ||
class GuaranteedOpinionSiteReview extends BaseGuaranteedOpinionSiteReview | ||
{ | ||
|
||
} |
Oops, something went wrong.