Files
Phraseanet/lib/classes/patch/390alpha7a.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

249 lines
8.0 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\AggregateToken;
use Alchemy\Phrasea\Model\Entities\Feed;
use Alchemy\Phrasea\Model\Entities\FeedEntry;
use Alchemy\Phrasea\Model\Entities\FeedItem;
use Alchemy\Phrasea\Model\Entities\FeedPublisher;
use Alchemy\Phrasea\Model\Entities\FeedToken;
use Doctrine\ORM\Query\ResultSetMapping;
class patch_390alpha7a implements patchInterface
{
/** @var string */
private $release = '3.9.0-alpha.7';
/** @var array */
private $concern = [base::APPLICATION_BOX];
/**
* {@inheritdoc}
*/
public function get_release()
{
return $this->release;
}
/**
* {@inheritdoc}
*/
public function require_all_upgrades()
{
return false;
}
/**
* {@inheritdoc}
*/
public function concern()
{
return $this->concern;
}
/**
* {@inheritdoc}
*/
public function getDoctrineMigrations()
{
return ['feed'];
}
/**
* {@inheritdoc}
*/
public function apply(base $appbox, Application $app)
{
if (false === $this->hasFeedBackup($app)) {
return false;
}
$sql = 'DELETE FROM Feeds';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'DELETE FROM FeedEntries';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'DELETE FROM FeedPublishers';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'DELETE FROM FeedItems';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'DELETE FROM FeedTokens';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'DELETE FROM AggregateTokens';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$conn = $app['phraseanet.appbox']->get_connection();
$sql = 'SELECT id, title, subtitle, public, created_on, updated_on, base_id FROM feeds_backup;';
$stmt = $conn->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
$n = 0;
$em = $app['EM'];
$fpSql = 'SELECT id, usr_id, owner, created_on FROM feed_publishers WHERE feed_id = :feed_id;';
$fpStmt = $conn->prepare($fpSql);
$feSql = 'SELECT id, title, description, created_on, updated_on, author_name, author_email FROM feed_entries WHERE feed_id = :feed_id AND publisher = :publisher_id;';
$feStmt = $conn->prepare($feSql);
$fiSql = 'SELECT sbas_id, record_id, ord FROM feed_entry_elements WHERE entry_id = :entry_id;';
$fiStmt = $conn->prepare($fiSql);
$ftSql = 'SELECT token, usr_id, aggregated FROM feed_tokens WHERE feed_id = :feed_id;';
$ftStmt = $conn->prepare($ftSql);
$faSql = 'SELECT token, usr_id FROM feed_tokens WHERE aggregated = 1;';
$faStmt = $conn->prepare($faSql);
foreach ($rs as $row) {
$feed = new Feed();
$feed->setTitle($row['title']);
$feed->setSubtitle($row['subtitle']);
$feed->setIconUrl(false);
$feed->setIsPublic($row['public']);
$feed->setCreatedOn(new \DateTime($row['created_on']));
$feed->setUpdatedOn(new \DateTime($row['updated_on']));
$feed->setCollection($row['base_id'] ? collection::get_from_base_id($app, $row['base_id']) : null);
$fpStmt->execute([':feed_id' => $row['id']]);
$fpRes = $fpStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($fpRes as $fpRow) {
$user = $app['manipulator.user']->getRepository()->find($fpRow['usr_id']);
$feedPublisher = new FeedPublisher();
$feedPublisher->setFeed($feed);
$feed->addPublisher($feedPublisher);
$feedPublisher->setCreatedOn(new \DateTime($fpRow['created_on']));
$feedPublisher->setIsOwner((Boolean) $fpRow['owner']);
$feedPublisher->setUser($user);
$feStmt->execute([':feed_id' => $row['id'], ':publisher_id' => $fpRow['id']]);
$feRes = $feStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($feRes as $feRow) {
$feedEntry = new FeedEntry();
$feedEntry->setFeed($feed);
$feed->addEntry($feedEntry);
$feedEntry->setPublisher($feedPublisher);
$feedEntry->setTitle($feRow['title']);
$feedEntry->setSubtitle($feRow['description']);
$feedEntry->setAuthorName($feRow['author_name']);
$feedEntry->setAuthorEmail($feRow['author_email']);
$feedEntry->setCreatedOn(new \DateTime($feRow['created_on']));
$feedEntry->setUpdatedOn(new \DateTime($feRow['updated_on']));
$fiStmt->execute([':entry_id' => $feRow['id']]);
$fiRes = $fiStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($fiRes as $fiRow) {
$feedItem = new FeedItem();
$feedItem->setEntry($feedEntry);
$feedEntry->addItem($feedItem);
$feedItem->setOrd($fiRow['ord']);
$feedItem->setSbasId($fiRow['sbas_id']);
$feedItem->setRecordId($fiRow['record_id']);
$em->persist($feedItem);
}
$em->persist($feedEntry);
}
$em->persist($feedPublisher);
}
$ftStmt->execute([':feed_id' => $row['id']]);
$ftRes = $ftStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($ftRes as $ftRow) {
$user = $app['manipulator.user']->getRepository()->find($ftRow['usr_id']);
$token = new FeedToken();
$token->setFeed($feed);
$feed->addToken($token);
$token->setUser($user);
$token->setValue($ftRow['token']);
$em->persist($token);
}
$em->persist($feed);
$n++;
if ($n % 100 === 0) {
$em->flush();
$em->clear();
}
}
$fiStmt->closeCursor();
$feStmt->closeCursor();
$fpStmt->closeCursor();
$ftStmt->closeCursor();
$faStmt->execute();
$faRes = $faStmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($faRes as $faRow) {
$user = $app['manipulator.user']->getRepository()->find($faRow['usr_id']);
$token = new AggregateToken();
$token->setUser($user);
$token->setValue($faRow['token']);
$em->persist($token);
}
$faStmt->closeCursor();
$em->flush();
$em->clear();
return true;
}
/**
* Checks whether `feeds_backup` tables exists.
*
* @param Application $app
*
* @return boolean True if `feeds_backup` table exists.
*/
private function hasFeedBackup(Application $app)
{
$rsm = (new ResultSetMapping())->addScalarResult('Name', 'Name');
$backup = false;
foreach ($app['EM']->createNativeQuery('SHOW TABLE STATUS', $rsm)->getResult() as $row) {
if ('feeds_backup' === $row['Name']) {
$backup = true;
break;
}
}
return $backup;
}
}