Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.7' into 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Jun 12, 2015
2 parents ef3107e + 3ab2138 commit d977830
Show file tree
Hide file tree
Showing 64 changed files with 1,232 additions and 275 deletions.
32 changes: 32 additions & 0 deletions src/Oro/Bundle/ActivityListBundle/Entity/ActivityList.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ class ActivityList extends ExtendActivityList
*/
protected $subject;

/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
* @Soap\ComplexType("string", nillable=true)
*/
protected $description;

/**
* @var bool
*
Expand Down Expand Up @@ -217,6 +225,30 @@ public function setSubject($subject)
return $this;
}

/**
* Get a description of the related record
*
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* Set a description of the related record
*
* @param string $description
*
* @return self
*/
public function setDescription($description)
{
$this->description = $description;

return $this;
}

/**
* Get head item in the thread
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public function getEntityViewModel(ActivityList $entity, $targetEntityData = [])
'editor_id' => $editorId,
'verb' => $entity->getVerb(),
'subject' => $entity->getSubject(),
'description' => $entity->getDescription(),
'data' => $data,
'relatedActivityClass' => $entity->getRelatedActivityClass(),
'relatedActivityId' => $entity->getRelatedActivityId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Oro\Bundle\ActivityListBundle\Migrations\Data\ORM;

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\QueryBuilder;

use Oro\Bundle\EmailBundle\Entity\Email;
use Oro\Bundle\BatchBundle\ORM\Query\BufferedQueryResultIterator;

class UpdateEmailActivityListDescription extends AbstractFixture implements ContainerAwareInterface
{
const BATCH_SIZE = 500;

/** @var ContainerInterface */
protected $container;

/**
* {@inheritdoc}
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}

/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$this->updateEmailActivityDescription($manager);
}

/**
* Update activity
* @param ObjectManager $manager
*/
public function updateEmailActivityDescription(ObjectManager $manager)
{
/** @var QueryBuilder $activityListBuilder */
$activityListBuilder = $manager->getRepository('OroActivityListBundle:ActivityList')->createQueryBuilder('e');

$iterator = new BufferedQueryResultIterator($activityListBuilder);
$iterator->setBufferSize(self::BATCH_SIZE);

$itemsCount = 0;
$entities = [];
$emailRepository = $manager->getRepository('OroEmailBundle:Email');
$activityProvider = $this->container->get('oro_email.activity_list.provider');

foreach ($iterator as $activity) {
$email = $emailRepository->find($activity->getRelatedActivityId());
if ($email) {
$itemsCount++;
$activity->setDescription($activityProvider->getDescription($email));
$entities[] = $activity;
}
if (0 === $itemsCount % self::BATCH_SIZE) {
$this->saveEntities($manager, $entities);
$entities = [];
}
}

if ($itemsCount % self::BATCH_SIZE > 0) {
$this->saveEntities($manager, $entities);
}
}

/**
* @param ObjectManager $manager
* @param array $entities
*/
protected function saveEntities(ObjectManager $manager, array $entities)
{
foreach ($entities as $activity) {
$manager->persist($activity);
}
$manager->flush();
$manager->clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Oro\Bundle\MigrationBundle\Migration\Installation;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
use Oro\Bundle\ActivityListBundle\Migrations\Schema\v1_1\OroActivityListBundle as OroActivityListBundle11;
use Oro\Bundle\ActivityListBundle\Migrations\Schema\v1_2\AddActivityDescription as AddActivityDescription12;

class OroActivityListBundleInstaller implements Installation
{
Expand All @@ -15,7 +16,7 @@ class OroActivityListBundleInstaller implements Installation
*/
public function getMigrationVersion()
{
return 'v1_1';
return 'v1_2';
}

/**
Expand All @@ -30,6 +31,7 @@ public function up(Schema $schema, QueryBag $queries)
$this->addOroActivityListForeignKeys($schema);

OroActivityListBundle11::addColumns($schema);
AddActivityDescription12::addColumns($schema);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Oro\Bundle\ActivityListBundle\Migrations\Schema\v1_2;

use Doctrine\DBAL\Schema\Schema;

use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class AddActivityDescription implements Migration
{
/**
* @inheritdoc
*/
public function up(Schema $schema, QueryBag $queries)
{
self::addColumns($schema);
}

/**
* Add description to activity list
*
* @param Schema $schema
*/
public static function addColumns(Schema $schema)
{
$table = $schema->getTable('oro_activity_list');
$table->addColumn('description', 'text', ['notnull' => false]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public function isApplicableTarget(ConfigIdInterface $configId, ConfigManager $c
*/
public function getSubject($entity);

/**
* @param object $entity
*
* @return string|null
*/
public function getDescription($entity);

/**
* @param ActivityList $activityListEntity
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Oro\Bundle\ActivityListBundle\Model\ActivityListDateProviderInterface;
use Oro\Bundle\ActivityListBundle\Model\ActivityListGroupProviderInterface;
use Oro\Bundle\CommentBundle\Model\CommentProviderInterface;
use Oro\Bundle\UIBundle\Tools\HtmlTagHelper;

/**
* Class ActivityListChainProvider
Expand All @@ -42,22 +43,28 @@ class ActivityListChainProvider
/** @var array */
protected $targetClasses = [];

/** @var HtmlTagHelper */
protected $htmlTagHelper;

/**
* @param DoctrineHelper $doctrineHelper
* @param ConfigManager $configManager
* @param TranslatorInterface $translator
* @param EntityRoutingHelper $routingHelper
* @param HtmlTagHelper $htmlTagHelper
*/
public function __construct(
DoctrineHelper $doctrineHelper,
ConfigManager $configManager,
TranslatorInterface $translator,
EntityRoutingHelper $routingHelper
EntityRoutingHelper $routingHelper,
HtmlTagHelper $htmlTagHelper
) {
$this->doctrineHelper = $doctrineHelper;
$this->configManager = $configManager;
$this->translator = $translator;
$this->routingHelper = $routingHelper;
$this->htmlTagHelper = $htmlTagHelper;
}

/**
Expand Down Expand Up @@ -213,6 +220,22 @@ public function getSubject($entity)
return null;
}

/**
* @param object $entity
*
* @return string|null
*/
public function getDescription($entity)
{
foreach ($this->providers as $provider) {
if ($provider->isApplicable($entity)) {
return $provider->getDescription($entity);
}
}

return null;
}

/**
* Get activity list provider for given activity entity
*
Expand Down Expand Up @@ -257,6 +280,10 @@ protected function getActivityListEntityForEntity(
}

$list->setSubject($provider->getSubject($entity));
$description = $this->htmlTagHelper->stripTags(
$this->htmlTagHelper->purify($provider->getDescription($entity))
);
$list->setDescription($description);
if ($this->hasCustomDate($provider)) {
$list->setCreatedAt($provider->getDate($entity));
$list->setUpdatedAt($provider->getDate($entity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ services:
- @oro_entity_config.config_manager
- @translator
- @oro_entity.routing_helper
- @oro_ui.html_tag_helper

oro_activity_list.entity_config_dumper.extension:
class: %oro_activity_list.entity_config_dumper.extension.class%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
oro:
activitylist:
entity_label: Activity list
entity_plural_label: Activity list
entity_description: Represent activities list
entity_label: Activity list
entity_plural_label: Activity list
entity_description: Represent activities list

id.label: Id
owner.label: Created by
editor.label: Updated by
verb.label: Verb
subject.label: Subject
data.label: Data
organization.label: Organization
id.label: Id
owner.label: Created by
editor.label: Updated by
verb.label: Verb
subject.label: Subject
data.label: Data
organization.label: Organization
related_activity_class.label: Related activity class
related_activity_id.label: Related activity id
created_at.label: Created at
updated_at.label: Updated at
head.label: Is Head
created_at.label: Created at
updated_at.label: Updated at
head.label: Is Head
description.label: Description

no_activities_exist: No activities found

Expand All @@ -25,7 +26,7 @@ oro:
activity_list.label: Activity lists
fields:
sorting_field:
label: Sort by field
label: Sort by field
choices:
createdAt: Created date
updatedAt: Updated date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
</div>
<div class="message-item message">
{% block activityShortMessage %}
<%= subject %>
<strong><%= subject %></strong>
<% if (!_.isUndefined(description) && !_.isEmpty(description)) { %>
- <%= description %>
<% } %>
{% endblock %}
</div>
<div class="created-at">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function getSetDataProvider()
return [
['verb', 'testVerb'],
['subject', 'testSubject'],
['description', 'testDescription'],
['relatedActivityClass', 'testRelatedActivityClass'],
['relatedActivityId', 123],
['updatedAt', new \DateTime('now')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public function testGetItem()
$testItem->setUpdatedAt(new \DateTime('2014-01-01', new \DateTimeZone('UTC')));
$testItem->setVerb(ActivityList::VERB_UPDATE);
$testItem->setSubject('test_subject');
$testItem->setDescription('test_description');
$testItem->setRelatedActivityClass('Acme\TestBundle\Entity\TestEntity');
$testItem->setRelatedActivityId(127);

Expand Down Expand Up @@ -245,6 +246,7 @@ function ($user) {
'editor_id' => 142,
'verb' => 'update',
'subject' => 'test_subject',
'description' => 'test_description',
'data' => ['test_data'],
'relatedActivityClass' => 'Acme\TestBundle\Entity\TestEntity',
'relatedActivityId' => 127,
Expand Down
Loading

0 comments on commit d977830

Please sign in to comment.