/
Version20171121000000.php
55 lines (51 loc) · 1.96 KB
/
Version20171121000000.php
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Concrete\Core\Updater\Migrations\Migrations;
use Concrete\Core\File\Image\Thumbnail\ThumbnailFormatService;
use Concrete\Core\Updater\Migrations\AbstractMigration;
use Concrete\Core\Updater\Migrations\DirectSchemaUpgraderInterface;
use Concrete\Core\Updater\Migrations\ManagedSchemaUpgraderInterface;
use Doctrine\DBAL\Schema\Schema;
class Version20171121000000 extends AbstractMigration implements ManagedSchemaUpgraderInterface, DirectSchemaUpgraderInterface
{
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Updater\Migrations\ManagedSchemaUpgraderInterface::upgradeSchema()
*/
public function upgradeSchema(Schema $schema)
{
$table = $schema->getTable('FileImageThumbnailPaths');
if ($table->hasIndex('thumbnailPathID')) {
$table->dropIndex('thumbnailPathID');
}
if (!$table->hasColumn('thumbnailFormat')) {
$table->addColumn(
'thumbnailFormat',
'string',
[
'notnull' => true,
'default' => '',
'length' => 5,
]
);
$table->setPrimaryKey([
'fileID',
'fileVersionID',
'thumbnailTypeHandle',
'storageLocationID',
'thumbnailFormat',
]);
}
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Updater\Migrations\DirectSchemaUpgraderInterface::upgradeDatabase()
*/
public function upgradeDatabase()
{
$db = $this->connection;
$db->executeQuery("UPDATE FileImageThumbnailPaths SET thumbnailFormat = ? WHERE thumbnailFormat = '' AND (path LIKE '%.jpg' OR path LIKE '%.jpeg' OR path LIKE '%.pjpg' OR path LIKE '%.pjpeg')", [ThumbnailFormatService::FORMAT_JPEG]);
$db->executeQuery("UPDATE FileImageThumbnailPaths SET thumbnailFormat = ? WHERE thumbnailFormat = ''", [ThumbnailFormatService::FORMAT_PNG]);
}
}