You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 line
2.4KB

  1. <?php
  2. namespace console\commands;
  3. use domain\Order\Order\OrderModule;
  4. use domain\Order\OrderStatus\OrderStatus;
  5. use domain\Producer\Producer\ProducerModule;
  6. use domain\User\User\UserModule;
  7. use yii\console\Controller;
  8. class InitOrderStatusHistoryController extends Controller
  9. {
  10. // ./yii init-order-status-history/index
  11. public function actionIndex()
  12. {
  13. ini_set('memory_limit', '-1');
  14. /*
  15. Remettre à zéro :
  16. -----------------
  17. DELETE FROM `order_status_history`;
  18. UPDATE `order` SET `order`.order_status_alias = NULL;
  19. */
  20. $producerModule = ProducerModule::getInstance();
  21. $orderModule = OrderModule::getInstance();
  22. $userSystem = UserModule::getInstance()->getRepository()->findOneUserSystem();
  23. foreach($producerModule->getRepository()->findProducers() as $producer) {
  24. \Yii::$app->logic->setProducerContext($producer);
  25. $ordersArray = $orderModule->getRepository()->findOrdersWithOrderStatusAliasNull();
  26. echo ($ordersArray ? count($ordersArray) : '0').' : '.$producer->name."\n";
  27. while ($ordersArray && count($ordersArray)) {
  28. foreach ($ordersArray as $order) {
  29. $orderModule->getManager()->changeOrderStatus(
  30. $order,
  31. OrderStatus::ALIAS_ORDERED,
  32. $userSystem,
  33. new \DateTime($order->date)
  34. );
  35. if($order->date_update) {
  36. $orderModule->getManager()->changeOrderStatus(
  37. $order,
  38. OrderStatus::ALIAS_UPDATED,
  39. $userSystem,
  40. new \DateTime($order->date_update)
  41. );
  42. }
  43. if($order->date_delete) {
  44. $orderModule->getManager()->changeOrderStatus(
  45. $order,
  46. OrderStatus::ALIAS_DELETED,
  47. $userSystem,
  48. new \DateTime($order->date_delete)
  49. );
  50. }
  51. echo 'Order #'.$order->id."\n";
  52. }
  53. $ordersArray = $orderModule->getRepository()->findOrdersWithOrderStatusAliasNull();
  54. }
  55. }
  56. }
  57. }