Skip to content

Commit

Permalink
Merge pull request #2512 from EC-CUBE/experimental/physical-delete
Browse files Browse the repository at this point in the history
SoftDeleteFilter及び論理削除の廃止
  • Loading branch information
Chihiro Adachi committed Sep 19, 2017
2 parents 94d0cd4 + 1e387ca commit 3ded70a
Show file tree
Hide file tree
Showing 163 changed files with 1,325 additions and 1,994 deletions.
1 change: 0 additions & 1 deletion eccube_install.php
Expand Up @@ -340,7 +340,6 @@ function initializeDatabase(\Eccube\Application $app)
'password' => $encodedPassword,
'salt' => $salt,
'work' => 1,
'del_flg' => 0,
'authority' => 0,
'creator_id' => 1,
'rank' => 1,
Expand Down
5 changes: 0 additions & 5 deletions src/Eccube/Application.php
Expand Up @@ -23,9 +23,6 @@

namespace Eccube;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\DBAL\Types\Type;
use Eccube\Doctrine\DBAL\Types\UTCDateTimeType;
use Eccube\Doctrine\DBAL\Types\UTCDateTimeTzType;
Expand Down Expand Up @@ -717,10 +714,8 @@ function (\Doctrine\ORM\Configuration $config, \Silex\Application $app) {

// filters
$config = $em->getConfiguration();
$config->addFilter("soft_delete", '\Eccube\Doctrine\Filter\SoftDeleteFilter');
$config->addFilter("nostock_hidden", '\Eccube\Doctrine\Filter\NoStockHiddenFilter');
$config->addFilter("incomplete_order_status_hidden", '\Eccube\Doctrine\Filter\OrderStatusFilter');
$em->getFilters()->enable('soft_delete');

return $em;
});
Expand Down
9 changes: 3 additions & 6 deletions src/Eccube/Controller/Admin/AdminController.php
Expand Up @@ -369,8 +369,7 @@ protected function getOrderEachStatus($em, array $excludes)
FROM
dtb_order t1
WHERE
t1.del_flg = 0
AND t1.status NOT IN (:excludes)
t1.status NOT IN (:excludes)
GROUP BY
t1.status
ORDER BY
Expand Down Expand Up @@ -400,8 +399,7 @@ protected function getSalesByMonth($em, $dateTime, array $excludes)
FROM
Eccube\Entity\Order o
WHERE
o.del_flg = 0
AND o.OrderStatus NOT IN (:excludes)
o.OrderStatus NOT IN (:excludes)
AND SUBSTRING(CONCAT(o.order_date, \'\'), 1, 7) = SUBSTRING(:targetDate, 1, 7)
GROUP BY
order_month';
Expand Down Expand Up @@ -431,8 +429,7 @@ protected function getSalesByDay($em, $dateTime, array $excludes)
FROM
Eccube\Entity\Order o
WHERE
o.del_flg = 0
AND o.OrderStatus NOT IN (:excludes)
o.OrderStatus NOT IN (:excludes)
AND SUBSTRING(CONCAT(o.order_date, \'\'), 1, 10) = SUBSTRING(:targetDate, 1, 10)
GROUP BY
order_day';
Expand Down
18 changes: 11 additions & 7 deletions src/Eccube/Controller/Admin/Customer/CustomerController.php
Expand Up @@ -24,9 +24,10 @@

namespace Eccube\Controller\Admin\Customer;

use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\ORM\EntityManager;
use Eccube\Annotation\Inject;
use Eccube\Annotation\Component;
use Eccube\Annotation\Inject;
use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
Expand All @@ -40,9 +41,9 @@
use Eccube\Repository\Master\SexRepository;
use Eccube\Service\CsvExportService;
use Eccube\Service\MailService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -289,9 +290,14 @@ public function delete(Application $app, Request $request, $id)
return $app->redirect($app->url('admin_customer_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED);
}

$Customer->setDelFlg(Constant::ENABLED);
$this->entityManager->persist($Customer);
$this->entityManager->flush();
try {
$this->entityManager->remove($Customer);
$this->entityManager->flush($Customer);
$app->addSuccess('admin.customer.delete.complete', 'admin');
} catch (ForeignKeyConstraintViolationException $e) {
log_error('会員削除失敗', [$e], 'admin');
$app->addError('admin.customer.delete.failed', 'admin');
}

log_info('会員削除完了', array($id));

Expand All @@ -303,8 +309,6 @@ public function delete(Application $app, Request $request, $id)
);
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELETE_COMPLETE, $event);

$app->addSuccess('admin.customer.delete.complete', 'admin');

return $app->redirect($app->url('admin_customer_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED);
}

Expand Down
Expand Up @@ -29,6 +29,7 @@
use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
use Eccube\Entity\CustomerAddress;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\Admin\CustomerType;
Expand Down Expand Up @@ -99,7 +100,7 @@ public function index(Application $app, Request $request, $id = null)
// 新規登録
} else {
$Customer = $this->customerRepository->newCustomer();
$CustomerAddress = new \Eccube\Entity\CustomerAddress();
$CustomerAddress = new CustomerAddress();
$Customer->setBuyTimes(0);
$Customer->setBuyTotal(0);
}
Expand Down Expand Up @@ -149,7 +150,6 @@ public function index(Application $app, Request $request, $id = null)
->setFax01($Customer->getFax01())
->setFax02($Customer->getFax02())
->setFax03($Customer->getFax03())
->setDelFlg(Constant::DISABLED)
->setCustomer($Customer);

$this->entityManager->persist($CustomerAddress);
Expand Down
22 changes: 6 additions & 16 deletions src/Eccube/Controller/Admin/Order/EditController.php
Expand Up @@ -25,11 +25,11 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManager;
use Eccube\Annotation\Inject;
use Eccube\Annotation\Component;
use Eccube\Annotation\Inject;
use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Master\CustomerStatus;
use Eccube\Entity\Master\DeviceType;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
Expand All @@ -46,9 +46,9 @@
use Eccube\Service\PurchaseFlow\PurchaseException;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Eccube\Service\TaxRuleService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bridge\Monolog\Logger;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Form\FormFactory;
Expand Down Expand Up @@ -163,13 +163,6 @@ class EditController extends AbstractController
*/
public function index(Application $app, Request $request, $id = null)
{
/* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */
$softDeleteFilter = $this->entityManager->getFilters()->getFilter('soft_delete');
$softDeleteFilter->setExcludes(array(
'Eccube\Entity\ProductClass',
'Eccube\Entity\Product',
));

$TargetOrder = null;
$OriginOrder = null;

Expand Down Expand Up @@ -444,6 +437,9 @@ public function searchCustomerHtml(Application $app, Request $request, $page_no

$searchData = array(
'multi' => $request->get('search_word'),
'customer_status' => [
CustomerStatus::REGULAR
]
);

$session->set('eccube.admin.order.customer.search', $searchData);
Expand Down Expand Up @@ -712,12 +708,6 @@ protected function calculate($app, \Eccube\Entity\Order $Order)
// $subtotal += $OrderDetail->getTotalPrice();
}

$shippings = $Order->getShippings();
/** @var \Eccube\Entity\Shipping $Shipping */
foreach ($shippings as $Shipping) {
$Shipping->setDelFlg(Constant::DISABLED);
}

// // 受注データの税・小計・合計を再計算
// $Order->setTax($taxtotal);
// $Order->setSubtotal($subtotal);
Expand Down
3 changes: 0 additions & 3 deletions src/Eccube/Controller/Admin/Order/MailController.php
Expand Up @@ -187,7 +187,6 @@ public function index(Application $app, Request $request, $id)
$MailHistory
->setSubject($data['subject'])
->setMailBody($body)
->setMailTemplate($MailTemplate)
->setSendDate(new \DateTime())
->setOrder($Order);

Expand Down Expand Up @@ -370,12 +369,10 @@ public function mailAll(Application $app, Request $request)
$this->mailService->sendAdminOrderMail($Order, $data);

// 送信履歴を保存.
$MailTemplate = $form->get('template')->getData();
$MailHistory = new MailHistory();
$MailHistory
->setSubject($data['subject'])
->setMailBody($body)
->setMailTemplate($MailTemplate)
->setSendDate(new \DateTime())
->setOrder($Order);
$this->entityManager->persist($MailHistory);
Expand Down
20 changes: 16 additions & 4 deletions src/Eccube/Controller/Admin/Order/OrderController.php
Expand Up @@ -31,6 +31,7 @@
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Master\CsvType;
use Eccube\Entity\Order;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\Admin\SearchOrderType;
Expand Down Expand Up @@ -301,15 +302,26 @@ public function delete(Application $app, Request $request, $id)

log_info('受注削除開始', array($Order->getId()));

$Order->setDelFlg(Constant::ENABLED);
// 出荷に紐付いている明細がある場合は削除できない.
$hasShipping = $Order->getItems()->exists(function ($k, $v) {
return false === is_null($v->getShipping());
});
if ($hasShipping) {
log_info('受注削除失敗', [$Order->getId()]);
$app->addError('admin.order.delete.failed', 'admin');

$this->entityManager->persist($Order);
$this->entityManager->flush();
return $app->redirect($app->url('admin_order_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED);
}

$Customer = $Order->getCustomer();
$OrderStatusId = $Order->getOrderStatus()->getId();

$this->entityManager->remove($Order);
$this->entityManager->flush();

if ($Customer) {
// 会員の場合、購入回数、購入金額などを更新
$this->customerRepository->updateBuyData($app, $Customer, $Order->getOrderStatus()->getId());
$this->customerRepository->updateBuyData($app, $Customer, $OrderStatusId);
}

$event = new EventArgs(
Expand Down
46 changes: 46 additions & 0 deletions src/Eccube/Controller/Admin/Product/ClassCategoryController.php
Expand Up @@ -219,6 +219,52 @@ public function delete(Application $app, Request $request, $class_name_id, $id)
return $app->redirect($app->url('admin_product_class_category', array('class_name_id' => $ClassName->getId())));
}

/**
* @Method("PUT")
* @Route("/{_admin}/product/class_category/{class_name_id}/{id}/visibility", requirements={"class_name_id" = "\d+", "id" = "\d+"}, name="admin_product_class_category_visibility")
*/
public function visibility(Application $app, Request $request, $class_name_id, $id)
{
$this->isTokenValid($app);

$ClassName = $this->classNameRepository->find($class_name_id);
if (!$ClassName) {
throw new NotFoundHttpException('商品規格が存在しません');
}

log_info('規格分類表示変更開始', array($id));

$TargetClassCategory = $this->classCategoryRepository->find($id);
if (!$TargetClassCategory || $TargetClassCategory->getClassName() != $ClassName) {
$app->deleteMessage();
return $app->redirect($app->url('admin_product_class_category', array('class_name_id' => $ClassName->getId())));
}

$status = $this->classCategoryRepository->toggleVisibility($TargetClassCategory);

if ($status === true) {

log_info('規格分類表示変更完了', array($id));

$event = new EventArgs(
array(
'ClassName' => $ClassName,
'TargetClassCategory' => $TargetClassCategory,
),
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_CATEGORY_DELETE_COMPLETE, $event);

$app->addSuccess('admin.class_category.delete.complete', 'admin');
} else {
log_info('規格分類表示変更エラー', array($id));

$app->addError('admin.class_category.delete.error', 'admin');
}

return $app->redirect($app->url('admin_product_class_category', array('class_name_id' => $ClassName->getId())));
}

/**
* @Method("POST")
* @Route("/product/class_category/rank/move", name="admin_product_class_category_rank_move")
Expand Down

0 comments on commit 3ded70a

Please sign in to comment.