Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.10' into 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Oct 20, 2016
2 parents f2fded9 + 1e946a2 commit 40d95cb
Show file tree
Hide file tree
Showing 64 changed files with 1,921 additions and 417 deletions.
4 changes: 2 additions & 2 deletions src/Oro/Bundle/ActivityListBundle/Entity/ActivityList.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ public function getSubject()
}

/**
* Set a subject of the related record
* Set a subject of the related record. The subject cutes to 250 symbols.
*
* @param string $subject
*
* @return self
*/
public function setSubject($subject)
{
$this->subject = substr($subject, 0, 255);
$this->subject = mb_substr($subject, 0, 250, mb_detect_encoding($subject));

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,20 @@ public function testIsNotUpdatedFlags()
$this->assertFalse($activityList->isUpdatedBySet());
$this->assertFalse($activityList->isUpdatedAtSet());
}

public function testSetSubjectOnLongString()
{
$activityList = new ActivityList();
$activityList->setSubject(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget elementum velit, ac tempor orci. '
. 'Cras aliquet massa id dignissim bibendum. Interdum et malesuada fames ac ante ipsum primis in faucibus.'
.' Aenean ac libero magna. Proin eu tristiqäe est. Donec convallis pretium congue. Nullam sed.'
);
self::assertEquals(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget elementum velit, ac tempor orci. '
. 'Cras aliquet massa id dignissim bibendum. Interdum et malesuada fames ac ante ipsum primis in faucibus.'
. ' Aenean ac libero magna. Proin eu tristiqä',
$activityList->getSubject()
);
}
}
2 changes: 1 addition & 1 deletion src/Oro/Bundle/CronBundle/Command/CronCommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface CronCommandInterface
* Define default cron schedule definition for a command.
* Example: "5 * * * *"
*
* @see Oro\Bundle\CronBundle\Entity\Schedule::setDefinition()
* @see \Oro\Bundle\CronBundle\Entity\Schedule::setDefinition()
* @return string
*/
public function getDefaultDefinition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Here's list of already implemented extensions:
- [Export](extensions/export.md) - responsible for export grid data
- [Field ACL](extensions/field_acl.md) - allow to protect entity fields with ACL
- [Board](extensions/board.md) - responsible for adding Kanban board views for datagrids
- [Filter](http://github.com/orocrm/platform/blob/master/src/Oro/Bundle/FilterBundle/Resources/doc/reference/grid_extension.md) - responsible for adding filtering and filter widgets to grid

Customization
-------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ define(function(require) {

this.columnFilterModel = new ColumnFilterModel();

this._createViews(options);
this.createViews = _.bind(this._createViews, this, options);

this._applyState(this.grid.collection, this.grid.collection.state);

Expand All @@ -79,7 +79,6 @@ define(function(require) {
*/
delegateListeners: function() {
this.listenTo(this.grid.collection, 'updateState', this._applyState);
this.listenTo(this.columnManagerCollectionView, 'reordered', this._pushState);
this.listenTo(this.managedColumns, 'change:renderable', this._pushState);
this.listenTo(this.managedColumns, 'sort', function() {
this.columns.sort();
Expand Down Expand Up @@ -112,9 +111,13 @@ define(function(require) {
filterModel: this.columnFilterModel,
orderShift: orderShift
});
this.listenTo(this.columnManagerCollectionView, 'reordered', this._pushState);
},

updateViews: function() {
if (!this.columnManagerCollectionView) {
this.createViews();
}
this.columnManagerCollectionView.updateView();
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ define(function(require) {
/**
* @inheritDoc
*/
initComponent: function() {
render: function() {
ActionComponentDropdownLauncher.__super__.render.call(this);
this.componentOptions._sourceElement = this.$('.dropdown-menu');
var Component = this.componentConstructor;
this.component = new Component(this.componentOptions);
return this;
},

/**
Expand Down Expand Up @@ -92,8 +94,8 @@ define(function(require) {
* Handles dropdown menu open and sets max-width for the element
*/
onOpen: function() {
if (!this.component) {
this.initComponent();
if (_.isFunction(this.component.updateViews)) {
this.component.updateViews();
}
var $dropdownMenu = this.$('>.dropdown-menu');
if ($dropdownMenu.length) {
Expand All @@ -105,9 +107,6 @@ define(function(require) {
var $elem = this.$('.dropdown-menu');
// focus input after Bootstrap opened dropdown menu
$elem.focusFirstInput();
if (_.isFunction(this.component.updateViews)) {
this.component.updateViews();
}
},

/**
Expand Down
19 changes: 18 additions & 1 deletion src/Oro/Bundle/EmailBundle/Builder/EmailBodyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Oro\Bundle\EmailBundle\Entity\EmailAttachment;
use Oro\Bundle\EmailBundle\Entity\EmailAttachmentContent;
use Oro\Bundle\ConfigBundle\Config\ConfigManager;
use Oro\Bundle\EmailBundle\Tools\EmailBodyHelper;

/**
* A helper class allows you to easy build EmailBody entity
Expand All @@ -24,6 +25,9 @@ class EmailBodyBuilder
/** @var ConfigManager */
protected $configManager;

/** @var EmailBodyHelper */
private $emailBodyHelper;

/**
* @param ConfigManager $configManager
*/
Expand Down Expand Up @@ -58,7 +62,8 @@ public function setEmailBody($content, $bodyIsText)
$this->emailBody = new EmailBody();
$this->emailBody
->setBodyContent($content)
->setBodyIsText($bodyIsText);
->setBodyIsText($bodyIsText)
->setTextBody($this->getEmailBodyHelper()->getTrimmedClearText($content));
}

/**
Expand Down Expand Up @@ -159,4 +164,16 @@ protected function checkContentSizeValue($content, $contentSize, $contentTransfe

return $contentSize;
}

/**
* @return EmailBodyHelper
*/
protected function getEmailBodyHelper()
{
if (!$this->emailBodyHelper) {
$this->emailBodyHelper = new EmailBodyHelper();
}

return $this->emailBodyHelper;
}
}
19 changes: 18 additions & 1 deletion src/Oro/Bundle/EmailBundle/Builder/EmailEntityBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Oro\Bundle\EmailBundle\Exception\UnexpectedTypeException;
use Oro\Bundle\EmailBundle\Model\FolderType;
use Oro\Bundle\EmailBundle\Tools\EmailAddressHelper;
use Oro\Bundle\EmailBundle\Tools\EmailBodyHelper;
use Oro\Bundle\OrganizationBundle\Entity\OrganizationInterface;
use Oro\Bundle\UserBundle\Entity\User;

Expand All @@ -35,6 +36,9 @@ class EmailEntityBuilder
*/
private $emailAddressHelper;

/** @var EmailBodyHelper */
private $emailBodyHelper;

/**
* Constructor
*
Expand Down Expand Up @@ -250,7 +254,8 @@ public function body($content, $isHtml, $persistent = false)
$result
->setBodyContent($content)
->setBodyIsText(!$isHtml)
->setPersistent($persistent);
->setPersistent($persistent)
->setTextBody($this->getEmailBodyHelper()->getTrimmedClearText($content, !$isHtml));

return $result;
}
Expand Down Expand Up @@ -476,4 +481,16 @@ public function setObject($obj)
);
}
}

/**
* @return EmailBodyHelper
*/
protected function getEmailBodyHelper()
{
if (!$this->emailBodyHelper) {
$this->emailBodyHelper = new EmailBodyHelper();
}

return $this->emailBodyHelper;
}
}
77 changes: 77 additions & 0 deletions src/Oro/Bundle/EmailBundle/Command/ConvertEmailBodyToTextBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Oro\Bundle\EmailBundle\Command;

use Doctrine\DBAL\Connection;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Oro\Bundle\EmailBundle\Tools\EmailBodyHelper;

/**
* Converts email body representations.
* Will be deleted in 2.0
*/
class ConvertEmailBodyToTextBody extends ContainerAwareCommand
{
const COMMAND_NAME = 'oro:email:convert-body-to-text';

const BATCH_SIZE = 500;

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName(static::COMMAND_NAME)
->setDescription('Converts emails body. Generates and stores textual email body representation.');

parent::configure();
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('<info>Conversion of emails body is started.</info>');

/** @var Connection $connection */
$connection = $this->getContainer()->get('doctrine')->getConnection();

$tableName = $this->queryHelper->getTableName('Oro\Bundle\EmailBundle\Entity\EmailBody');
$selectQuery = 'select id, body from ' . $tableName . ' where body is not null and text_body is null '
. 'order by created desc limit :limit offset :offset';
$pageNumber = 0;
$emailBodyHelper = new EmailBodyHelper();
while (true) {
$output->writeln(sprintf('<info>Process page %s.</info>', $pageNumber + 1));
$data = $connection->fetchAll(
$selectQuery,
['limit' => self::BATCH_SIZE, 'offset' => self::BATCH_SIZE * $pageNumber],
['limit' => 'integer', 'offset' => 'integer']
);

// exit if we have no data anymore
if (count($data) === 0) {
break;
}

foreach ($data as $dataArray) {
$connection->update(
$tableName,
['text_body' => $emailBodyHelper->getTrimmedClearText($dataArray['body'])],
['id' => $dataArray['id']],
['textBody' => 'string']
);
}

$pageNumber++;
}

$output->writeln('<info>Job complete.</info>');
}
}
2 changes: 1 addition & 1 deletion src/Oro/Bundle/EmailBundle/Entity/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function getSubject()
*/
public function setSubject($subject)
{
$this->subject = $subject;
$this->subject = mb_substr($subject, 0, 998, mb_detect_encoding($subject));

return $this;
}
Expand Down
26 changes: 26 additions & 0 deletions src/Oro/Bundle/EmailBundle/Entity/EmailBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class EmailBody
*/
protected $bodyIsText;

/**
* @var string
*
* @ORM\Column(name="text_body", type="text", nullable=true)
*/
protected $textBody;

/**
* @var bool
*
Expand Down Expand Up @@ -271,4 +278,23 @@ public function __toString()
{
return (string)$this->getId();
}

/**
* @return string
*/
public function getTextBody()
{
return $this->textBody;
}

/**
* @param string $textBody
* @return $this
*/
public function setTextBody($textBody)
{
$this->textBody = $textBody;

return $this;
}
}
2 changes: 1 addition & 1 deletion src/Oro/Bundle/EmailBundle/Entity/EmailFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class EmailFolder
/**
* @var integer
*
* @ORM\Column(name="failed_count", type="integer", nullable=false)
* @ORM\Column(name="failed_count", type="integer", nullable=false, options={"default" = "0"})
*/
protected $failedCount = 0;

Expand Down
13 changes: 2 additions & 11 deletions src/Oro/Bundle/EmailBundle/Manager/EmailNotificationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Routing\Exception\RouteNotFoundException;

use Oro\Bundle\EmailBundle\Entity\Email;
use Oro\Bundle\EmailBundle\Tools\EmailBodyHelper;
use Oro\Bundle\EntityConfigBundle\Config\ConfigManager;
use Oro\Bundle\OrganizationBundle\Entity\Organization;
use Oro\Bundle\UIBundle\Tools\HtmlTagHelper;
Expand All @@ -23,9 +22,6 @@ class EmailNotificationManager
/** @var HtmlTagHelper */
protected $htmlTagHelper;

/** @var EmailBodyHelper */
protected $emailBodyHelper;

/** @var Router */
protected $router;

Expand All @@ -40,20 +36,17 @@ class EmailNotificationManager
* @param HtmlTagHelper $htmlTagHelper
* @param Router $router
* @param ConfigManager $configManager
* @param EmailBodyHelper $emailBodyHelper
*/
public function __construct(
EntityManager $entityManager,
HtmlTagHelper $htmlTagHelper,
Router $router,
ConfigManager $configManager,
EmailBodyHelper $emailBodyHelper
ConfigManager $configManager
) {
$this->em = $entityManager;
$this->htmlTagHelper = $htmlTagHelper;
$this->router = $router;
$this->configManager = $configManager;
$this->emailBodyHelper = $emailBodyHelper;
}

/**
Expand All @@ -80,9 +73,7 @@ public function getEmails(User $user, Organization $organization, $maxEmailsDisp
$bodyContent = '';
$emailBody = $email->getEmailBody();
if ($emailBody) {
$bodyContent = $this->htmlTagHelper->shorten(
$this->emailBodyHelper->getClearBody($emailBody->getBodyContent())
);
$bodyContent = $emailBody->getTextBody();
}

$emailId = $email->getId();
Expand Down
Loading

0 comments on commit 40d95cb

Please sign in to comment.