/
Version20150515000000.php
62 lines (55 loc) · 1.86 KB
/
Version20150515000000.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
56
57
58
59
60
61
62
<?php
namespace Concrete\Core\Updater\Migrations\Migrations;
use Concrete\Core\Updater\Migrations\AbstractMigration;
use Concrete\Core\Updater\Migrations\RepeatableMigrationInterface;
class Version20150515000000 extends AbstractMigration implements RepeatableMigrationInterface
{
/**
* {@inheritdoc}
*
* @see \Doctrine\Migrations\AbstractMigration::getDescription()
*/
public function getDescription(): string
{
return '5.7.5a1';
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Updater\Migrations\AbstractMigration::upgradeDatabase()
*/
public function upgradeDatabase()
{
$this->refreshDatabaseTables([
'PageFeeds',
'PageTypeComposerOutputBlocks',
]);
// I can't seem to get the doctrine cache to clear any other way.
$this->app->clearCaches();
$this->purgeOrphanedScrapbooksBlocks();
}
protected function purgeOrphanedScrapbooksBlocks()
{
$this->refreshDatabaseTables(['PageTypeComposerOutputBlocks']);
$orphanedCollectionVersionBlocks = $this->connection->fetchAll(
'
select cID, cvID, cvb.bID, arHandle
from CollectionVersionBlocks cvb
inner join btCoreScrapbookDisplay btCSD on cvb.bID = btCSD.bID
inner join Blocks b on b.bID = btCSD.bOriginalID
left join BlockTypes bt on b.btID = bt.btID
where bt.btID IS NULL',
[]
);
foreach ($orphanedCollectionVersionBlocks as $row) {
$nc = \Page::getByID($row['cID'], $row['cvID']);
if (!is_object($nc) || $nc->isError()) {
continue;
}
$b = \Block::getByID($row['bID'], $nc, $row['arHandle']);
if (is_object($b)) {
$b->deleteBlock();
}
}
}
}