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 Nov 2, 2016
2 parents 80ee1d6 + 4ed8fbc commit 8834d73
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 51 deletions.
47 changes: 34 additions & 13 deletions src/Oro/Bundle/CronBundle/Command/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ protected function execute(InputInterface $input, OutputInterface $output)

// check if daemon is running
if (!$skipCheckDaemon && !$daemon->getPid()) {
$output->writeln('');
$output->write('Daemon process not found, running.. ');
$output->writeln('', OutputInterface::VERBOSITY_DEBUG);

if ($pid = $daemon->run()) {
$output->writeln(sprintf('<info>OK</info> (pid: %u)', $pid));
$output->write('Daemon process not found, running.. ', false, OutputInterface::VERBOSITY_DEBUG);
$output->writeln(sprintf('<info>OK</info> (pid: %u)', $pid), OutputInterface::VERBOSITY_DEBUG);
} else {
$output->write('Daemon process not found, running.. ');
$output->writeln('<error>failed</error>. Cron jobs can\'t be launched.');

return;
Expand All @@ -78,8 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output)

$em->flush();

$output->writeln('');
$output->writeln('All commands finished');
$output->writeln('', OutputInterface::VERBOSITY_DEBUG);
$output->writeln('All commands finished', OutputInterface::VERBOSITY_DEBUG);
}

/**
Expand All @@ -99,7 +100,11 @@ protected function processCommands(OutputInterface $output, array $commands, Col
$em = $this->getEntityManager('OroCronBundle:Schedule');

foreach ($commands as $name => $command) {
$output->write(sprintf('Processing command "<info>%s</info>": ', $name));
$output->write(
sprintf('Processing command "<info>%s</info>": ', $name),
false,
OutputInterface::VERBOSITY_DEBUG
);

if ($this->skipCommand($output, $command)) {
continue;
Expand Down Expand Up @@ -151,7 +156,11 @@ protected function processSchedules(OutputInterface $output, Collection $schedul

$arguments = $schedule->getArguments() ? ' ' . implode(' ', $schedule->getArguments()) : '';

$output->write(sprintf('Processing command "<info>%s%s</info>": ', $schedule->getCommand(), $arguments));
$output->write(
sprintf('Processing command "<info>%s%s</info>": ', $schedule->getCommand(), $arguments),
false,
OutputInterface::VERBOSITY_DEBUG
);

if ($job = $this->createJob($output, $schedule)) {
$jobs[] = $job;
Expand All @@ -171,14 +180,23 @@ protected function skipCommand(OutputInterface $output, Command $command)
{
if (!$command instanceof CronCommandInterface) {
$output->writeln(
'<error>Unable to setup, command must be instance of CronCommandInterface</error>'
sprintf(
'<error>Unable to setup, command "<info>%s</info>" must be instance ' .
'of CronCommandInterface</error>',
$command->getName()
)
);

return true;
}

if (!$command->getDefaultDefinition()) {
$output->writeln('<error>no cron definition found, check command</error>');
$output->writeln(
sprintf(
'<error>no cron definition found, check command "<info>%s</info>"</error>',
$command->getName()
)
);

return true;
}
Expand Down Expand Up @@ -216,7 +234,10 @@ protected function createSchedule(
$name,
array $arguments = []
) {
$output->writeln('<comment>new command found, setting up schedule..</comment>');
$output->writeln(
'<comment>new command found, setting up schedule..</comment>',
OutputInterface::VERBOSITY_DEBUG
);

$schedule = new Schedule();
$schedule
Expand Down Expand Up @@ -263,14 +284,14 @@ protected function createJob(
) {
$job = new Job($schedule->getCommand(), $arguments);

$output->writeln('<comment>added to job queue</comment>');
$output->writeln('<comment>added to job queue</comment>', OutputInterface::VERBOSITY_DEBUG);

return $job;
} else {
$output->writeln('<comment>already exists in job queue</comment>');
$output->writeln('<comment>already exists in job queue</comment>', OutputInterface::VERBOSITY_DEBUG);
}
} else {
$output->writeln('<comment>skipped</comment>');
$output->writeln('<comment>skipped</comment>', OutputInterface::VERBOSITY_DEBUG);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ public function testCheckRunDuplicateJob()
{
$this->mockCronHelper(true);

$result = $this->runCommand(CronCommand::COMMAND_NAME, ['--skipCheckDaemon' => true]);
$result = $this->runCommand(CronCommand::COMMAND_NAME, ['--skipCheckDaemon' => true, '-vvv' => true]);
$this->assertNotEmpty($result);

$this->checkMessage('allJobNew', $result);

$result = $this->runCommand(CronCommand::COMMAND_NAME, []);
$result = $this->runCommand(CronCommand::COMMAND_NAME, ['-vvv' => true]);
$this->checkMessage('AllJobAdded', $result);

for ($i = 1; $i < EmailSyncCommand::MAX_JOBS_COUNT; $i++) {
$result = $this->runCommand(CronCommand::COMMAND_NAME, []);
$result = $this->runCommand(CronCommand::COMMAND_NAME, ['-vvv' => true]);
$this->assertRegexp('/Processing command "oro:cron:imap-sync": added to job queue/', $result);
}

$result = $this->runCommand(CronCommand::COMMAND_NAME, []);
$result = $this->runCommand(CronCommand::COMMAND_NAME, ['-vvv' => true]);
$this->checkMessage('AllJobAlreadyExist', $result);
}

Expand All @@ -60,7 +60,7 @@ public function testSkipAllJob()
'--skipCheckDaemon' => true,
));

$result = $this->runCommand(CronCommand::COMMAND_NAME, []);
$result = $this->runCommand(CronCommand::COMMAND_NAME, ['-vvv' => true]);
$this->assertNotEmpty($result);

$this->checkMessage('AllJobSkip', $result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ define([
*/
ChangeEditableCellListener = AbstractGridChangeListener.extend({

/** @param {Object} */
$selector: null,
/** @type {string|null} */
selector: null,

/**
* @inheritDoc
Expand All @@ -25,9 +25,9 @@ define([
if (!_.has(options, 'selector')) {
throw new Error('Parameter selector is not specified');
}
this.$selector = $(options.selector);
this.selector = options.selector;

if (!this.$selector.length) {
if (!$(this.selector).length) {
throw new Error('DOM element for selector not found');
}

Expand Down Expand Up @@ -100,7 +100,7 @@ define([
* @inheritDoc
*/
_synchronizeState: function() {
this.$selector.val(JSON.stringify(this.get('changeset')));
$(this.selector).val(JSON.stringify(this.get('changeset')));
},

/**
Expand All @@ -122,8 +122,9 @@ define([
*/
_restoreState: function() {
var changeset = {};
if (this.$selector.length) {
changeset = this._toObject(this.$selector.val());
var $selector = $(this.selector);
if ($selector.length) {
changeset = this._toObject($selector.val());
this.set('changeset', changeset);
}
if (!_.isEmpty(changeset)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$connection = $container->get('doctrine')->getConnection();
$tableName = $container->get('oro_entity.orm.native_query_executor_helper')->getTableName(EmailBody::class);
$selectQuery = 'select id, body from ' . $tableName . ' where body is not null and text_body is null '
. 'order by created desc limit :limit offset :offset';
. 'order by created desc limit :limit';
$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']
['limit' => self::BATCH_SIZE],
['limit' => 'integer']
);

// exit if we have no data anymore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ public function getEmailsUsedInLast30DaysQb(
) {
$emailQb = $this->_em->getRepository('Oro\Bundle\EmailBundle\Entity\Email')->createQueryBuilder('e');
$emailQb
->select('MAX(r.id) AS id')
->select('r.id')
->join('e.fromEmailAddress', 'fe')
->join('e.recipients', 'r')
->join('r.emailAddress', 'a')
->andWhere('e.sentAt > :from')
->groupBy('a.email');
->andWhere('e.sentAt > :from');

if ($senderEmails) {
$emailQb->andWhere($emailQb->expr()->in('fe.email', ':senders'));
Expand All @@ -74,6 +73,7 @@ public function getEmailsUsedInLast30DaysQb(

$recepientsQb = $this->createQueryBuilder('re');
$recepientsQb
->distinct()
->select('re.name, ea.email')
->orderBy('re.name')
->join('re.emailAddress', 'ea')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getEmails(User $user, Organization $organization, $maxEmailsDisp
'forwardRoute' => $this->router->generate('oro_email_email_forward', ['id' => $emailId]),
'id' => $emailId,
'seen' => $emailUser->isSeen(),
'subject' => $this->htmlTagHelper->stripTags($email->getSubject()),
'subject' => $email->getSubject(),
'bodyContent' => $bodyContent,
'fromName' => $email->getFromName(),
'linkFromName' => $this->getFromNameLink($email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Adds job to collect email body representations.
* Will be deleted in 2.0
*/
class CollectEmailBodyJobFixture extends AbstractFixture
class CollectEmailBodyAddJobFixture extends AbstractFixture
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% import 'OroUIBundle::macros.html.twig' as UI %}
<script type="text/template" id="email-notification-item-template">
<div class="info" data-id="<%= id %>">
<div class="info" data-id="<%- id %>">
<div class="body">
<div class="title nowrap-ellipsis"><%= subject %></div>
<div class="title nowrap-ellipsis"><%- subject %></div>
<div class="description nowrap-ellipsis"><%= bodyContent %></div>
</div>
<% if (seen) { %>
Expand All @@ -14,9 +14,9 @@
<div class="footer row-fluid">
<span class="pull-left fromName">
<% if (linkFromName) { %>
<a href="<%= linkFromName %>"><%= fromName %></a>
<a href="<%- linkFromName %>"><%- fromName %></a>
<% } else { %>
<%= fromName %>
<%- fromName %>
<% } %>
</span>
<span class="pull-right reply-all-action">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,41 @@ public function testGetEmailOriginFromSecurity()
$this->assertEquals($expectedOrigin, $origin);
}

public function testGetEmailOriginCache()
{
$email = 'test';
$organization = null;
$originName = InternalEmailOrigin::BAP;
$enableUseUserEmailOrigin = true;
$expectedOrigin = new \stdClass();
$owner = new \stdClass();

$this->emailOwnerProvider->expects($this->exactly(2))
->method('findEmailOwner')
->willReturn($owner);
$entityRepository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')
->disableOriginalConstructor()
->getMock();
$entityRepository->expects($this->at(0))
->method('findOneBy')
->willReturn($expectedOrigin);
$entityRepository->expects($this->at(1))
->method('findOneBy')
->willReturn(null);
$this->em->expects($this->exactly(2))
->method('getRepository')
->willReturn($entityRepository);

$origin =
$this->emailOriginHelper->getEmailOrigin($email, $organization, $originName, $enableUseUserEmailOrigin);

$this->assertEquals($expectedOrigin, $origin);

$origin = $this->emailOriginHelper->getEmailOrigin($email, $organization, $originName, false);

$this->assertNull($origin);
}

/**
* @dataProvider findEmailOriginDataProvider
*
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/EmailBundle/Tools/EmailOriginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getEmailOrigin(
$originName = InternalEmailOrigin::BAP,
$enableUseUserEmailOrigin = true
) {
$originKey = $originName . $email;
$originKey = $originName . $email . $enableUseUserEmailOrigin;
if (!$organization && $this->securityFacade !== null && $this->securityFacade->getOrganization()) {
$organization = $this->securityFacade->getOrganization();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ protected function setCorsHeaders(EmbeddedForm $formEntity, Request $request, Re
if ('*' === $allowedDomain || preg_match($regexp, $origin)) {
$response->headers->set('Access-Control-Allow-Origin', $origin);
$response->headers->set('Access-Control-Allow-Credentials', 'true');
$response->headers->set('Access-Control-Allow-Headers', 'Accept-Encoding');

break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var ORO = (function(ORO) {

var button = this.container.querySelector('button');
if (button) {
button.disable();
button.disabled = true;
}

this.ajax(this.options.url, {
Expand Down
Loading

0 comments on commit 8834d73

Please sign in to comment.