Example #1
0
 private function createOneOrder($usage)
 {
     self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\\Phrasea\\Notification\\Deliverer')->disableOriginalConstructor()->getMock();
     $receveid = [self::$DI['record_1']->get_serialize_key() => self::$DI['record_1']];
     $order = new Order();
     $order->setOrderUsage($usage);
     $order->setUser(self::$DI['user_alt2']);
     $order->setDeadline(new \DateTime('+10 minutes'));
     $orderElement = new OrderElement();
     $orderElement->setBaseId(self::$DI['record_1']->get_base_id());
     $orderElement->setRecordId(self::$DI['record_1']->get_record_id());
     $orderElement->setOrder($order);
     $order->addElement($orderElement);
     $order->setTodo(1);
     self::$DI['app']['EM']->persist($order);
     self::$DI['app']['EM']->persist($orderElement);
     self::$DI['app']['EM']->flush();
     return $order;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     $sql = 'DELETE FROM Orders';
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM OrderElements';
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $conn = $app['phraseanet.appbox']->get_connection();
     $sql = 'SELECT id, usr_id, created_on, `usage`, deadline, ssel_id FROM `order`';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $n = 0;
     $em = $app['EM'];
     $em->getEventManager()->removeEventSubscriber(new TimestampableListener());
     foreach ($rs as $row) {
         $sql = 'SELECT count(id) as todo
                 FROM order_elements
                 WHERE deny = NULL
                     AND order_id = :id';
         $stmt = $conn->prepare($sql);
         $stmt->execute([':id' => $row['id']]);
         $todo = $stmt->fetch(\PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         if (null === ($user = $this->loadUser($app['EM'], $row['usr_id']))) {
             continue;
         }
         try {
             $basket = $app['EM']->createQuery('SELECT PARTIAL b.{id} FROM Phraseanet:Basket b WHERE b.id = :id')->setParameters(['id' => $row['ssel_id']])->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)->getSingleResult();
         } catch (NoResultException $e) {
             continue;
         }
         $order = new Order();
         $order->setUser($user)->setTodo($todo['todo'])->setOrderUsage($row['usage'])->setDeadline(new \DateTime($row['deadline']))->setCreatedOn(new \DateTime($row['created_on']))->setBasket($basket);
         $em->persist($order);
         $sql = 'SELECT base_id, record_id, order_master_id, deny
                 FROM order_elements
                 WHERE order_id = :id';
         $stmt = $conn->prepare($sql);
         $stmt->execute([':id' => $row['id']]);
         $elements = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         foreach ($elements as $element) {
             $orderElement = new OrderElement();
             $user = $this->loadUser($app['EM'], $row['usr_id']);
             $orderElement->setBaseId($element['base_id'])->setDeny($element['deny'] === null ? null : (bool) $element['deny'])->setOrder($order)->setOrderMaster($user)->setRecordId($element['record_id']);
             $order->addElement($orderElement);
             $em->persist($orderElement);
         }
         if ($n % 100 === 0) {
             $em->flush();
             $em->clear();
         }
     }
     $em->flush();
     $em->clear();
     $em->getEventManager()->addEventSubscriber(new TimestampableListener());
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function getSbasId(\Alchemy\Phrasea\Application $app)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSbasId', array($app));
     return parent::getSbasId($app);
 }