Files
Phraseanet/lib/classes/patch/390alpha1b.php
Nicolas Le Goff 26bd977d5f Delete references to usr.usr_id field in entities
Conflicts:
	lib/Alchemy/Phrasea/Controller/Prod/Push.php
	lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php
	lib/conf.d/migrations.yml

Conflicts:
	lib/Alchemy/Phrasea/ACL/BasketACL.php
	lib/Alchemy/Phrasea/Authentication/Authenticator.php
	lib/Alchemy/Phrasea/Controller/Prod/Order.php
	lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php
	lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php
	lib/Alchemy/Phrasea/Controller/Root/Session.php
	lib/Alchemy/Phrasea/Model/Entities/Basket.php
	lib/Alchemy/Phrasea/Model/Entities/BasketElement.php
	lib/Alchemy/Phrasea/Model/Entities/Feed.php
	lib/Alchemy/Phrasea/Model/Entities/FeedEntry.php
	lib/Alchemy/Phrasea/Model/Entities/FtpExport.php
	lib/Alchemy/Phrasea/Model/Entities/Session.php
	lib/Alchemy/Phrasea/Model/Entities/StoryWZ.php
	lib/Alchemy/Phrasea/Model/Entities/UsrList.php
	lib/Alchemy/Phrasea/Model/Entities/UsrListEntry.php
	lib/Alchemy/Phrasea/Model/Entities/UsrListOwner.php
	lib/Alchemy/Phrasea/Model/Entities/ValidationParticipant.php
	lib/Alchemy/Phrasea/Model/Entities/ValidationSession.php
	lib/Alchemy/Phrasea/Model/Repositories/StoryWZRepository.php
	lib/classes/API/V1/adapter.php
	templates/mobile/lightbox/sc_note.html.twig
	templates/web/admin/connected-users.html.twig
	templates/web/admin/publications/fiche.html.twig
	templates/web/lightbox/IE6/agreement_box.html.twig
	templates/web/lightbox/agreement_box.html.twig
	templates/web/lightbox/basket_content_report.html.twig
	templates/web/lightbox/sc_note.html.twig
	templates/web/prod/WorkZone/Browser/Basket.html.twig
	templates/web/prod/WorkZone/Browser/Results.html.twig
	templates/web/prod/WorkZone/Macros.html.twig
	templates/web/prod/actions/Feedback/List-Share.html.twig
	templates/web/prod/actions/Feedback/ListsMacros.html.twig
	templates/web/prod/orders/order_box.html.twig
	templates/web/prod/orders/order_item.html.twig
	templates/web/prod/upload/lazaret.html.twig
	tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php
2014-02-19 17:29:25 +01:00

142 lines
3.9 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\Order;
use Alchemy\Phrasea\Model\Entities\OrderElement;
use Gedmo\Timestampable\TimestampableListener;
class patch_390alpha1b implements patchInterface
{
/** @var string */
private $release = '3.9.0-alpha.1';
/** @var array */
private $concern = [base::APPLICATION_BOX];
/**
* {@inheritdoc}
*/
public function get_release()
{
return $this->release;
}
/**
* {@inheritdoc}
*/
public function require_all_upgrades()
{
return true;
}
/**
* {@inheritdoc}
*/
public function concern()
{
return $this->concern;
}
/**
* {@inheritdoc}
*/
public function getDoctrineMigrations()
{
return ['order'];
}
/**
* {@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());
$basketRepository = $em->getRepository('Phraseanet:Basket');
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();
$user = $app['manipulator.user']->getRepository()->find($row['usr_id']);
$order = new Order();
$order->setUser($user)
->setTodo($todo['todo'])
->setOrderUsage($row['usage'])
->setDeadline(new \DateTime($row['deadline']))
->setCreatedOn(new \DateTime($row['created_on']))
->setBasket($basketRepository->find($row['ssel_id']));
$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();
$orderElement->setBaseId($element['base_id'])
->setDeny($element['deny'] === null ? null : (Boolean) $element['deny'])
->setOrder($order)
->setOrderMasterId($element['order_master_id'])
->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;
}
}