Skip to content

Commit b55dbfc

Browse files
authored
Merge pull request #2 from wirelane/doctrine-upgrade-fetch-api
Fix deprecations
2 parents 2d07e39 + 067bbd4 commit b55dbfc

File tree

7 files changed

+51
-18
lines changed

7 files changed

+51
-18
lines changed

Command/CleanUpCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function cleanUpExpiredJobs(EntityManager $em, Connection $con, InputInt
9999
$count++;
100100

101101
$result = $con->executeQuery($incomingDepsSql, array('id' => $job->getId()));
102-
if ($result->fetchColumn() !== false) {
102+
if ($result->fetchOne() !== false) {
103103
$em->transactional(function() use ($em, $job) {
104104
$this->resolveDependencies($em, $job);
105105
$em->remove($job);

Console/Application.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(KernelInterface $kernel)
3838
}
3939
}
4040

41-
public function doRun(InputInterface $input, OutputInterface $output)
41+
public function doRun(InputInterface $input, OutputInterface $output): int
4242
{
4343
$this->input = $input;
4444

@@ -54,7 +54,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
5454
}
5555
}
5656

57-
public function onTick()
57+
public function onTick(): void
5858
{
5959
if ( ! $this->input->hasOption('jms-job-id') || null === $jobId = $this->input->getOption('jms-job-id')) {
6060
return;
@@ -78,7 +78,7 @@ public function onTick()
7878
}
7979
}
8080

81-
private function saveDebugInformation(\Exception $ex = null)
81+
private function saveDebugInformation(\Exception $ex = null): void
8282
{
8383
if ( ! $this->input->hasOption('jms-job-id') || null === $jobId = $this->input->getOption('jms-job-id')) {
8484
return;

Entity/CronJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public function getLastRunAt()
3535
{
3636
return $this->lastRunAt;
3737
}
38-
}
38+
}

Entity/Job.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
/**
2828
* @ORM\Entity
2929
* @ORM\Table(name = "jms_jobs", indexes = {
30-
* @ORM\Index("cmd_search_index", columns = {"command"}),
31-
* @ORM\Index("sorting_index", columns = {"state", "priority", "id"}),
30+
* @ORM\Index(name = "cmd_search_index", columns = {"command"}),
31+
* @ORM\Index(name = "sorting_index", columns = {"state", "priority", "id"}),
3232
* })
3333
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
3434
*

Entity/Listener/StatisticsListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ public function postGenerateSchema(GenerateSchemaEventArgs $event)
2222
$table->addColumn('charValue', 'float', array('notnull' => true));
2323
$table->setPrimaryKey(array('job_id', 'characteristic', 'createdAt'));
2424
}
25-
}
25+
}

Entity/Repository/JobManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Doctrine\Common\Collections\ArrayCollection;
2222
use Doctrine\Common\Util\ClassUtils;
2323
use Doctrine\DBAL\Connection;
24-
use Doctrine\DBAL\Types\Type;
24+
use Doctrine\DBAL\Types\Types;
2525
use Doctrine\ORM\EntityManager;
2626
use Doctrine\ORM\Query\Parameter;
2727
use Doctrine\ORM\Query\ResultSetMappingBuilder;
@@ -49,7 +49,7 @@ public function findJob($command, array $args = array())
4949
{
5050
return $this->getJobManager()->createQuery("SELECT j FROM JMSJobQueueBundle:Job j WHERE j.command = :command AND j.args = :args")
5151
->setParameter('command', $command)
52-
->setParameter('args', $args, Type::JSON_ARRAY)
52+
->setParameter('args', $args, Types::JSON)
5353
->setMaxResults(1)
5454
->getOneOrNullResult();
5555
}
@@ -75,7 +75,7 @@ public function getOrCreateIfNotExists($command, array $args = array())
7575

7676
$firstJob = $this->getJobManager()->createQuery("SELECT j FROM JMSJobQueueBundle:Job j WHERE j.command = :command AND j.args = :args ORDER BY j.id ASC")
7777
->setParameter('command', $command)
78-
->setParameter('args', $args, 'json_array')
78+
->setParameter('args', $args, Types::JSON)
7979
->setMaxResults(1)
8080
->getSingleResult();
8181

@@ -384,7 +384,7 @@ private function getJobIdsOfIncomingDependencies(Job $job)
384384
{
385385
$jobIds = $this->getJobManager()->getConnection()
386386
->executeQuery("SELECT source_job_id FROM jms_job_dependencies WHERE dest_job_id = :id", array('id' => $job->getId()))
387-
->fetchAll(\PDO::FETCH_COLUMN);
387+
->fetchFirstColumn();
388388

389389
return $jobIds;
390390
}

Entity/Type/SafeObjectType.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,50 @@
22

33
namespace JMS\JobQueueBundle\Entity\Type;
44

5-
use Doctrine\DBAL\Types\ObjectType;
5+
use Doctrine\DBAL\Platforms\AbstractPlatform;
6+
use Doctrine\DBAL\Types\ConversionException;
7+
use Doctrine\DBAL\Types\Type;
68

7-
class SafeObjectType extends ObjectType
9+
class SafeObjectType extends Type
810
{
9-
public function getSQLDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform): string
11+
public const TYPE_NAME = 'jms_job_safe_object';
12+
13+
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
14+
{
15+
return $platform->getBlobTypeDeclarationSQL($column);
16+
}
17+
18+
public function convertToDatabaseValue($value, AbstractPlatform $platform)
1019
{
11-
return $platform->getBlobTypeDeclarationSQL($fieldDeclaration);
20+
return serialize($value);
21+
}
22+
23+
public function convertToPHPValue($value, AbstractPlatform $platform)
24+
{
25+
if ($value === null) {
26+
return null;
27+
}
28+
29+
$value = is_resource($value) ? stream_get_contents($value) : $value;
30+
31+
set_error_handler(function (int $code, string $message): bool {
32+
throw ConversionException::conversionFailedUnserialization($this->getName(), $message);
33+
});
34+
35+
try {
36+
return unserialize($value);
37+
} finally {
38+
restore_error_handler();
39+
}
1240
}
1341

1442
public function getName(): string
1543
{
16-
return 'jms_job_safe_object';
44+
return self::TYPE_NAME;
45+
}
46+
47+
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
48+
{
49+
return true;
1750
}
18-
}
51+
}

0 commit comments

Comments
 (0)