Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Symfony 5 and 6 #364

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1']
phpunit-versions: ['latest']
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
composer.lock
phpunit.xml
.phpunit
.phpunit.*
vendor
.php_cs.cache
.php_cs
Expand Down
70 changes: 32 additions & 38 deletions Command/MongoDBMigrateMetadataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function configure()
fields to a new schema optimized for MongoDB queries. This command requires the
participant class to be provided as its first and only parameter:

<info>php app/console fos:message:mongodb:migrate:metadata "Acme\Document\User"</info>
<info>php bin/console fos:message:mongodb:migrate:metadata "Acme\Document\User"</info>

The following hash fields will become obsolete after migration:

Expand Down Expand Up @@ -104,15 +104,15 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->threadCollection = $this->getMongoCollectionForClass($registry, $this->getContainer()->getParameter('fos_message.thread_class'));
$this->participantCollection = $this->getMongoCollectionForClass($registry, $input->getArgument('participantClass'));

$this->updateOptions = array(
$this->updateOptions = [
'multiple' => false,
'safe' => $input->getOption('safe'),
'fsync' => $input->getOption('fsync'),
);
'fsync' => $input->getOption('fsync')
];

$this->printStatusCallback = function () {
};
register_tick_function(array($this, 'printStatus'));
register_tick_function([$this, 'printStatus']);
}

/**
Expand All @@ -124,7 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->migrateThreads($output);

$size = memory_get_peak_usage(true);
$unit = array('b', 'k', 'm', 'g', 't', 'p');
$unit = ['b', 'k', 'm', 'g', 't', 'p'];
$output->writeln(sprintf('Peak Memory Usage: <comment>%s</comment>', round($size / pow(1024, $i = floor(log($size, 1024))), 2).$unit[$i]));
}

Expand All @@ -134,11 +134,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
private function migrateMessages(OutputInterface $output)
{
$cursor = $this->messageCollection->find(
array('metadata' => array('$exists' => false)),
array(
'isReadByParticipant' => 1,
'isSpam' => 1,
)
['metadata' => ['$exists' => false]],
['isReadByParticipant' => 1, 'isSpam' => 1]
);
$cursor->snapshot();

Expand All @@ -160,11 +157,11 @@ private function migrateMessages(OutputInterface $output)
$this->createMessageUnreadForParticipants($message);

$this->messageCollection->update(
array('_id' => $message['_id']),
array('$set' => array(
['_id' => $message['_id']],
['$set' => [
'metadata' => $message['metadata'],
'unreadForParticipants' => $message['unreadForParticipants'],
)),
'unreadForParticipants' => $message['unreadForParticipants']
]],
$this->updateOptions
);
++$numProcessed;
Expand All @@ -181,15 +178,15 @@ private function migrateMessages(OutputInterface $output)
private function migrateThreads(OutputInterface $output)
{
$cursor = $this->threadCollection->find(
array('metadata' => array('$exists' => false)),
array(
['metadata' => ['$exists' => false]],
[
'datesOfLastMessageWrittenByOtherParticipant' => 1,
'datesOfLastMessageWrittenByParticipant' => 1,
'isDeletedByParticipant' => 1,
'isSpam' => 1,
'messages' => 1,
'participants' => 1,
)
'participants' => 1
]
);

$numProcessed = 0;
Expand All @@ -211,14 +208,14 @@ private function migrateThreads(OutputInterface $output)
$this->createThreadActiveParticipantArrays($thread);

$this->threadCollection->update(
array('_id' => $thread['_id']),
array('$set' => array(
['_id' => $thread['_id']],
['$set' => [
'activeParticipants' => $thread['activeParticipants'],
'activeRecipients' => $thread['activeRecipients'],
'activeSenders' => $thread['activeSenders'],
'lastMessageDate' => $thread['lastMessageDate'],
'metadata' => $thread['metadata'],
)),
'metadata' => $thread['metadata']
]],
$this->updateOptions
);
++$numProcessed;
Expand All @@ -237,13 +234,13 @@ private function migrateThreads(OutputInterface $output)
*/
private function createMessageMetadata(array &$message)
{
$metadata = array();
$metadata = [];

foreach ($message['isReadByParticipant'] as $participantId => $isRead) {
$metadata[] = array(
$metadata[] = [
'isRead' => $isRead,
'participant' => $this->participantCollection->createDBRef(array('_id' => new \MongoId($participantId))) + array('$db' => (string) $this->participantCollection->db),
);
'participant' => $this->participantCollection->createDBRef(['_id' => new \MongoId($participantId)]) + ['$db' => (string) $this->participantCollection->db]
];
}

$message['metadata'] = $metadata;
Expand All @@ -258,7 +255,7 @@ private function createMessageMetadata(array &$message)
*/
private function createMessageUnreadForParticipants(array &$message)
{
$unreadForParticipants = array();
$unreadForParticipants = [];

if (!$message['isSpam']) {
foreach ($message['metadata'] as $metadata) {
Expand All @@ -281,15 +278,12 @@ private function createMessageUnreadForParticipants(array &$message)
*/
private function createThreadMetadata(array &$thread)
{
$metadata = array();
$metadata = [];

$participantIds = array_keys($thread['datesOfLastMessageWrittenByOtherParticipant'] + $thread['datesOfLastMessageWrittenByParticipant'] + $thread['isDeletedByParticipant']);

foreach ($participantIds as $participantId) {
$meta = array(
'isDeleted' => false,
'participant' => $this->participantCollection->createDBRef(array('_id' => new \MongoId($participantId))) + array('$db' => (string) $this->participantCollection->db),
);
$meta = ['isDeleted' => false, 'participant' => $this->participantCollection->createDBRef(['_id' => new \MongoId($participantId)]) + ['$db' => (string) $this->participantCollection->db]];

if (isset($thread['isDeletedByParticipant'][$participantId])) {
$meta['isDeleted'] = $thread['isDeletedByParticipant'][$participantId];
Expand Down Expand Up @@ -320,8 +314,8 @@ private function createThreadLastMessageDate(array &$thread)

if (false !== $lastMessageRef) {
$lastMessage = $this->messageCollection->findOne(
array('_id' => $lastMessageRef['$id']),
array('createdAt' => 1)
['_id' => $lastMessageRef['$id']],
['createdAt' => 1]
);
}

Expand All @@ -337,9 +331,9 @@ private function createThreadLastMessageDate(array &$thread)
*/
private function createThreadActiveParticipantArrays(array &$thread)
{
$activeParticipants = array();
$activeRecipients = array();
$activeSenders = array();
$activeParticipants = [];
$activeRecipients = [];
$activeSenders = [];

foreach ($thread['participants'] as $participantRef) {
foreach ($thread['metadata'] as $metadata) {
Expand Down
Loading