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 Dec 9, 2016
2 parents 647160b + 511e124 commit aa6a8f9
Show file tree
Hide file tree
Showing 36 changed files with 1,647 additions and 1,117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,22 @@ public function replaceActivityTargetWithPlainQuery(
$activityField = current(array_keys($association['relationToSourceKeyColumns']));
$targetField = current(array_keys($association['relationToTargetKeyColumns']));

$where = "WHERE $targetField = :sourceEntityId AND $activityField IN(" . implode(',', $activityIds) . ")";
$dbConnection = $this->doctrineHelper
->getEntityManager(ActivityList::ENTITY_NAME)
->getConnection()
->prepare("UPDATE $tableName SET $targetField = :masterEntityId $where");
->getConnection();

// to avoid of duplication activity lists and activities items we need to clear these relations
// from the master record before update
$where = "WHERE $targetField = :masterEntityId AND $activityField IN(" . implode(',', $activityIds) . ")";
$stmt = $dbConnection->prepare("DELETE FROM $tableName $where");
$stmt->bindValue('masterEntityId', $newTargetId);
$stmt->execute();

$dbConnection->bindValue('masterEntityId', $newTargetId);
$dbConnection->bindValue('sourceEntityId', $oldTargetId);
$dbConnection->execute();
$where = "WHERE $targetField = :sourceEntityId AND $activityField IN(" . implode(',', $activityIds) . ")";
$stmt = $dbConnection->prepare("UPDATE $tableName SET $targetField = :masterEntityId $where");
$stmt->bindValue('masterEntityId', $newTargetId);
$stmt->bindValue('sourceEntityId', $oldTargetId);
$stmt->execute();
}

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setExtendExtension(ExtendExtension $extendExtension)
*/
public function getMigrationVersion()
{
return 'v1_14';
return 'v1_14_1';
}

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

namespace Oro\Bundle\CalendarBundle\Migrations\Schema\v1_14_1;

use Doctrine\DBAL\Schema\Schema;

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

class RemoveInvitationStatusFieldConfig implements Migration
{
/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
$queries->addPostQuery(new RemoveInvitationStatusFieldConfigQuery());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Oro\Bundle\CalendarBundle\Migrations\Schema\v1_14_1;

use Psr\Log\LoggerInterface;

use Doctrine\DBAL\Connection;

use Oro\Bundle\MigrationBundle\Migration\ArrayLogger;
use Oro\Bundle\MigrationBundle\Migration\ParametrizedMigrationQuery;

class RemoveInvitationStatusFieldConfigQuery extends ParametrizedMigrationQuery
{
/**
* {@inheritdoc}
*/
public function getDescription()
{
$logger = new ArrayLogger();
$logger->info(
sprintf(
'Remove outdated field from entity configuration: %s::$%s.',
'Oro\Bundle\CalendarBundle\Entity\CalendarEvent',
'invitationStatus'
)
);
$this->doExecute($logger, true);

return $logger->getMessages();
}

/**
* {@inheritdoc}
*/
public function execute(LoggerInterface $logger)
{
$this->doExecute($logger);
}

/**
* {@inheritdoc}
*/
public function doExecute(LoggerInterface $logger, $dryRun = false)
{
$sql = 'DELETE FROM oro_entity_config_field WHERE field_name = ? '.
'AND entity_id = (SELECT id FROM oro_entity_config WHERE class_name = ? LIMIT 1)';

$parameters = ['invitationStatus', 'Oro\Bundle\CalendarBundle\Entity\CalendarEvent'];
$this->connection->executeUpdate($sql, $parameters);

$this->logQuery($logger, $sql, $parameters);

if (!$dryRun) {
$this->connection->executeUpdate($sql, $parameters);
}
}

/**
* {@inheritdoc}
*/
public function setConnection(Connection $connection)
{
$this->connection = $connection;
}
}
28 changes: 25 additions & 3 deletions src/Oro/Bundle/CalendarBundle/Model/Recurrence/WeeklyStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
use Oro\Bundle\CalendarBundle\Entity;
use Oro\Bundle\CalendarBundle\Model\Recurrence;

/**
* Class WeeklyStrategy
* @package Oro\Bundle\CalendarBundle\Model\Recurrence
*
* The weekly strategy for the first week takes into account only that days that are later than start
* of recurrence and then it selects next days according to its interval.
* For example, the rule 'Weekly every 2 weeks on Monday, Friday every 2 weeks'
* starting on Thursday, the 6th of October, 2016 will work in such way:
*
* S M T W T F S
* 1
* 2 3 4 5 6 [7] 8
* 9 10 11 12 13 14 15
* 16 [17] 18 19 20 [21] 22
* 23 24 25 26 27 28 29
* 30 [31]
*
*/
class WeeklyStrategy extends AbstractStrategy
{
/**
Expand All @@ -25,18 +43,22 @@ public function getOccurrences(Entity\Recurrence $recurrence, \DateTime $start,
//week days should be sorted in standard sequence (sun, mon, tue...)
$this->sortWeekDays($weekDays);

$firstDay = reset($weekDays);
$startTime = new \DateTime("previous $firstDay {$recurrence->getStartTime()->format('c')}");
$startTimeNumericDay = $recurrence->getStartTime()->format('w');
//move startTime to the first day of week
$startTime = new \DateTime("-$startTimeNumericDay days {$recurrence->getStartTime()->format('c')}");
/** @var float $fromStartInterval */
$fromStartInterval = 0;
$interval = $recurrence->getInterval();
$fullWeeks = 0;
//check if there were events before start of dates interval, so if yes we should calculate how many times
if ($start > $startTime) {
$dateInterval = $start->diff($startTime);
//it calculates total occurrences were between $start and $startTime
$fromStartInterval = floor(((int)$dateInterval->format('%a') + 1) / 7 / $interval) * count($weekDays);
foreach ($weekDays as $day) {
$currentDay = new \DateTime($day, $this->getTimeZone());
if ($currentDay->format('w') < $recurrence->getStartTime()->format('w')) {
//for the first week the items before startTime must not be taken into account
$fromStartInterval = $fromStartInterval == 0 ? $fromStartInterval : $fromStartInterval - 1;
}
}
Expand All @@ -62,7 +84,7 @@ public function getOccurrences(Entity\Recurrence $recurrence, \DateTime $start,
) {
$result[] = $next;
}

$fromStartInterval = $next >= $recurrence->getStartTime() ? $fromStartInterval +1 : $fromStartInterval;
}
$fullWeeks += $interval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,42 @@ public function propertiesDataProvider()
'2016-05-22',
],
],
'start and startTime are close, week interval' => [
'params' => [
'daysOfWeek' => [
'monday',
'friday'
],
'interval' => 1,
'occurrences' => 2,
'start' => '2016-11-13',
'end' => '2016-11-19',
'startTime' => '2016-11-14',
'endTime' => '9999-12-31',
],
'expected' => [
'2016-11-14',
'2016-11-18',
],
],
'start and startTime are close, month interval' => [
'params' => [
'daysOfWeek' => [
'monday',
'friday'
],
'interval' => 1,
'occurrences' => 2,
'start' => '2016-09-24',
'end' => '2016-11-05',
'startTime' => '2016-09-26',
'endTime' => '9999-12-31',
],
'expected' => [
'2016-09-26',
'2016-09-30',
],
],
];
}

Expand Down
52 changes: 50 additions & 2 deletions src/Oro/Bundle/CronBundle/Entity/Repository/JobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ class JobRepository extends JMSJobRepository
/** @var \ReflectionMethod */
protected $closeJobMethod;

/**
* These jobs were closed, but cannot be detached since there are jobs which have the job in dependencies
* (Job::dependencies)
*
* Detaching such job would cause doctrine thinking that the jobs in dependencies are new entities and exception
* would be thrown once the job would be updated.
*
* @var Job[]
*/
protected $jobsPendingDetach = [];

/**
* {@inheritdoc}
*/
Expand All @@ -45,7 +56,6 @@ public function __construct($em, ClassMetadata $class)
*/
public function closeJob(Job $job, $finalState)
{

$this->_em->getConnection()->beginTransaction();
try {
$visited = array();
Expand All @@ -61,13 +71,19 @@ public function closeJob(Job $job, $finalState)
continue;
}

$this->_em->detach($job);
if ($this->jobCanBeSafelyDetached($job)) {
$this->_em->detach($job);
} else {
$this->jobsPendingDetach[spl_object_hash($job)] = $job;
}
}
} catch (\Exception $ex) {
$this->_em->getConnection()->rollback();

throw $ex;
}

$this->detachJobsPendingDetach();
}

/**
Expand Down Expand Up @@ -116,4 +132,36 @@ protected function getJobIdsOfIncomingDependencies(Job $job)
->fetchAll(\PDO::FETCH_COLUMN);
return $jobIds;
}

protected function detachJobsPendingDetach()
{
foreach ($this->jobsPendingDetach as $k => $job) {
if ($this->jobCanBeSafelyDetached($job)) {
$this->_em->detach($job);
unset($this->jobsPendingDetach[$k]);
}
}
}

/**
* Checks if job can be safely detached
* (is not in Job::dependencies of another job)
*
* @param Job $job
*
* @return boolean
*/
protected function jobCanBeSafelyDetached(Job $job)
{
$uow = $this->_em->getUnitOfWork();
$identityMap = $uow->getIdentityMap();
$managedJobs = isset($identityMap[Job::class]) ? $identityMap[Job::class] : [];
foreach ($managedJobs as $managedJob) {
if ($managedJob !== $job && $managedJob->hasDependency($job)) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getBigNumberValues(
$previousInterval = $this->dateHelper->getLastWeekPeriod(-1);
}

$previousData['value'] = call_user_func($getter, $previousInterval);
$previousData['value'] = call_user_func($getter, $previousInterval, $owners);
$previousData['dateRange'] = $previousInterval;
$previousData['lessIsBetter'] = $lessIsBetter;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/DataGridBundle/Datagrid/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public function build(DatagridConfiguration $config, ParameterBag $parameters)
$acceptor = $this->createAcceptor($config, $parameters);
$datagrid->setAcceptor($acceptor);

$this->buildDataSource($datagrid, $config);
$acceptor->processConfiguration();
$this->buildDataSource($datagrid, $config);

$event = new BuildAfter($datagrid);
$this->eventDispatcher->dispatch(BuildAfter::NAME, $event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ define([
defaultMessages: {
confirm_title: 'Execution Confirmation',
confirm_content: 'Are you sure you want to do this?',
confirm_content_params: {},
confirm_ok: 'Yes, do it',
confirm_cancel: 'Cancel',
success: 'Action performed.',
Expand Down Expand Up @@ -332,7 +333,7 @@ define([
* @return {String}
*/
getConfirmContentMessage: function() {
return __(this.messages.confirm_content);
return __(this.messages.confirm_content, this.messages.confirm_content_params);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public function processUpdateEmailOwner($ownerClassName, $ownerId)
{
$ownerQb = $this->createOwnerQb($ownerClassName, $ownerId);
$owners = $this->getOwnerIterator($ownerQb);
$dependenceJob = null;
$countNewJob = 0;
foreach ($owners as $owner) {
$dependenceJob = null;
$emailsQB = $this->emailOwnersProvider->getQBEmailsByOwnerEntity($owner);

/** @var QueryBuilder $emailQB */
Expand Down
14 changes: 10 additions & 4 deletions src/Oro/Bundle/EmailBundle/Controller/EmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,16 @@ public function viewThreadAction(Email $entity)
*/
public function threadWidgetAction(Email $entity)
{
$emails = $this->get('oro_email.email.thread.provider')->getThreadEmails(
$this->get('doctrine')->getManager(),
$entity
);
$emails = [];
if ($this->getRequest()->get('showSingleEmail', false)) {
$emails[] = $entity;
} else {
$emails = $this->get('oro_email.email.thread.provider')->getThreadEmails(
$this->get('doctrine')->getManager(),
$entity
);
}

$emails = array_filter($emails, function ($email) {
return $this->get('security.context')->isGranted('VIEW', $email);
});
Expand Down
Loading

0 comments on commit aa6a8f9

Please sign in to comment.